Question About Sequences and Buttons
Author |
Message |
sakib15
|
Posted: Sun Jan 20, 2008 1:29 pm Post subject: Question About Sequences and Buttons |
|
|
Hello folks. I've been working on a project that's due soon at my high school, and it is a memory game consisting of a breadboard and 3 LED's. The user clicks a level of difficulty, the 3 LED's blink in any random order through the parallel ports and then the user has to match that sequence by clicking a separate section of buttons which are coloured RED, YELLOW and GREEN. I get the concept of using the keyboard to match the sequence...but i'm having issues matching the sequences by the user clicking the order of boxes. Is there a 'get' command for a click? Since there is a 'get' command for a string...i can do the keyboard matching sequence easily. By the way, i'm storing the sequences in an array. For ex.
for count : 1 .. 5
randint (z (count), 1, 3)
if z(count) = 3 then
parallelput (8) % This is 2^3 = 8
delay (500)
parallelput (0)
delay (500)
elsif z(count) = 2 or z(count) = 3 then
parallelput (z(count))
delay (500)
parallelput (0)
delay (500)
end if
end for
and to match the sequence via a keyboard would be something like...
if count = 4 then
put "What was the order of blinks (Red-1, Yellow-2, Green-3)"
for i : 1 .. 4
get answer
if answer = z(i) then
put "Correct"
else
put "Incorrect"
end if
end for
end if
My main question is how the hell do i match the random sequence via buttons? Any help would be appreciated... |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
BigBear
|
Posted: Mon Mar 03, 2008 11:08 am Post subject: Re: Question About Sequences and Buttons |
|
|
To get a click from the mouse use code: | Mouse.Where (x, y, button) | (x, y, button are all integers variables)
So x is equal to the x location of the mouse and y is where the mouse is vertically. Button is if a button is being pressed (no button being pressed is 0) If the mouse is greater than 0 then you know they clicked the mouse.
Turing: | %variables
var font := Font.New ("Arial:40:bold,italic")
var x, y, button : int
var answer : string
%Draws choices
Font.Draw ("1 RED", 50, maxy - 300, font, brightred)
Font.Draw ("2 YELLOW", 50, maxy - 360, font, yellow)
Font.Draw ("3 GREEN", 50, maxy - 420, font, brightgreen)
loop
%Gets mouse information (location and if button is down)
Mouse.Where (x, y, button )
%if they use keyboard then will get answer in string (no hasch it stops to get answer)
if hasch then
get answer
end if
%Displays when mouse is over word
if x >= 50 and x <= 501 and y >= maxy - 300 and y <= maxy - 236 then
Font.Draw ("1 RED", 52, maxy - 300, font, black)
Font.Draw ("2 YELLOW", 50, maxy - 360, font, yellow)
Font.Draw ("3 GREEN", 50, maxy - 420, font, brightgreen)
elsif x >= 50 and x <= 544 and y >= maxy - 360 and y <= maxy - 303 then
Font.Draw ("2 YELLOW", 52, maxy - 360, font, black)
Font.Draw ("1 RED", 50, maxy - 300, font, brightred)
Font.Draw ("3 GREEN", 50, maxy - 420, font, brightgreen)
elsif x >= 50 and x <= 535 and y >= maxy - 420 and y <= maxy - 357 then
Font.Draw ("3 GREEN", 52, maxy - 420, font, black)
Font.Draw ("1 RED", 50, maxy - 300, font, brightred)
Font.Draw ("2 YELLOW", 50, maxy - 360, font, yellow)
end if
%If they are over word and click button
if x >= 50 and x <= 501 and y >= maxy - 300 and y <= maxy - 236 and button > 0 then
%they chose red then you assign answer as if they pressed "1"
answer := "1"
elsif x >= 50 and x <= 544 and y >= maxy - 360 and y <= maxy - 303 and button > 0 then
%they chose yellow then you assign answer as if they pressed "2"
answer := "2"
elsif x >= 50 and x <= 535 and y >= maxy - 420 and y <= maxy - 357 and button > 0 then
%they chose green then you assign answer as if they pressed "3"
answer := "3"
end if
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
|
|