Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Simon Game, need help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Fashoomp




PostPosted: Tue May 22, 2007 3:35 pm   Post subject: Simon Game, need help

ok, i have some code im working on for a simon game. Visually, its all there...but programming wise it is not. I have a randint from 1..4 to see which of the 4 buttons on the simon machine is pressed. It stops after 3 blinks (which i want). How can i get it to detect which arrow key is pressed (i dont want to use GUI). If i can assign up_arrow = 1, left = 2, etc... Here is what i have so far. Just comment out that pic, it just shows which arrow key corresponds with what colour...i think you can figure it out on your own...How can i put in a pause for it to wait for input (not Input.Pause), and still detect what i press?
code:

var presses : array 1..100 of int
var counter : int := 0
var colours : array 1 .. 100 of int
proc blue_press
    drawfillarc (maxx div 2 - 150, maxy div 2 + 10, 120, 120, 45, 135, 7)
end blue_press
proc green_press
    drawfillarc (maxx div 2 - 150 - 10, maxy div 2, 120, 120, 135, 225, 7)
end green_press
proc red_press
    drawfillarc (maxx div 2 - 150, maxy div 2 - 10, 120, 120, 225, 315, 7)
end red_press
proc yellow_press
    drawfillarc (maxx div 2 - 150 + 10, maxy div 2, 120, 120, 315, 45, 7)
end yellow_press
proc simon_setup
    %blue
    drawfillarc (maxx div 2 - 150, maxy div 2 + 10, 120, 120, 45, 135, 9)
    %green
    drawfillarc (maxx div 2 - 150 - 10, maxy div 2, 120, 120, 135, 225, 10)
    %red
    drawfillarc (maxx div 2 - 150, maxy div 2 - 10, 120, 120, 225, 315, 12)
    %yellow
    drawfillarc (maxx div 2 - 150 + 10, maxy div 2, 120, 120, 315, 45, 14)
    %arrows
    %Pic.ScreenLoad ("arrows.jpg", 350, 75, picCopy)
end simon_setup

put "You will have to press the keys that correspond with each colour"
put " "
put "Be sure to remember the order of the sequence"
put " "
put "Good luck, and press any key to start"
Input.Pause
cls
simon_setup
var colour_blink : int
for i : 1 .. 100
    randint (colour_blink, 1, 4)
    colours (i) := colour_blink
end for
loop
    var press : array char of boolean
    Input.KeyDown (press)
    cls
    simon_setup
    delay (1000)
    counter := counter + 1
    put colours (counter)
    if colours (counter) = 1 then
        blue_press
        delay (1000)
        simon_setup
    end if
    if colours (counter) = 2 then
        green_press
        delay (1000)
        simon_setup
    end if
    if colours (counter) = 3 then
        red_press
        delay (1000)
        simon_setup
    end if
    if colours (counter) = 4 then
        yellow_press
        delay (1000)
        simon_setup
    end if
    if counter = 3 then
       
       
        for f:1..counter
        get presses (f)
        if presses (f) = colours (f) then
        put "CORRECT"
        else
        put "INCORRECT"
        end if
        end for
       
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Fashoomp




PostPosted: Tue May 22, 2007 8:24 pm   Post subject: Re: Simon Game, need help

Sorry to bug everyone, but i really need help, i made a bit more progress by assigning each arrow key a value. Now i just need to know how to make it stop and let me enter these arrow keys. Also, how to make it stop after 3 loops, and then every loop there after.
code:

var presses : array 1..100 of int
var counter : int := 0
var colours : array 1 .. 100 of int
var pressing : int
proc blue_press
    drawfillarc (maxx div 2 - 150, maxy div 2 + 10, 120, 120, 45, 135, 7)
end blue_press
proc green_press
    drawfillarc (maxx div 2 - 150 - 10, maxy div 2, 120, 120, 135, 225, 7)
end green_press
proc red_press
    drawfillarc (maxx div 2 - 150, maxy div 2 - 10, 120, 120, 225, 315, 7)
end red_press
proc yellow_press
    drawfillarc (maxx div 2 - 150 + 10, maxy div 2, 120, 120, 315, 45, 7)
end yellow_press
proc simon_setup
    %blue
    drawfillarc (maxx div 2 - 150, maxy div 2 + 10, 120, 120, 45, 135, 9)
    %green
    drawfillarc (maxx div 2 - 150 - 10, maxy div 2, 120, 120, 135, 225, 10)
    %red
    drawfillarc (maxx div 2 - 150, maxy div 2 - 10, 120, 120, 225, 315, 12)
    %yellow
    drawfillarc (maxx div 2 - 150 + 10, maxy div 2, 120, 120, 315, 45, 14)
    %arrows
    %Pic.ScreenLoad ("arrows.jpg", 350, 75, picCopy)
end simon_setup

put "You will have to press the keys that correspond with each colour"
put " "
put "Be sure to remember the order of the sequence"
put " "
put "Good luck, and press any key to start"
Input.Pause
cls
simon_setup
var colour_blink : int
for i : 1 .. 100
    randint (colour_blink, 1, 4)
    colours (i) := colour_blink
end for
loop
    var press : array char of boolean
    Input.KeyDown (press)
    cls
    %assigning press values
    if press (KEY_UP_ARROW) then
    pressing := 1
    elsif
    press (KEY_LEFT_ARROW) then
    pressing := 2
    elsif
    press (KEY_DOWN_ARROW) then
    pressing := 3
    elsif
    press (KEY_RIGHT_ARROW) then
    pressing := 4
    end if
    simon_setup
    delay (1000)
    counter := counter + 1
    put colours (counter)
    if colours (counter) = 1 then
        blue_press
        delay (1000)
        simon_setup
    end if
    if colours (counter) = 2 then
        green_press
        delay (1000)
        simon_setup
    end if
    if colours (counter) = 3 then
        red_press
        delay (1000)
        simon_setup
    end if
    if colours (counter) = 4 then
        yellow_press
        delay (1000)
        simon_setup
    end if
    if counter = 3 then
for g:1..counter
        pressing := presses (g)
        if presses (g) = colours (g) then
        put "CORRECT"
        else
        put "INCORRECT"
        end if
        end for
       
    end if
end loop

Albrecd




PostPosted: Wed May 23, 2007 12:37 pm   Post subject: Re: Simon Game, need help

First of all, you shouldn't declare the variable press inside the loop.

Secondly, your code to check for the sequence pressed won't work because it only checks once for the pressed key, and then uses that variable for the entire sequence. Also, after the sequence, it doesn't give you enough time to press before it checks the variable and causes an error because it has no value.

You should have an error-handling loop after it shows the sequence to determine if something has been pressed. If so, check to see if it's correct. If so, get the input for the next colour. If nothing's been pressed, check for input again until they press something.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: