goto start?
Author |
Message |
Thuged_Out_G
|
Posted: Tue Nov 18, 2003 7:49 pm Post subject: goto start? |
|
|
how do i make it so when the program is finished running, it clears the screen and says You Win! or You Lose! in the center of the screen, and then under it say Click to continue.
i guess my only problem is how to make the program restart when the screen is clicked, everything else i can do |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
|
|
|
 |
Thuged_Out_G
|
Posted: Tue Nov 18, 2003 8:44 pm Post subject: (No subject) |
|
|
ok, i understand all that, but all ive made it do, is make it so you have to click to continue each turn :S lol
ill paste the code and tell me what im doing wrong please.
code: |
var stones, Turn, PInput, CompTake : int := 0
var answer : string
var done,button,x,y:int
done:=1
var Flag := false
stones := Rand.Int (15, 30)
procedure CheckWin
if stones = 1 then
put "You Lose! " ..
if Turn mod 2 = 0 then
put "Player"
else
put "Computer"
end if
Flag := true
end if
end CheckWin
function GetTotal : int
for rep : 0 .. 7
if stones - ((4 * rep) + 1) < 4 then
result (4 * rep) + 1
end if
end for
end GetTotal
loop
CheckWin
exit when Flag = true
put "it's now the player's turn" %
put "We now have ", stones, " stones left"
loop
put "Player, please take 1, 2, or 3 stones from the pile: " ..
get PInput
cls
if PInput > 3 or PInput < 1 then
put "Invalid move, try again!"
else
exit
end if
end loop
put skip
stones -= PInput
Turn += 1
CheckWin
exit when Flag = true
put "We now have ", stones, " stones left"
put "It's now the computer's turn"
if stones - GetTotal not= 0 then
CompTake := stones - GetTotal
stones -= CompTake
else
CompTake := Rand.Int (1, 3)
stones -= CompTake
end if
put "Computer takes ", CompTake, " stones.\n"
Turn += 1
loop
if Flag=true then
put "Click To Play Again"
end if
Mouse.Where (x,y,button)
exit when button=1
end loop
end loop
|
|
|
|
|
|
 |
AsianSensation
|
Posted: Tue Nov 18, 2003 10:47 pm Post subject: (No subject) |
|
|
can you explain again?
what do you want to do, output "It's now the computer's turn, computer takes 3 stones", click the mouse, wipe the screen, then have it output "It's now the player's turn, how many would you like to take?" get number, click mouse, wipe screen?
is that what you want to do, then I suggest Mouse.ButtonWait, no need to go through that loop with a flag and whatnot.
anyways, do please give credits where it is deserved when using other people's code |
|
|
|
|
 |
Thuged_Out_G
|
Posted: Tue Nov 18, 2003 11:33 pm Post subject: (No subject) |
|
|
sry, i never did get to thank you for the proggy
but what i wanted it to do, is after the game is over and it says you lose player/computer i want it to clear the screen(i know how to do that) and then i want to give the user the option to restart the game, by clicking the mouse anywhere on the screen
btw, awesome job on ths AI, ive never managed to win a game hehe |
|
|
|
|
 |
thoughtful

|
Posted: Wed Nov 19, 2003 12:14 am Post subject: (No subject) |
|
|
Basically the easiest way is to put the program in an loop and use an if statement to see if the user wants to restart or not. This time i did it for you.
code: |
var stones, Turn, PInput, CompTake : int := 0
var answer : string
var done, button, x, y : int
var restart:string
done := 1
var Flag := false
stones := Rand.Int (15, 30)
procedure CheckWin
if stones = 1 then
put "You Lose! " ..
if Turn mod 2 = 0 then
put "Player"
else
put "Computer"
end if
Flag := true
end if
end CheckWin
function GetTotal : int
for rep : 0 .. 7
if stones - ((4 * rep) + 1) < 4 then
result (4 * rep) + 1
end if
end for
end GetTotal
loop
Flag := false
stones := Rand.Int (15, 30)
loop
CheckWin
exit when Flag = true
put "it's now the player's turn" %
put "We now have ", stones, " stones left"
loop
put "Player, please take 1, 2, or 3 stones from the pile: " ..
get PInput
cls
if PInput > 3 or PInput < 1 then
put "Invalid move, try again!"
else
exit
end if
end loop
put skip
stones -= PInput
Turn += 1
CheckWin
exit when Flag = true
put "We now have ", stones, " stones left"
put "It's now the computer's turn"
if stones - GetTotal not= 0 then
CompTake := stones - GetTotal
stones -= CompTake
else
CompTake := Rand.Int (1, 3)
stones -= CompTake
end if
put "Computer takes ", CompTake, " stones.\n"
Turn += 1
loop
if Flag = true then
put "Click To Play Again"
end if
Mouse.Where (x, y, button)
exit when button = 1
end loop
end loop
cls
put "Do you want to restart?(y/n)"
get restart
if restart="n" or restart="N" then
exit
end if
end loop
|
|
|
|
|
|
 |
|
|