-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyarsg.sh
More file actions
executable file
·246 lines (208 loc) · 6.37 KB
/
yarsg.sh
File metadata and controls
executable file
·246 lines (208 loc) · 6.37 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# ============================================================================ #
# __ __ _____ _____ _____ #
# \ \ / //\ | __ \ / ____|/ ____| #
# \ \_/ // \ | |__) | (___ | | __ #
# \ // /\ \ | _ / \___ \| | |_ | #
# | |/ ____ \| | \ \ ____) | |__| | #
# |_/_/ \_\_| \_\_____/ \_____| #
# #
# Yet Another RPG Style Game #
# a simple game by niro, with love #
# #
# ============================================================================ #
# ------------------------------------------------------------------------------
# VARIABLES
# ------------------------------------------------------------------------------
launch=$1
# Enemy
enemyHPmax=20
enemyHP=$enemyHPmax
enemyAtk=""
# Player
playerHPmax=25
playerHP=$playerHPmax
playerStamina=20
pleayerPotions=3
# Attacks
enemyDMG=5
playerLightDMG=3
playerHeavyDMG=5
playerLightCost=2
playerHeavyCost=6
playerHeal=7
# ------------------------------------------------------------------------------
# FUNCTIONS
# ------------------------------------------------------------------------------
function actionPick() {
while true; do
echo $enemyAtk
fight_print
printf " >> "
read input
if (( input == 3 & pleayerPotions <= 0 )); then
# No potions
clear
echo "!!! - You dont have enough potions to heal yourself! - !!!"
elif (( input == 1 | input == 2 | input == 3 )); then
# Action
action $input
break
else
# Bad input
clear
echo "!!! - Please put in only 1, 2 or 3 - !!!"
fi
done
}
function action() {
case $1 in
1)
# Light Attack
playerStamina=$(( playerStamina - playerLightCost ))
enemyHP=$(( enemyHP - playerLightDMG ))
break
;;
2)
# Heavy Attack
playerStamina=$(( playerStamina - playerHeavyCost ))
enemyHP=$(( enemyHP - playerHeavyDMG ))
break
;;
3)
# Heal
playerHP=$(( playerHP + playerHeal ))
pleayerPotions=$(( pleayerPotions - 1 ))
# Dont go over max HP thingy
if (( playerHP > playerHPmax )); then playerHP=$playerHPmax; fi
break
;;
*)
echo "if you see this, some error accured :("
break
;;
esac
}
function enemy_attack() {
# Critical Damage Chance
ran=$(( $RANDOM % 3 ))
crit=1
enemyAtk="The enemy attacked you with a normal attack!"
# Crit DMG
if (( ran == 0 )); then
#Crit successful
playerHP=$(( playerHP - crit ))
enemyAtk="The enemy attacked you with a strong attack, dealing" $crit "more damage."
elif (( ran == 1 )); then
#Crit unsuccessful
enemyAtk="The enemy attacked you with a weak attack, dealing" $crit "less damage."
playerHP=$(( playerHP + crit ))
fi
# Standard DMG
playerHP=$(( playerHP - enemyDMG ))
echo ""
}
function fight_print() {
echo "HP Enemy: " $enemyHP"/"$enemyHPmax
echo "HP Player: " $playerHP"/"$playerHPmax" Stamina: " $playerStamina
echo
echo " Type 1 for a light attack:" " - DMG:" $playerLightDMG " - Stamina Cost:" $playerLightCost
echo " Type 2 for heavy attack: " " - DMG:" $playerHeavyDMG " - Stamina Cost:" $playerHeavyCost
echo " Type 3 to heal yourself: " " - HP+:" $playerHeal " - Potions:" $pleayerPotions
}
function winScreen() {
while true; do
clear
echo "__ ___ "
echo "\ \ / (_) "
echo " \ \ /\ / / _ _ __ _ __ ___ _ __ "
echo " \ \/ \/ / | | '_ \| '_ \ / _ \ '__|"
echo " \ /\ / | | | | | | | | __/ | "
echo " \/ \/ |_|_| |_|_| |_|\___|_| "
echo " "
echo " You defeated the enemy! "
echo " Your HP:" $playerHP "- Your Stamina:" $playerStamina
echo " "
echo " <press enter to quit this program> "
echo " "
printf " > > "
read exit
break
done
}
function loseScreen() {
while true; do
clear
echo " _____ __ _ "
echo " | __ \ / _| | | "
echo " | | | | ___| |_ ___ __ _| |_ "
echo " | | | |/ _ \ _/ _ \/ _' | __| "
echo " | |__| | __/ || __/ (_| | |_ "
echo " |_____/ \___|_| \___|\__,_|\__| "
echo " "
if (( playerStamina < 0 )); then
echo " You ran out of stamina! "
else
echo " The enemy has defeated you! "
fi
echo " Your HP:" $playerHP "- Your Stamina:" $playerStamina
echo " Enemy HP:" $enemyHP
echo " "
echo " <press enter to quit this program> "
echo " "
printf " > > "
read exit
break
done
}
function welcome() {
clear
echo " __ __ _____ _____ _____ "
echo " \ \ / //\ | __ \ / ____|/ ____| "
echo " \ \_/ // \ | |__) | (___ | | __ "
echo " \ // /\ \ | _ / \___ \| | |_ | "
echo " | |/ ____ \| | \ \ ____) | |__| | "
echo " |_/_/ \_\_| \_\_____/ \_____| "
echo " "
echo " Yet Another RPG Style Game "
echo " a simple game by niro "
echo " "
echo " <press enter to start the game> "
echo " "
printf " > > "
read start
}
function helpScreen() {
echo \-\e "This is the help screen!"\\\n"Here you will find general information about the game:"
}
# ------------------------------------------------------------------------------
# MAIN LOOP
# ------------------------------------------------------------------------------
case $launch in
h)
helpScreen
;;
*)
# Welcome screen
welcome
while true; do
clear
# Player Attack, Stamina Check, Enemy Alive Check
actionPick
if (( playerStamina < 0 )); then
loseScreen
break
fi
if (( enemyHP <= 0 )); then
winScreen
break
fi
# Enemy Attack and Player Alive Check
sleep 0.2
enemy_attack
if (( playerHP <= 0 )); then
loseScreen
break
fi
done
;;
esac