yes or no button,yes = game restart, no = quit
Author |
Message |
SamF
|
Posted: Sun Jan 03, 2010 3:47 pm Post subject: yes or no button,yes = game restart, no = quit |
|
|
What is it you are trying to achieve?
I want to make 2 buttons for my game at the end of the game, a yes button and a no button. Hitting yes will cause the game to restart, hitting no causing the game the close
Describe what you have tried to solve this problem
I havent tried this but i was thinking about it, creating two buttons, and i copy paste the whole program into the loop if the person hits yes and if he/she hits no i just put quit
Turing 4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
imbored
|
Posted: Sun Jan 03, 2010 3:51 pm Post subject: RE:yes or no button,yes = game restart, no = quit |
|
|
or you can just put a loop until they hit no... and then make a ending screen like "THE END!!!" or something idk what your doing... maybe "GAME OVER" at the end with a nice back ground and sound effects |
|
|
|
|
![](images/spacer.gif) |
SamF
|
Posted: Sun Jan 03, 2010 5:22 pm Post subject: yes or no button,yes = game restart, no = quit |
|
|
This isnt my actual program, i just created it as an example, is there a way tht i could do something so in the buttons process, i dont have to copy paste the program into there, because the actual program i made is about 400-500 lines long, and i dont want to copy paste because then there would be too many lines.
Turing: |
var num, num1 : int
var mouseX, mouseY, button : int %Mouse variables
var textfont := Font.New ("Times New Roman:14")
proc buttons
loop
Draw.Box (570, maxy - 11, 520, maxy - 29, yellow)
Draw.Box (571, maxy - 10, 519, maxy - 30, brightred)
Font.Draw ("Yes", 534, maxy - 26, textfont, yellow)
Font.Draw ("Yes", 533, maxy - 26, textfont, brightred)
Draw.Box (460, maxy - 11, 510, maxy - 29, yellow)
Draw.Box (459, maxy - 10, 511, maxy - 30, brightred)
Font.Draw ("No", 464, maxy - 26, textfont, yellow)
Font.Draw ("No", 463, maxy - 26, textfont, brightred)
Mouse.Where (mouseX, mouseY, button )
if mouseY < maxy - 11 and mouseY > maxy - 30 and button = 1 then
if mouseX > 458 and mouseX < 512 then
quit
put "Thank you for playing :D"
elsif mouseX > 518 and mouseX < 572 then
delay (100)
cls
randint (num, 1, 2)
put "Guess the number, 1 or 2"
get num1
if num = num1 then
put "You Won :D"
elsif num > num1 or num < num1 then
put "You Lost :("
end if
put "Would you like to try again"
end if
end if
end loop
end buttons
setscreen ("graphics")
loop
randint (num, 1, 2)
put "Guess the number, 1 or 2"
get num1
if num = num1 then
put "YOU WON :D "
else
put "YOU LOST :( "
end if
put "Would you like to try again?"
buttons
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
imbored
|
Posted: Sun Jan 03, 2010 6:15 pm Post subject: RE:yes or no button,yes = game restart, no = quit |
|
|
umm after "would you like to play again" you dont have to re do the "guess the number thing" again in the procedure. In the main program you already have the guessing game. so the procedure only handles the button inputs. so instead of having your procedure do the same thing the main program is doing. Just put the graphics of the button and the if statements so when the mouse is clicked into that space it activates kinda thing. Instead of putting if and then repeating the stuff in your program... just make a boolean true and false. so "if mouse hits yes" then bpValue := true and "if mouse hits no" then bpValue := false. In the mainprogram you have have it "exit when bValue := false". You would also have to make the procedure either a function of a procedure with a pass by reference. |
|
|
|
|
![](images/spacer.gif) |
SamF
|
Posted: Sun Jan 03, 2010 6:32 pm Post subject: RE:yes or no button,yes = game restart, no = quit |
|
|
im kinda new to boolean so i dont really know how to work with it, do i have to create a new variable called bpValue, if i do, of what type does it have to be? |
|
|
|
|
![](images/spacer.gif) |
imbored
|
Posted: Sun Jan 03, 2010 6:52 pm Post subject: RE:yes or no button,yes = game restart, no = quit |
|
|
for a boolean its just true and false thats all the thing it takes. and for your procedure
its procedure button(var bpValue :boolean)
there is a var there because that would allow it to change the value of the variable.
for the main program you would have
var bValue : boolean
something like that and to call the procedure
buttons(bValue)
ps: the name bpvalue is just (boolean)(parameter)(name) thats how i do variables so i know what the variable is for. |
|
|
|
|
![](images/spacer.gif) |
|
|