Highly broken game of simon.
This commit is contained in:
parent
ad94595721
commit
f11a72cfe2
50
simon/simon
Executable file
50
simon/simon
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simon notes
|
||||||
|
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
|
||||||
|
i=0
|
||||||
|
while read -n1 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
|
||||||
|
play -q -n synth .5 ${notes[$key]} norm -9 &
|
||||||
|
fi
|
||||||
|
# make sure the player pattern is the same as the computer generated one
|
||||||
|
if [ "${player[$i]}" != "${pattern[$i]}" ]; then
|
||||||
|
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
|
||||||
|
((i++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $continue -ne 0 ]; then
|
||||||
|
# sleep slightly longer than the length of one note.
|
||||||
|
sleep .6
|
||||||
|
pattern=(${pattern[@]} $(($RANDOM % 4 + 1)))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "You got $((${#pattern[@]} - 1)) correct."
|
||||||
|
exit 0
|
Loading…
Reference in New Issue
Block a user