2d Hanoi by Anonymous Coder8th Jul 2004 5:17
|
---|
Summary My First DarkBasic 3 hours coding time due to language issuse. Basic 2d functions not real clean. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Rem Project: Hanoi Rem Created: 7/7/2004 8:23:46 PM Remstart ***** Hanoi.dba ***** This program is a 3d implementation of the old towers of Hanoi puzzle You have 3 pegs and 3 discs. You may move the top disc on any peg to aher as long as the the disc is the smallest on that peg The program loads a menu with four options N - New Game - loads the game clicking moves the blocks R Restarts R - Rules - describes the rules O - Options - graphical options E - Exit Remend load music "media\music triumph.mp3",1 : loop music 1 rem globals for which disc is on which peg _restart: peg1#=0 : peg2#=0 : peg3#=0 rem Main - Game Loop Do gosub _load_menu keyPress$=inkey$() Select keyPress$ Case "n" gosub _start_game EndCase Case "r" cls center text screen width()/2, 200, "The Towers of Hanoi Puzzle - You may any disc to any" center text screen width()/2, 230, "other peg so long as it is smaller then the one it is on" center text screen width()/2, 260, "top of. The goal is to recreate the starting position on Peg 3" center text screen width()/2, 290, "Press Any Key" Wait Key cls EndCase Case "o" cls center text screen width()/2, 200, "None Currently - These will be 3d Graphics options in the future" center text screen width()/2, 230, "Press Any Key" Wait Key cls EndCase Case "e" End EndCase Case Default: EndCase EndSelect loop rem Load the options rem and handle the request _load_menu: center text screen width()/2, 200, "Towers Of Hanoi" center text screen width()/2,(screen height()/2)-15,"N - New Game" center text screen width()/2,screen height()/2,"R - Rules" center text screen width()/2,(screen height()/2)+15,"O - Options" center text screen width()/2,(screen height()/2)+30,"E - Exit" return _start_game: !Do gosub _draw_pegs center text screen width()/2, 400, "Type the number of the Start Peg, then the End Peg" center text screen width()/2, 430, "Type Start Peg Now" wait key keyPress$=inkey$() If (Asc(keyPress$)<49) Or (Asc(keyPress$)>51) Then goto _start_game center text screen width()/2, 460, "Type Second Peg Now" wait key keyPress2$=inkey$() If (Asc(keyPress$)<49) Or (Asc(keyPress$)>51) Then goto _start_game gosub _moveDisc loop Wait Key cls return _draw_pegs: cls If (peg1#>1.0 And peg2#>1.0 And peg3#>1.0 ) Then gosub _win_state Circle (screen width()/2)+(200*peg3#)-200,screen height()/2,60 Circle (screen width()/2)+(200*peg2#)-200,screen height()/2,45 Circle (screen width()/2)+(200*peg1#)-200,screen height()/2,30 Circle (screen width()/2)-200,screen height()/2,15 center text (screen width()/2)-200,(screen height()/2)+100,"Peg 1" Circle screen width()/2,screen height()/2,15 center text (screen width()/2),(screen height()/2)+100,"Peg 2" Circle (screen width()/2)+200,screen height()/2,15 center text (screen width()/2)+200,(screen height()/2)+100,"Peg 3" return _moveDisc: newPeg#=(Asc(keyPress2$)-49) If newPeg#>2 Or newPeg#<0 Then return Select keyPress$ Case "1" Select peg1# Case 0 peg1#=newPeg# EndCase Case Default: Select peg2# Case 0 If (peg1#>newPeg# Or peg1#<newPeg#) Then peg2#=newPeg# EndCase Case Default: Select peg3# Case 0 If ((peg1#>newPeg# Or peg1#<newPeg#) And (peg2#>newPeg# Or peg2#<newPeg#)) Then peg3#=newPeg# EndCase EndSelect EndCase EndSelect EndCase EndSelect EndCase Case "2" Select peg1# Case 1.0 peg1#=newPeg# EndCase Case Default: Select peg2# Case 1.0 If (peg1#>newPeg# Or peg1#<newPeg#) Then peg2#=newPeg# EndCase Case Default: Select peg3# Case 1.0 If ((peg1#>newPeg# Or peg1#<newPeg#) And (peg2#>newPeg# Or peg2#<newPeg#)) Then peg3#=newPeg# EndCase EndSelect EndCase EndSelect EndCase EndSelect EndCase Case "3" Select peg1# Case 2.0 peg1#=newPeg# EndCase Case Default: Select peg2# Case 2.0 If (peg1#>newPeg# Or peg1#<newPeg#) Then peg2#=newPeg# EndCase Case Default: Select peg3# Case 2.0 If ((peg1#>newPeg# Or peg1#<newPeg#) And (peg2#>newPeg# Or peg2#<newPeg#)) Then peg3#=newPeg# EndCase EndSelect EndCase EndSelect EndCase EndSelect EndCase EndSelect return _win_state: cls center text screen width()/2,screen height()/2,"You Win!!" center text screen width()/2,(screen height()/2)+60,"Press Any Key to return to Main Menu" wait key cls goto _restart return |