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

Username:   Password: 
 RegisterRegister   
 Help on how to do User Input for Simon Says Game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
unicorn-ellie




PostPosted: Thu Jan 02, 2014 11:35 pm   Post subject: Help on how to do User Input for Simon Says Game

Hi, it's me again.

I've been wondering how to code the user input for the Simon Says game...

So like, after the colours flash, the user gets to click on the colours and follow the pattern.
If they do it correctly, the user moves onto the next level/wins.
If not, they lose.

Is there a way to code the user input? I've rack-sacked my brain for idea, but I just don't know how to do it.
Because the pattern is always random each time you play it, I simply cannot use if statements for the colours in general...

Here is the 3rd/final level of the game:

Turing:

var square : int
var finished, finished2, finished3, finished4, finished5, finished6, finished7, finished8 : boolean := true

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 level3RandomFlashing
    randint (square, 1, 8)
end level3RandomFlashing

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

procedure level3Flashing
    var finished, finished2, finished3, finished4, finished5, finished6, finished7, finished8 : boolean := true
    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 x : 1 .. 20
            level3RandomFlashing
            if square = 1 then
                square1Level3
                finished := true
            elsif square = 2 then
                square2Level3
                finished2 := true
            elsif square = 3 then
                square3Level3
                finished3 := true
            elsif square = 4 then
                square4Level3
                finished4 := true
            elsif square = 5 then
                square5Level3
                finished5 := true
            elsif square = 6 then
                square6Level3
                finished6 := true
            elsif square = 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
end level3Flashing
level3Flashing


It would be great help if you explain to me how to code the user input part of this program.
I'm sorry if I caused any inconvenience to you.
Thank you!

P.S: For those who do not know Simon Says, this is the game: http://www.freegames.ws/games/kidsgames/simon/simon.htm
Sponsor
Sponsor
Sponsor
sponsor
np_123




PostPosted: Fri Jan 03, 2014 2:38 am   Post subject: RE:Help on how to do User Input for Simon Says Game

Okay, so to begin, you do not need and should not include the variable declarations that you have at the beginning of your code.

I dont think your procedure level3RandomFlashing should be included as a procedure or a function. You can instead declare and initialize the variable square inside your for loop and set it equal to Rand.Int (1,8)

About the 'randomness' of the pattern, I suggest you find a way to store the order of the colours flashing in the pattern, probably in an array, so you can refer to it later

To get user input, I would suggest a combination of mouse.where and maybe whatdotcolour to detect the colour of the pixel where the mouse is located when you click.

I do not have experience with whatdotcolour, but I would say that using it would work for your purpose, because it detects the colour of a pixel at a certain location.
I will preferably leave it to someone with experience with whatdotcolour to either promote or discourage its use in this situation
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  [ 2 Posts ]
Jump to:   


Style:  
Search: