forked from klmov/DevOps-BootCamp-Bash-Style
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.sh
executable file
·47 lines (46 loc) · 943 Bytes
/
game.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
#!/bin/bash
echo -e "\n NumberJack \n"
ch=0
while [ $ch -ne 3 ]; do
echo "
PLAY : Hit 1 and enter.
HELP : Hit 2 and enter.
EXIT : Hit 3 and enter.
"
read -rp "Enter your choice : " ch
if [ "$ch" -eq 1 ]; then
x=0
c=0
p=0
read -rp "Enter any number between 0 and 9 : " n
while [ $c -eq 0 ]; do
x=11
r=("$(shuf -i 0-9 -n 10)")
echo "${r[@]}"
for i in {1..10}; do
a[$i]=$i
done
echo "${a[@]}"
read -rt 5 -p "Enter the index of your number : " x
if [[ $? -gt 128 ]]; then
c=1
break
fi
if [ "${r[((x - 1))]}" -eq "$n" ]; then
echo "Great"
(( p++ ))
else
c=1
break
fi
done
elif [ "$ch" -eq 2 ]; then
echo "HELP: INSTRUCTIONS TO PLAY THE GAME. "
else
break
fi
if [ "$c" -eq 1 ]; then
echo -e "\nGAME OVER\n"
echo "You scored $p points"
fi
done