-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourceCode.txt
More file actions
426 lines (402 loc) · 11.1 KB
/
sourceCode.txt
File metadata and controls
426 lines (402 loc) · 11.1 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/bin/bash
declare -a Board
size=100;
declare -a Basket
let ActualScore=0;
filename="highscore.txt"
HighScore=$(<highscore.txt)
timer=0
#=============================================
#Initializing the Game Board
#=============================================
function DrawBoard()
{
for ((i=0;i<size;i++))
do
Board[$i]=$i
done
}
#=============================================
#Printing the Board
#=============================================
function PrintBoard()
{
let breakCounter=0;
for ((i=0;i<size;i++))
do
if (($breakCounter==9));
then
if (($i<=9))
then
printf "\t${Board[$i]} \n"
((breakCounter=0))
else
printf "\t${Board[$i]} \n"
((breakCounter=0))
fi
else
if (($i<=9))
then
printf "\t${Board[$i]} "
((breakCounter++))
else
printf "\t${Board[$i]}"
((breakCounter++))
fi
fi
done
}
#=============================================
#Printing the Empty Board
#=============================================
function EmptyBoard()
{ echo "Timer: "
duration=$((SECONDS-start))
tput cup 0 0
printf "\n"
printf "$duration\n"
printf "\t\t\t\t ___ __ ___ ___\n"
printf "\t\t\t\t/ |__| | / |__|\n"
printf "\t\t\t\t\___ | | | \___ | |\n"
printf "\t\t\t\t\t\tTHE FRUITS\n\n\n"
printf "\tMove Basket with A and D"
printf "\t\t\tScore = $ActualScore \n"
printf "\t\t\t\t\t\t\tHighScore = $HighScore \n"
let breakCounter=0;
for ((i=0;i<size;i++))
do
if (($breakCounter==9))
then
if [ ${Board[$i]} == "A" ] || [ ${Board[$i]} == "B" ] || [ ${Board[$i]} == "C" ] || [ ${Board[$i]} == "W" ] || [ ${Board[$i]} == "M" ] || [ ${Board[$i]} == "L" ] || [ ${Board[$i]} == "X" ]
then
printf "\t${Board[$i]}|\n|"
((breakCounter=0))
else
printf "\t |\n|"
((breakCounter=0))
fi
else
if [ ${Board[$i]} == "A" ] || [ ${Board[$i]} == "B" ] || [ ${Board[$i]} == "C" ] || [ ${Board[$i]} == "W" ] || [ ${Board[$i]} == "M" ] || [ ${Board[$i]} == "L" ] || [ ${Board[$i]} == "X" ]
then
printf "\t${Board[$i]}"
((breakCounter++))
else
printf "\t "
((breakCounter++))
fi
fi
done
}
#=============================================
#Inialize the Basket
let Randomindex=0
#=============================================
function DrawBasket()
{
for ((i=0;i<10;i++))
do
Basket[$i]=$i
done
Randomindex=$(($RANDOM % 9))
Basket[$Randomindex]="\_/"
}
#=============================================
#Display Basket
#=============================================
function PrintBasket()
{
for ((i=0;i<10;i++))
do
if [ ${Basket[$i]} == "\_/" ]
then
printf "\t\_/"
elif [ ${Basket[$i]} == 9 ]
then
if [ ${Basket[$i]} == "\_/" ]
then
printf "\t\_/\n"
else
printf "\t \n"
fi
else
printf "\t "
fi
done
}
#=============================================
#Move Basket
#=============================================
function MoveBasket()
{
printf "\n"
read -t 1 opt
temp1=$Randomindex;
if [ "$opt" == "A" ] || [ "$opt" == "a" ]
then
Basket[$Randomindex]=$temp1
((Randomindex--))
if [ $Randomindex == -1 ]
then
temp1=9
Basket[9]="\_/"
opt=0
Randomindex=9
elif [ $Randomindex -gt -1 ]
then
temp1=Basket[$Randomindex]
Basket[$Randomindex]="\_/"
opt=0
fi
elif [ "$opt" == "D" ] || [ "$opt" == "d" ]
then
Basket[$Randomindex]=$temp1
((Randomindex++))
if [ $Randomindex == 10 ]
then
temp1=0
Basket[0]="\_/"
opt=0
Randomindex=0
elif [ $Randomindex -le 10 ]
then
temp1=Basket[$Randomindex]
Basket[$Randomindex]="\_/"
opt=0
fi
fi
}
#=============================================
#RANDOM FRUIT
#dummy initialization
#=============================================
function Randomfruit()
{
if((whichfruit==1))
then
whichfruit=" A"
#Apple
elif((whichfruit==2))
then
whichfruit=" M"
#Mango
elif((whichfruit==3))
then
whichfruit=" L"
#Lemon
elif((whichfruit==4))
then
whichfruit=" W"
#watermelon
elif((whichfruit==5))
then
whichfruit=" B"
#Banana
elif((whichfruit==6))
then
whichfruit=" C"
#Cherry
elif((whichfruit==7))
then
whichfruit=" X"
#junk fruit
fi
}
#=============================================
#Drop the fruit
#=============================================
function DropFruit()
{ clear
let Fruit1=$(($RANDOM % 9))
let jump=10
whichfruit=$(($RANDOM % 8))
if((whichfruit==0))
then
((whichfruit++))
fi
while [ $Fruit1 -le $size ]
do
let temp=Board[$Fruit1]
Randomfruit
Board[$Fruit1]=$whichfruit
clear
#PrintBoard
EmptyBoard
PrintBasket
Board[$Fruit1]=$temp;
((Fruit1=Fruit1+jump))
CalculateScore
checkMaximm
MoveBasket
done
}
#=============================================
#Calculate Score Disappear
#=============================================
function CalculateScore()
{
let forScore=$Randomindex
((forScore+=100))
if [ $forScore == $Fruit1 ]
then
if [ "$whichfruit" == " X" ]
then
((ActualScore=ActualScore-5))
else
((ActualScore+=5))
fi
fi
}
#=============================================
#C H E C K - M A X I M U M
#=============================================
function checkMaximm()
{
if [[ "$ActualScore" -gt "$HighScore" ]]
then
printf "\nBoooom!! New High Score :-)\n"
echo $ActualScore>$filename
sleep 1
fi
}
#=============================================
#H I G H _ S C O R E
#=============================================
function HighScorefun()
{
printf "\t\t\t _____ _____ _______ _____ _ _ \n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t || ||___|| || || | |___| |\n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t ===== || || || ===== |_| |_|\n"
printf "\n\t\t\t\t\t\t\t\tT H E _ F R U I T S\n\n\n"
if [[ "$ActualScore" -gt "$HighScore" ]]
then
printf "\t\t\t\tHIGH-SCORE = $ActualScore \n"
else
printf "\t\t\t\tHIGH-SCORE = $HighScore \n"
fi
#sleep 4
Thankyou
clear
}
#=============================================
#Boom Welcome
#=============================================
function Boom()
{
printf "\t\t\t _____ _____ _______ _____ _ _ \n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t || ||___|| || || | |___| |\n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t ===== || || || ===== |_| |_|\n"
printf "\n\t\t\t\t\t\t\t\tT H E _ F R U I T S\n\n\n"
sleep 0.5
printf "\t\t\t\t\t"Loading
while [ $SECONDS -le 3 ]
do
printf "."
sleep 0.3
done
printf "\n"
}
#=============================================
#PLAY GUIDLINES
#=============================================
function PlayGuide()
{
clear
printf "\t\tP L A Y _ G U I D E L I N E S\n\n\n"
printf "\t\tFRUIT NAMES.\n"
printf "\t\t1) A = APPLE\n"
printf "\t\t2) M = MANGO\n"
printf "\t\t3) L = LEMON\n"
printf "\t\t4) W = WATERMELON\n"
printf "\t\t5) B = BANANA\n"
printf "\t\t6) C = CHERRY\n"
printf "\t\t7) X = JUNK FRUIT\n\n\n"
printf "\t\tINSTRUCTIONS\n"
printf "\t\tPRESS 'A' OR 'a' TO MOVE BASKET LEFT BY 1 INDEX.\n"
printf "\t\tPRESS 'D' OR 'd' TO MOVE BASKET RIGHT BY 1 INDEX.\n"
printf "\t\tCATCHING A FRUIT ADDS UP 5 POINTS IN TOTAL SCORE.\n\n"
printf "\t\tWATCH OUT FOR THE JUNK FRUIT 'X'. IT WILL DEDUCT THE SCORE BY 5 POINTS.\n"
printf "\t\tENJOY THE GAME!!!\n\n"
}
#=============================================
#CREDITS
#=============================================
function Credits()
{
clear
printf "\t\t\t _____ _____ _______ _____ _ _ \n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t || ||___|| || || | |___| |\n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t ===== || || || ===== |_| |_|\n"
printf "\n\t\t\t\t\t\t\t\tT H E _ F R U I T S\n\n"
printf "\t\tT E A M _ M E M B E R S\n\n\n"
printf "\t\t1) MUHAMMAD ZAIN AHSAN.\t19f0228\n"
printf "\t\t2) DANISH AHMAD.\t19f0170\n"
printf "\t\t3) USAMA NOSHER.\t19f0269\n"
}
#=============================================
#THANKYOU
#=============================================
function Thankyou()
{
printf "\t\tTHANK YOU FOR PLAYING THIS FUN GAME.<3\n"
sleep 1
}
#=============================================
#MAIN MENU
#=============================================
function MainMenu()
{
Boom
clear
let Mchoice=0
while [ $Mchoice -ne 4 ]
do
printf "\t\t\t _____ _____ _______ _____ _ _ \n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t || ||___|| || || | |___| |\n"
printf "\t\t\t || || || || || | | | |\n"
printf "\t\t\t ===== || || || ===== |_| |_|\n"
printf "\n\t\t\t\t\t\t\t\tT H E _ F R U I T S\n\n"
printf "\t\t\t\tM A I N _ M E N U\n"
printf "\t\t\t\t1:Play the game\n"
printf "\t\t\t\t2:How to play Guide\n"
printf "\t\t\t\t3:Credits\n"
printf "\t\t\t\t4:Exit\n"
read -p " Input " Mchoice
if((Mchoice==1))
then
start=$((SECONDS))
DrawBoard
DrawBasket
while [ $SECONDS -le 61 ]
do
DropFruit
done
#clear
HighScorefun
elif((Mchoice==2))
then
PlayGuide
sleep 5
clear
elif((Mchoice==3))
then
Credits
sleep 3
clear
else
Thankyou
sleep 1
clear
fi
done
}
#=============================================
#int main
#=============================================
MainMenu