It's alive!
This commit is contained in:
parent
f11a72cfe2
commit
fc2156effe
13
simon/simon
13
simon/simon
@ -4,27 +4,25 @@
|
||||
notes=("sq E4" "sq C#4" "sq A3" "sq E3")
|
||||
#Original note.
|
||||
pattern=($(($RANDOM % 4)))
|
||||
# Clear the player variable
|
||||
unset player
|
||||
#Here is the main loop of the program
|
||||
continue=1
|
||||
while [ $continue -ne 0 ]; do
|
||||
# Play the pattern to match
|
||||
echo "pattern is ${pattern[@]}"
|
||||
for i in ${pattern[@]} ; do
|
||||
play -q -n synth .5 ${notes[$i]} norm -9
|
||||
done
|
||||
# Loop to read the player's input and compare it to the pattern
|
||||
# Clear the player variable
|
||||
unset player
|
||||
i=0
|
||||
while read -n1 key ; do
|
||||
while read -sn1 key ; do
|
||||
key="$(echo "$key" | tr 'fk' '0')"
|
||||
key="$(echo "$key" | tr 'dj' '1')"
|
||||
key="$(echo "$key" | tr 'ir' '2')"
|
||||
key="$(echo "$key" | tr 'eu' '3')"
|
||||
echo "key is $key"
|
||||
player=(${player[@]} $key)
|
||||
# make sure the pressed key exists in the array.
|
||||
if [[ "$key" =~ [1-4] ]]; then
|
||||
if [[ "$key" =~ [0-3] ]]; then
|
||||
play -q -n synth .5 ${notes[$key]} norm -9 &
|
||||
fi
|
||||
# make sure the player pattern is the same as the computer generated one
|
||||
@ -33,7 +31,6 @@ continue=0
|
||||
break
|
||||
fi
|
||||
# If the arrays are equal then break the loop, else increment i.
|
||||
echo "Player = ${player[@]}"
|
||||
if [ ${#player[@]} -eq ${#pattern[@]} ]; then
|
||||
break
|
||||
else
|
||||
@ -43,7 +40,7 @@ done
|
||||
if [ $continue -ne 0 ]; then
|
||||
# sleep slightly longer than the length of one note.
|
||||
sleep .6
|
||||
pattern=(${pattern[@]} $(($RANDOM % 4 + 1)))
|
||||
pattern=(${pattern[@]} $(($RANDOM % 4)))
|
||||
fi
|
||||
done
|
||||
echo "You got $((${#pattern[@]} - 1)) correct."
|
||||
|
Loading…
Reference in New Issue
Block a user