Older Version Newer Version

GrahameKing GrahameKing Aug 17, 2006

[[code]] ' Program Entrap ' The first version of this program was written in machine ' language and used to demonstrate Digital Group equipment. ' MAXI-BASIC version by Hal Knippenberg, April 1979 ' Liberty Basic version by Harmonv, July 2006 nomainwin global w$, cr$, move, blu, yelo blu = 1 : yelo = 0 : gwin = 0 cr$ = chr$(13) [newgame] if gwin=1 then close #g tm = 0 ' total moves call boardsetup UpperLeftX = 40 : UpperLeftY = 20 WindowWidth = 500 : WindowHeight = 350 menu #g, "File", "New Game", [newgame], |, "Exit", [alldone] menu #g, "Help", "Entrap Rules", showrules, "About Entrap", about button #g.b, "Done", [alldone], UL, 340, 240 ' {, width, height} statictext #g.s1, "Entrap", 320, 40, 160, 60 statictext #g.s2, "Want the rules?"+cr$+"Check Help menu.", 300, 120, 190, 80 open "Entrap" for graphics_nsb as #g gwin=1 ' set window flag to active print #g, "color black ; down" print #g.s1, "!font Arial 14" print #g.s2, "!font Arial 14" print #g, "flush" print #g, "trapclose [quit]" print #g, "when leftButtonDown [clicked]" gosub [showgboard] wait ' start of main loop [clicked] gosub [getmousemove] if b(move)=yelo then #g.s2, " Illegal move."+cr$+" Try Again." wait else #g.s2, "" end if tm = tm + 1 call updateboard move gosub [showgboard] call winorlose if w$<>"" then [endgame] wait [showgboard] #g.s1, "Total Moves"+cr$+" ";tm for i = 1 to 9 x = 10+90*((i-1) mod 3) y = 10+90*int((i-1)/3) #g, "place ";x;" ";y if b(i)=yelo then #g, "backcolor yellow" else #g, "backcolor blue" end if #g, "boxfilled ";x+80;" ";y+80 #g, "flush" next i return [getmousemove] move = 0 if abs(MouseX-50)<40 and abs(MouseY-50)<40 then move = 1 if abs(MouseX-140)<40 and abs(MouseY-50)<40 then move = 2 if abs(MouseX-230)<40 and abs(MouseY-50)<40 then move = 3 if abs(MouseX-50)<40 and abs(MouseY-140)<40 then move = 4 if abs(MouseX-140)<40 and abs(MouseY-140)<40 then move = 5 if abs(MouseX-230)<40 and abs(MouseY-140)<40 then move = 6 if abs(MouseX-50)<40 and abs(MouseY-230)<40 then move = 7 if abs(MouseX-140)<40 and abs(MouseY-230)<40 then move = 8 if abs(MouseX-230)<40 and abs(MouseY-230)<40 then move = 9 return [endgame] if w$="won" then playwave "yeehaw.wav", async #g.s2, " ** You WON!! **"+cr$+"Congratulations!!" end if if w$="lost" then playwave "wlaugh.wav", async #g.s2, " -- You lost --"+cr$+"Better luck next time." end if wait [alldone] [quit] if gwin=1 then close #g end ' ----- end of main routine ----- sub boardsetup ok = 0 do for i = 1 to 9 t = rnd(1) if t<0.666 then b(i) = yelo else b(i) = blu ok = 1 end if next i loop until ok=1 end sub sub winorlose sum = 0 w$ = "" for i = 1 to 9 sum = sum + b(i) next i if sum=0 then w$="lost" if (sum=8) and (b(5)=yelo) then w$="won" end sub sub updateboard move select case move case 1: s=1245 case 2: s=123 case 3: s=2356 case 4: s=147 case 5: s=24568 case 6: s=369 case 7: s=4578 case 8: s=789 case 9: s=5689 end select for i = 1 to len(str$(s)) t = s mod 10 : b(t) = 1 - b(t) s = int(s/10) next i end sub sub showrules playwave "help.wav", async n$ = space$(10)+"Entrap Instructions"+cr$+cr$ n$=n$+ "This game is played on a 3-by-3 grid. "+cr$ n$=n$+ "When the game starts the board will be "+cr$ n$=n$+ "filled with yellow and blue squares. "+cr$+cr$ n$=n$+ "To change the board, click on any of the "+cr$ n$=n$+ "blue squares. "+cr$+cr$ n$=n$+ "To win, make the center square yellow "+cr$ n$=n$+ "and all the other squares blue."+cr$+cr$ n$=n$+ "If all the squares turn yellow, you lose. "+cr$+cr$ n$=n$+ "As you pick squares, the board will change "+cr$ n$=n$+ "based on these rule(s): "+cr$+cr$ n$=n$+ "If you pick a corner square, the 4 squares "+cr$ n$=n$+ "in the area will change."+cr$+cr$ n$=n$+ "Pick one in the middle of an edge and all "+cr$ n$=n$+ "three squares along the edge will change. "+cr$+cr$ n$=n$+ "Pick the center square and the center plus "+cr$ n$=n$+ "the 4 middle edge squares will change. "+cr$+cr$ n$=n$+ "To end the game, click the [Done] button. "+cr$+cr$ n$=n$+ "Good Luck !"+cr$ notice n$ end sub sub about n$="About Entrap"+cr$ n$=n$+ "The first version of this program was "+cr$ n$=n$+ "written in machine language and was used "+cr$ n$=n$+ "to demonstrate Digital Group equipment. "+cr$+cr$ n$=n$+ "MAXI-BASIC version by Hal Knippenberg, Apr 1979 "+cr$+cr$ n$=n$+ "Liberty Basic version by HarmonV, July 2006 "+cr$ notice n$ end sub [[code]]