Dice Game update (help needed)
Blitz3D Forums/Blitz3D Beginners Area/Dice Game update (help needed)
| ||
HI ALL! remeber my game? Well I updated it by adding a escape code. Before u press escape and then it just quits program and gives control back to windows. Now ia dded it so it asks "ARE U SURE U WANT TO QUIT" Pretty neat, I read it in my book but edited it for my game so I impressed my self. What i need help with is basicly if u look at my game or play it once u hit bottom screen it carries on from there. Know what I mean? I mean it just goes on and on.. How do I code it so once it hits bottom of the screen it starts from top again so its nice and fresh? Heres my code ; select example AppTitle "Dice Roll" Graphics 800,600 .start SeedRnd(MilliSecs()) ; Sets the random generator to get real random numbers when program is ran computer% = Rand(1,6) Select computer% Case 1 Print "The computer rolled a 1" Case 2 Print "The computer rolled a 2" Case 3 Print "The computer rolled a 3" Case 4 Print "The computer rolled a 4" Case 5 Print "The computer rolled a 5" Case 6 Print "The computer rolled a 6" End Select Print "Please press space to roll the dice!" ;Set a varible for gameinprocess true GameInProcess = True While GameInProcess = True While KeyHit(57) player = Rand(1,6) Print "You rolled a "+player+" If player < computer% Then Print "Computer WINS!" Else If player > computer% Then Print "You WON!" Else If player = computer% Then Print "ITS A DRAW!" EndIf EndIf EndIf Goto start Wend If KeyHit(1) ;Clear screen Cls QuitAnswer$ = Input$("Really quit (Y/N)?") If QuitAnswer$ = "Y" Or QuitAnswer = "y" Then GameInProcess = False Else Goto start EndIf EndIf Wend THanks WAZ! any help greatful EDIT: Notice i starting to use OR :) i am now currently reading until repeat forever commands |
| ||
A simple solution might be to keep it at the top of the screen all the time as below. Or another way might be to count how many times you can play before it hits the bottom of the screen and use a variable to keep track of it,once it reaches a certain number clear the screen and use locate 0,0 to put the cursor at the top again. ; select example AppTitle "Dice Roll" Graphics 800,600 .start SeedRnd(MilliSecs()) ; Sets the random generator to get real random numbers when program is ran computer% = Rand(1,6) Select computer% Case 1 Print "The computer rolled a 1" Case 2 Print "The computer rolled a 2" Case 3 Print "The computer rolled a 3" Case 4 Print "The computer rolled a 4" Case 5 Print "The computer rolled a 5" Case 6 Print "The computer rolled a 6" End Select Print "Please press space to roll the dice!" ;Set a varible for gameinprocess true GameInProcess = True While GameInProcess = True While KeyHit(57) player = Rand(1,6) Print "You rolled a "+player+" If player < computer% Then Print "Computer WINS!" Else If player > computer% Then Print "You WON!" Else If player = computer% Then Print "ITS A DRAW!" EndIf EndIf EndIf ;;**added code** Delay 1500 Cls Locate 0,0 ;*************** Goto start Wend If KeyHit(1) ;Clear screen Cls QuitAnswer$ = Input$("Really quit (Y/N)?") If QuitAnswer$ = "Y" Or QuitAnswer = "y" Then GameInProcess = False Else Goto start EndIf EndIf Wend |
| ||
A simple soltion, using the code above to go by - is that with the chosen resolution and default text-size, that the game plays through 10 times before it hits the bottom of the screen. All I have done here is add a variable 'Played_times' which increments each time the dice are rolled for each player. Once ten rolls each are made, it clears the screen (CLS) and sets the variable back to 1. I am sre there are more efficient ways to do this, bt this was just my simple, straight-forward method. The SetBuffer Frontbuffer() command resets the text origin to the top of the screen. This is not cleared with just Cls. I have used the front buffer, as by not initially setting a buffer, the FrontBuffer becomes default *** Maybe a bit of reading on buffers required... ; select example AppTitle "Dice Roll" Graphics 800,600 played_times=1 .start SeedRnd(MilliSecs()) ; Sets the random generator to get real random numbers when program is ran computer% = Rand(1,6) Select computer% Case 1 Print "The computer rolled a 1" Case 2 Print "The computer rolled a 2" Case 3 Print "The computer rolled a 3" Case 4 Print "The computer rolled a 4" Case 5 Print "The computer rolled a 5" Case 6 Print "The computer rolled a 6" End Select Print "Please press space to roll the dice!" ;Set a varible for gameinprocess true GameInProcess = True While GameInProcess = True While KeyHit(57) player = Rand(1,6) Print "You rolled a "+player+" If player < computer% Then Print "Computer WINS!" Else If player > computer% Then Print "You WON!" Else If player = computer% Then Print "ITS A DRAW!" EndIf EndIf EndIf played_times=played_times+1 If played_times=11 SetBuffer FrontBuffer() Cls played_times=1 EndIf Goto start Wend If KeyHit(1) ;Clear screen Cls QuitAnswer$ = Input$("Really quit (Y/N)?") If QuitAnswer$ = "Y" Or QuitAnswer = "y" Then GameInProcess = False Else Goto start EndIf EndIf Wend Ah Pazza beat me to it - Locate 0,0 (I thought there was a command to do that!) |