forked from integrii/bashgame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.sh
executable file
·137 lines (129 loc) · 2.82 KB
/
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
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
134
135
136
137
#!/bin/bash
# Bashgame for bash learning
#RNG
random() {
NUMBER=$[ ( $RANDOM % $1 ) + 1 ]
echo $NUMBER
}
# Monster list
monster() {
choice=`random 5`
if [[ $choice -eq 1 ]]; then
monname="House cat"
monhealth=4
monattack=6
monspattack=8
fi
if [[ $choice -eq 2 ]]; then
monname="Tiger"
monhealth=17
monattack=19
monspattack=25
fi
if [[ $choice -eq 3 ]]; then
monname="Giraffe"
monhealth=70
monattack=4
monspattack=6
fi
if [[ $choice -eq 4 ]]; then
monname="Horse"
monhealth=14
monattack=8
monspattack=12
fi
if [[ $choice -eq 5 ]]; then
monname="Rabbit"
monhealth=2
monattack=3
monspattack=4
fi
}
status() {
echo "Your name: $name"
echo "Health: $health"
echo "Attack: $attack"
echo "Kills: $kills"
if [[ $healpotion -gt 0 ]]; then
echo "Heal Potions: $healpotion"
fi
}
# Set starting stats
health=100
attack=10
kills="0"
echo "Welcome to Basher Inc"
echo -n "What is your name?: "
read name
while [[ $health -gt 0 ]]; do
monster
status
# Fight or run phase
echo "You are faced with a $monname"
echo -n "Do you wish to run or fight?: "
read rof
rof=$(echo "$rof" | tr '[:upper:]' '[:lower:]')
if [[ "$rof" = "fight" ]]; then
echo "You draw your weapon and face off against a $monname!"
else
echo "You sprint away and escape from a $monname!"
monhealth=0
fi
# Combat phase
while [[ $health -gt 0 && $monhealth -gt 0 ]]; do
echo "You attack for $attack damage."
sleep 1
monhealth=$(expr $monhealth - $attack)
echo "$monname hits you for $monattack damage."
sleep 1
health=$(expr $health - $monattack)
if [[ $monhealth -lt 1 ]]; then
echo "You have defeated a $monname! You have become more powerful!"
kills=$(expr $kills + 1)
attack=$(expr $attack + 1)
# Heal Potion
pot=`random 1`
if [[ $pot -eq 1 ]]; then
echo "You found a health potion! Press 1 to drink or 2 to save."
healpotion=$(expr $healpotion + 1)
select drink in "Drink" "Save"; do
case $drink in
Drink )
if [[ $healpotion -gt 0 ]]; then
health=$(expr $health + 20);
healpotion=$(expr $healpotion - 1);
else
echo "You dont have any health potions!"
fi
break;;
Save )
echo "You decide not to drink a health potion."
break;;
esac
done
fi
fi
# Death
if [[ $health -lt 1 ]]; then
echo "You're dead. :("
status
echo -n "Would you like to play again?: "
read again
again=$(echo "$again" | tr '[:upper:]' '[:lower:]')
if [[ $again = "yes" ]]; then
health=100
attack=10
kills="0"
monhealth=0
else
echo "$kills - $name" >> .highscores
cat .highscores | sort -n -r | tail -n 10 > .highscores.new
mv .highscores.new .highscores; rm -f .highscores.new
echo " -- HIGH SCORES -- "
cat .highscores
echo "GAME OVER!"
exit
fi
fi
done
done