turing code for "Simon Says"
Author |
Message |
davrya
|
Posted: Mon Jan 18, 2010 8:02 pm Post subject: turing code for "Simon Says" |
|
|
Hi, everyone, this is my first time posting here, so spare the criticism
Basically, for my culminating engineering project, i'm working with someone and we decided to make the computer game Simon Says. The turing code works but there are problems with the code and some functions are missing that i want to incorporate into the code.
1. In the game play of Simon says, after each successful repeat of a light pattern, one more light flash is added to the pattern. The current code flashes the right number of lights in the pattern of each level but doesn't continue from the previous pattern. That's the first problem.
2. After the light flashes and the pattern the user inputs matches, it is not cleared on the next level and needs to be reset. (On every new level, only one input is accepted)
3. I want to know how to make the code correspond to the buttons on the GUI (I tried to use an if statement, didn't work out), where if Easy is clicked, levelDiff (code) which sets the delay time of the light flashes, equals 3000, ...
Oh btw, i'm using the latest version of turing (version 4.11)
Turing: |
import GUI
setscreen ("graphics:350;250")
var levelDiff : int
const game
procedure Reset
locate (1, 1)
put "You pressed the reset button"
end Reset
procedure Easy
locate (1, 1)
levelDff := 3000
put "You pressed the easy button"
end Easy
procedure Medium
locate (1, 1)
levelDiff := 2000
put "You pressed the medium button"
end Medium
procedure Hard
locate (1, 1)
levelDiff := 1000
put "You pressed the hard button"
end Hard
var button1 : int := GUI.CreateButton (145, 50, 0, "Reset", Reset )
var button2 : int := GUI.CreateButton (5, 5, 0, "Easy", Easy )
var button3 : int := GUI.CreateButton (140, 5, 0, "Medium", Medium )
var button4 : int := GUI.CreateButton (290, 5, 0, "Hard", Hard )
loop
exit when GUI.ProcessEvent
end loop
const LED1 := 1
const LED2 := 2
const LED3 := 4
const LED4 := 8
const default := 120
const butt1 := 56
const butt2 := 248
const butt3 := 88
const butt4 := 104
var pattern : array 1 .. 10 of int
var input : array 1 .. 10 of int
var LED : int := 1
var value : int
var buttonNum : int := 1
var buttonPress : boolean := false
for levelLimit : 1 .. 10
% Flash the LEDs in a random pattern
put "Which LED Flashed?"
for count : 1 .. levelLimit
LED := Rand.Int (1, 4)
pattern (count ) := LED
if LED = 1 then
parallelput (LED1 )
play ("b")
delay (5000) %delay (levelDiff)
parallelput (0)
elsif LED = 2 then
parallelput (LED2 )
play ("c")
delay (5000) %delay (levelDiff)
parallelput (0)
elsif LED = 3 then
parallelput (LED3 )
play ("d")
delay (5000) %delay (levelDiff)
parallelput (0)
elsif LED = 4 then
parallelput (LED4 )
play ("e")
delay (5000) %delay (levelDiff)
parallelput (0)
end if
end for
% Get user input after LED's finish flashing
loop
value := parallelget
if value not= default then
if value = butt1 and not buttonPress then
input (buttonNum ) := 1
buttonNum := buttonNum + 1
buttonPress := true
elsif value = butt2 and not buttonPress then
input (buttonNum ) := 2
buttonNum := buttonNum + 1
buttonPress := true
elsif value = butt3 and not buttonPress then
input (buttonNum ) := 3
buttonNum := buttonNum + 1
buttonPress := true
elsif value = butt4 and not buttonPress then
input (buttonNum ) := 4
buttonNum := buttonNum + 1
buttonPress := true
end if
elsif value = default and buttonPress then
buttonPress := false
end if
exit when buttonNum = levelLimit + 1
end loop
% Compare user input and LED flash(s)
put "The pattern was:"
for count : 1 .. levelLimit
put pattern (count )
end for
put "Your input pattern was:"
for count : 1 .. levelLimit
put input (count )
end for
var lost : boolean := false
for count : 1 .. levelLimit
if input (count ) not= pattern (count ) then
lost := true
end if
end for
if lost then
put "You were wrong :("
exit
end if
end for
|
k, thanks for your help
PS: If i didn't clarify the idea enough the game is meant to be a simulator of the Simon Game found here: http://www.freegames.ws/games/kidsgames/simon/simon.htm# |
|
|
|
|
|
Sponsor Sponsor
|
|
|
gan gar
|
Posted: Mon Jan 18, 2010 10:20 pm Post subject: RE:turing code for "Simon Says" |
|
|
hey its nick from class ( doing mario)
dude having probs to. |
|
|
|
|
|
Prince Pwn
|
Posted: Mon Jan 18, 2010 11:23 pm Post subject: RE:turing code for "Simon Says" |
|
|
hey nick its me josh, i'm doin packman.
im also having probs |
|
|
|
|
|
ProgrammingFun
|
Posted: Tue Jan 26, 2010 6:43 pm Post subject: RE:turing code for "Simon Says" |
|
|
Wow, is everyone from your class having probs? |
|
|
|
|
|
|
|