Hi, ICS student here. Sorry if I'm posting too many times and it's annoying you.
I followed np_123's suggestion of using whatdotcolour and mouse.where for user input for the Simon Says game but my code doesn't seem to work.
In the game, the colours flash randomly and the user has to click on the colours in the right order.
The user input should check that what the user clicks is correct, and if they get all of it right, they win. It should also make sure that if the user clicks something wrong, they will lose.
In my code, even if you press the right colour, it still comes out as "you lose" and there are a few glitches. Is there a way to fix that?
Also, if you could explain to me how to use whatdotcolour and Mouse.Where to achieve user input for this game, that would be great and very appreciated.
Here is what I have coded and tried so far (Sorry, it's kind of long):
| Turing: |
% Variables to generate sequence
var pattern : array 1 .. 20 of int
var passComp : int
% Variable for determining gameover
var gameOver, win : boolean := false
var finished, finished2, finished3, finished4, finished5, finished6, finished7, finished8 : boolean := true
procedure randomFlashing
for x : 1 .. 20
passComp := Rand.Int (0, 8)
pattern (x ) := passComp
end for
end randomFlashing
procedure colourWheel3
drawfillarc (190, 230, 50, 100, 90, 180, black)
drawfillarc (290, 320, 110, 40, 90, 180, black)
drawfillarc (190, 170, 50, 100, 180, 270, black)
drawfillarc (290, 80, 110, 40, 180, 270, black)
drawfillarc (350, 80, 110, 40, 270, 0, black)
drawfillarc (450, 170, 50, 100, 270, 0, black)
drawfillarc (450, 230, 50, 100, 0, 90, black)
drawfillarc (350, 320, 110, 40, 0, 90, black)
drawfilloval (320, 190, 90, 90, 64)
locate (11, 36)
put "Simon Says" ..
locate (13, 34)
put "Look carefully" ..
locate (14, 34)
put "or go down the" ..
locate (15, 38)
put "drain!" ..
end colourWheel3
colourWheel3
procedure square1Level3
drawfillbox (300, 40, 340, 80, 0)
delay (250)
drawfillbox (300, 40, 340, 80, brightred)
delay (250)
end square1Level3
procedure square2Level3
drawfillbox (200, 90, 240, 130, 0)
delay (250)
drawfillbox (200, 90, 240, 130, brightblue)
delay (250)
end square2Level3
procedure square3Level3
drawfillbox (150, 180, 190, 220, 0)
delay (250)
drawfillbox (150, 180, 190, 220, yellow)
delay (250)
end square3Level3
procedure square4Level3
drawfillbox (400, 90, 440, 130, 0)
delay (250)
drawfillbox (400, 90, 440, 130, brightgreen)
delay (250)
end square4Level3
procedure square5Level3
drawfillbox (450, 180, 490, 220, 0)
delay (250)
drawfillbox (450, 180, 490, 220, 42)
delay (250)
end square5Level3
procedure square6Level3
drawfillbox (200, 270, 240, 310, 0)
delay (250)
drawfillbox (200, 270, 240, 310, brown)
delay (250)
end square6Level3
procedure square7Level3
drawfillbox (400, 270, 440, 310, 0)
delay (250)
drawfillbox (400, 270, 440, 310, purple)
delay (250)
end square7Level3
procedure square8Level3
drawfillbox (300, 320, 340, 360, 0)
delay (250)
drawfillbox (300, 320, 340, 360, 4)
delay (250)
end square8Level3
drawfillbox (300, 40, 340, 80, brightred)
drawfillbox (200, 90, 240, 130, brightblue)
drawfillbox (150, 180, 190, 220, yellow)
drawfillbox (400, 90, 440, 130, brightgreen)
drawfillbox (450, 180, 490, 220, 42)
drawfillbox (200, 270, 240, 310, brown)
drawfillbox (400, 270, 440, 310, purple)
drawfillbox (300, 320, 340, 360, 4)
delay (250)
loop
for p : 1 .. 20
randomFlashing
if pattern (p ) = 1 then
square1Level3
finished := true
elsif pattern (p ) = 2 then
square2Level3
finished2 := true
elsif pattern (p ) = 3 then
square3Level3
finished3 := true
elsif pattern (p ) = 4 then
square4Level3
finished4 := true
elsif pattern (p ) = 5 then
square5Level3
finished5 := true
elsif pattern (p ) = 6 then
square6Level3
finished6 := true
elsif pattern (p ) = 7 then
square7Level3
finished7 := true
else
square8Level3
finished8 := true
end if
end for
exit when finished = true and finished2 = true and finished3 = true and finished4 = true and finished5 = true and finished6 = true and finished7 = true and finished8 = true
end loop
for p : 1 .. 20
var x, y, b : int
loop
Mouse.Where (x, y, b )
if whatdotcolour (x, y ) not= pattern (p ) and b > 0 then
gameOver := true
put "You lose."
elsif whatdotcolour (x, y ) = pattern (p ) and b > 0 then
win := true
put "You won!"
end if
end loop
end for
|
I know I kinda messed up/sorta don't know how to do it, but if you could just point out where I went wrong and tell me how to correct this so that the user input works properly that would be great.
Thank you!
P.S: For those of you who don't know Simon Says, here is the game:http://www.freegames.ws/games/kidsgames/simon/simon.htm |