Memory game code help
MMauer
Posts: 1
I'm making a memory game (similar to Simon) & am stuck on the code. I am not sure what I need to enter in Select & Code (I probably have some others errors within the Code as well). Any help would be greatly appreciated! Because I'm not sure that I'm doing the Select & Code parts correctly I have them different under pattern 1 & 2. Here's my code so far:
pattern1 VAR Word
pattern2 VAR Word
DEBUG "Pattern 1", CR
DO
GOSUB GBUTTON 'Green button on
PAUSE 1500
GOSUB BBUTTON 'Blue button on
PAUSE 1500
GOSUB RBUTTON 'Red button on
PAUSE 1500
GOSUB LIGHTSOFF 'All lights off
DEBUG "Your Turn", CR
SELECT
CASE
HIGH 12
CASE ELSE
FREQOUT 7, 1500, 2000 'Buzzer sounds
PAUSE 1500
DEBUG "You Lose!", CR 'Game over
HIGH 14
CASE ELSE
FREQOUT 7, 1500, 2000 'Buzzer sounds
PAUSE 1500
DEBUG "You Lose!", CR 'Game over
HIGH 3
CASE ELSE
FREQOUT 7, 1500, 2000 'Buzzer sounds
PAUSE 1500
DEBUG "You Lose!", CR 'Game over
ENDSELECT
DEBUG "Pattern 2", CR
GOSUB BBUTTON 'Blue button on
PAUSE 1000
GOSUB RBUTTON 'Red button on
PAUSE 1000
GOSUB BBUTTON 'Blue button on
PAUSE 1000
GOSUB GBUTTON 'Green button on
PAUSE 1000
GOSUB RBUTTON 'Red button on
PAUSE 1000
GOSUB LIGHTSOFF 'All lights off
DEBUG "Your Turn", CR
SELECT
CASE
HIGH 14
HIGH 3
HIGH 14
HIGH 12
HIGH 3
CASE ELSE
FREQOUT 7, 1500, 2000
PAUSE 1500
ENDSELECT
LOOP
END
''''''''''''''''''''''''''''''''''''''''''''''
' Subroutines
''''''''''''''''''''''''''''''''''''''''''''''
GBUTTON:
DEBUG "Green..."
HIGH 13
PAUSE 1500
LOW 13
RETURN
''''''''''''''''''''''''''''''''''''''''''''''
RBUTTON:
DEBUG "Red..."
HIGH 4
PAUSE 1500
LOW 4
RETURN
''''''''''''''''''''''''''''''''''''''''''''''
BBUTTON:
DEBUG "Blue..."
HIGH 15
PAUSE 1500
LOW 15
RETURN
''''''''''''''''''''''''''''''''''''''''''''''
LIGHTSOFF:
LOW 13
LOW 4
LOW 15
RETURN
pattern1 VAR Word
pattern2 VAR Word
DEBUG "Pattern 1", CR
DO
GOSUB GBUTTON 'Green button on
PAUSE 1500
GOSUB BBUTTON 'Blue button on
PAUSE 1500
GOSUB RBUTTON 'Red button on
PAUSE 1500
GOSUB LIGHTSOFF 'All lights off
DEBUG "Your Turn", CR
SELECT
CASE
HIGH 12
CASE ELSE
FREQOUT 7, 1500, 2000 'Buzzer sounds
PAUSE 1500
DEBUG "You Lose!", CR 'Game over
HIGH 14
CASE ELSE
FREQOUT 7, 1500, 2000 'Buzzer sounds
PAUSE 1500
DEBUG "You Lose!", CR 'Game over
HIGH 3
CASE ELSE
FREQOUT 7, 1500, 2000 'Buzzer sounds
PAUSE 1500
DEBUG "You Lose!", CR 'Game over
ENDSELECT
DEBUG "Pattern 2", CR
GOSUB BBUTTON 'Blue button on
PAUSE 1000
GOSUB RBUTTON 'Red button on
PAUSE 1000
GOSUB BBUTTON 'Blue button on
PAUSE 1000
GOSUB GBUTTON 'Green button on
PAUSE 1000
GOSUB RBUTTON 'Red button on
PAUSE 1000
GOSUB LIGHTSOFF 'All lights off
DEBUG "Your Turn", CR
SELECT
CASE
HIGH 14
HIGH 3
HIGH 14
HIGH 12
HIGH 3
CASE ELSE
FREQOUT 7, 1500, 2000
PAUSE 1500
ENDSELECT
LOOP
END
''''''''''''''''''''''''''''''''''''''''''''''
' Subroutines
''''''''''''''''''''''''''''''''''''''''''''''
GBUTTON:
DEBUG "Green..."
HIGH 13
PAUSE 1500
LOW 13
RETURN
''''''''''''''''''''''''''''''''''''''''''''''
RBUTTON:
DEBUG "Red..."
HIGH 4
PAUSE 1500
LOW 4
RETURN
''''''''''''''''''''''''''''''''''''''''''''''
BBUTTON:
DEBUG "Blue..."
HIGH 15
PAUSE 1500
LOW 15
RETURN
''''''''''''''''''''''''''''''''''''''''''''''
LIGHTSOFF:
LOW 13
LOW 4
LOW 15
RETURN
Comments
You should use constants for your pins. That would make the code much more readable.
I would also look at your case statements. I'm not to familiar with PBASIC, but they sure don't look right to me: the syntax seems wrong. For example, you have three ELSE cases within one select. What I think you want would be something like this:
(look at the idea behind the code. It's not syntactically correct)
In the future, when you put code in your posts, it would make it easier on us if it a) used good indentation and b) you used the "code" format tags ( [ code ] and [ /code ] without the spaces).