-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimon.sh
140 lines (118 loc) · 2.08 KB
/
Simon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#./Simon.sh
clear
echo "The rules are simple: "
echo ""
echo "Remember colors in order of their appearing"
echo ""
echo "User ARROW KEYS (UP, DOWN, RIGHT, LEFT) to input colors"
echo ""
read -n 1 -s -r -p "Press any key to Start:"
clear
#declare -ia user_nums #array
declare -i score=1
game_colors=""
user_colors=""
function levelup(){
score+=1
}
function FillArray(){
MAXCOUNT=99
count=0
while [ "$count" -le $MAXCOUNT ]; do
numbers[$count]=$(( ( RANDOM % 4 ) + 1 ))
let "count += 1"
done
######
echo "Total Elements:" ${#numbers[@]}
echo "First element:" ${numbers[0]}
echo "${numbers[*]}"
#####
}
FillArray
function GameRound(){
MAXCOUNT=`expr $1`
i=0
while [ "$i" -ne $MAXCOUNT ]; do
if [[ ${numbers[$i]} = 1 ]];then
clear
echo -e "\e[32mGreen"
echo $i
game_colors+="g"
elif [[ ${numbers[$i]} = 2 ]];then
clear
echo -e "\e[31mRed"
echo $i
game_colors+="r"
elif [[ ${numbers[$i]} = 3 ]];then
clear
echo -e "\e[33mYellow"
echo $i
game_colors+="y"
elif [[ ${numbers[$i]} = 4 ]];then
clear
echo -e "\e[34mBlue"
echo $i
game_colors+="b"
fi
sleep 1.4
let "i += 1"
echo -e "\e[39m"
done
}
function TestInput(){
clear
echo -e "\t\e[32mGreen"
echo -e "\e[31mRed" "\t\t\e[33mYellow"
echo -e "\t\e[34mBlue"
counter=0
t=""
while [[ ${#user_colors} < ${#game_colors} ]]
do
read -r -sn1 t
case $t in
A) echo -e "\e[32mGreen"
user_colors+="g"
counter+=1 ;;
B) echo -e "\e[34mBlue"
user_colors+="b"
counter+=1 ;;
C) echo -e "\e[33mYellow"
user_colors+="y"
counter+=1 ;;
D) echo -e "\e[31mRed"
user_colors+="r"
counter+=1 ;;
[qQ]) echo $user_colors
counter=0
;;
esac
done
echo " "
#echo -e "\e[39m$user_colors"
echo -e "\e[39mActual colors were: " "$game_colors"
}
function Judge(){
if [ "$game_colors" == "$user_colors" ]; then
return 0
else
return 1
fi
}
function GameInit(){
GameRound $1
echo $game_colors
TestInput
if Judge; then
echo "win"
game_colors=""
user_colors=""
levelup
GameInit $score
else
echo "You've lost"
echo "SCORE" $score
exit 0
fi
}
GameInit $score