-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman
executable file
·807 lines (717 loc) · 16.4 KB
/
hangman
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#! /usr/bin/env bash
DICT="/usr/share/dict/words"
SNDDIR="/etc/hangman/snd"
source "/etc/hangman/src/scores"
declare -a USEDWORDS
declare -a LETTERS
pos() ( tput cup "$@" )
smso() ( tput smso )
rmso() ( tput rmso )
red() ( tput setaf 1 )
green() ( tput setaf 2 )
yellow() ( tput setaf 3 )
blink() ( tput blink )
off() ( tput sgr0 )
max() ( local v1="$1" v2="$2"; echo $((v1>v2?v1:v2)) )
playsnd() {
which paplay > /dev/null || return 1
[[ $QUIET ]] && return 1
case $1 in
pause ) (paplay "$SNDDIR/pause.ogg" 2> /dev/null) & ;;
new ) paplay "$SNDDIR/new.ogg" 2> /dev/null;;
correct1 ) (paplay "$SNDDIR/correct1.ogg" 2> /dev/null) & ;;
correct2 ) (paplay "$SNDDIR/correct2.ogg" 2> /dev/null) & ;;
heal ) (paplay "$SNDDIR/heal.ogg" 2> /dev/null) & ;;
incorrect) (paplay "$SNDDIR/incorrect.ogg" 2> /dev/null) & ;;
win ) (paplay "$SNDDIR/win.ogg" 2> /dev/null) & ;;
flawless ) (paplay "$SNDDIR/flawless.ogg" 2> /dev/null) & ;;
lose ) (paplay "$SNDDIR/lose.ogg" 2> /dev/null) & ;;
point ) (paplay "$SNDDIR/point.ogg" 2> /dev/null) & SPID=$! ;;
use ) (paplay "$SNDDIR/use.ogg" 2> /dev/null) & ;;
super ) (paplay "$SNDDIR/superhangman.ogg" 2> /dev/null) & SPID=$! ;;
title ) (paplay "$SNDDIR/title.ogg" 2> /dev/null) & ;;
word ) (paplay "$SNDDIR/word.ogg" 2> /dev/null) & ;;
end ) (paplay "$SNDDIR/end.ogg" 2> /dev/null) & SPID=$! ;;
esac
}
color() {
[[ $CHAIN_MODE ]] && { green; return; }
[[ $CHAIN_MODE ]] || ((ENERGY<4)) && off
[[ $CHAIN_MODE ]] || ((ENERGY>=4 && ENERGY <=6)) && yellow
[[ $CHAIN_MODE ]] || ((ENERGY>6)) && red
}
word_use() {
local word
for word in "${USEDWORDS[@]}"; do
[[ $word == "$1" ]] && return 0
done
return 1
}
letter_used() {
local letter
for letter in "${LETTERS[@]}"; do
[[ $letter == "${1^^}" ]] && return 0
done
return 1
}
word_random() {
local word
while :; do
word="$(shuf -n 1 "$DICT")"
word="${word^^}" # Conversion en majuscules.
# On ignore les mots de moins de 6 lettres.
(( ${#word} < 6 )) && continue
# On ignore les mots contenant une apostrophe.
[[ $word =~ [\'] ]] && continue
# On ignore les mots déjà utilisés.
word_use "$word" && continue
# Si toutes les conditions sont satisfaites
# on ajoute le mot à liste des mots utilisés.
USEDWORDS+=("$word")
echo "$word" # Affichage.
break # Sortie de la boucle.
done
}
hide_word() {
local src L L1 Ln lng dst i
src="$1" # Le mot d'origine.
lng="${#src}" # Longueur du mot.
L1="${src:0:1}" # Première lettre.
Ln="${src:$lng-1:1}" # Dernière lettre.
# La boucle permet de lire chaque lettre du mot.
for ((i=0;i<lng;i++)); do
L="${src:$i:1}"
[[ $L =~ [ÀÂÄÉÈÊËÎÏÔÖÙÛÜÇ-]|[${L1}${Ln}] ]] && {
# Aucun changement pour les lettres ci-dessus...
# on les ajoute simplement à dst
dst+="$L"
continue
}
# Sinon on hide...
dst+="_"
done
echo "$dst"
}
is_extra() {
# Détermine si une lettre fait partie des lettres "extra"
# Une lettre "extra" peut être la première ou la dernière lettre du mot à deviner.
# Elles peuvent octroyer un bonus supplémentaire quand elles sont jouées au moment
# opportun...
local letter
letter="${1^^}"
letter_used "$letter" && return 1
[[ ${WORD:0:1} == "$letter" ]] ||
[[ ${WORD:${#MOT}-1:1} == "$letter" ]] && return 0
return 1
}
top_word() {
((PARTIALSCORE>TOPWORDSCORE)) && {
TOPWORD="$WORD"
((TOPWORDSCORE=PARTIALSCORE))
}
}
unveil() {
local index i dst
index="$1"
for ((i=0;i<${#WORD};i++)); do
(( i == index )) && dst+="${WORD:$i:1}" || dst+="${HIDDEN:$i:1}"
done
HIDDEN="$dst"
}
guess() {
local letter i result
result=1 # 0 : vrai ; 1 : faux.
letter="${1^^}" # Lettre proposée par le joueur convertie en majuscule.
for ((i=0;i<${#WORD};i++)); do
[[ ${WORD:$i:1} == "$letter" ]] && {
unveil $((i))
result=0
}
done
return $((result))
}
init_screen() {
Y_TERM="$(tput lines)"
X_TERM="$(tput cols)"
tput smcup
tput civis
stty -echo
tput clear
}
deinit_screen() {
tput clear
tput cnorm
tput rmcup
stty sane
}
screen_title() {
local msg y x
playsnd super
WORD="- SUPER HANG MAN LEGEND -"
HIDDEN="$(hide_word "$WORD")"
red
display_hidden_word
sleep 1
unveil_hidden_word
playsnd title
msg="スーパーハングマンの伝説"
((y=(Y_TERM/2)+1))
((x=(X_TERM-(${#msg}*2))/2))
pos $((y)) $((x))
echo -n "$msg"
msg="press any key..."
((y=(Y_TERM/2)+2))
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
blink
echo -n "$msg"
off
read -rsn1
clear_letters
((y=(Y_TERM/2)+1))
pos $((y)) 0; tput el
red
display_word_animated
off
tput clear
}
screen_end() {
local maxscore msg y x
((maxscore=MAXSCORE>0?100*SCORE/MAXSCORE:0))
((TARGETSCORE>0)) && \
msg="FINAL SCORE: $SCORE | V: $WIN | xC: $CHAIN_MAX | xS: $MAXSTREAK | $((maxscore))%"
((TARGETSCORE==0)) && \
msg="FINAL SCORE: $SCORE | V: $WIN | xC: $CHAIN_MAX | xS: $MAXSTREAK | $((maxscore))%"
((y=(Y_TERM/2)-2))
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
}
display() {
color
display_energy
display_score
display_header
display_info
display_top_word
}
display_message() {
# Affiche un message temporaire...
local msg y x
msg="$1"
((y=(Y_TERM/2)-3))
((x=(X_TERM-${#msg})/2))
pos $((y)) 0; tput el
[[ $msg ]] || return 0
pos $((y)) $((x)); echo -n "$msg"
}
display_hidden_word() {
local y x l count
l="${#HIDDEN}"
((y=Y_TERM/2))
((x=(X_TERM-l)/2))
pos $((y)) $((x))
[[ $1 ]] || {
COUNT="$(grep "^${HIDDEN//_/.}$" -ic "$DICT")"
echo -n " ${HIDDEN} "
pos $((y+1)) $((x))
tput el
echo -n " [ 1/${COUNT} ] "
}
[[ $1 == "victoire" ]] && {
smso
echo -n " $HIDDEN "
rmso
pos $((y+1)) 1
tput el
}
}
display_letters() {
local y x l L
L="${LETTERS[*]}"
l="${#L}"
((y=(Y_TERM/2)+2))
((x=(X_TERM-l)/2))
pos $((y)) $((x))
echo -n "$L"
}
display_letter_used() {
local letter L index
letter="${1^^}"
index=0
for L in "${LETTERS[@]}"; do
[[ $L == "$letter" ]] && {
LETTERS[$index]=" "
playsnd use
display_letters
sleep 0.25
LETTERS[$index]="$letter"
display_letters
break
}
((index++))
done
}
clear_hidden_word() {
local y
((y=Y_TERM/2))
pos $((y)) 0
tput el
}
clear_letters() {
local y
((y=(Y_TERM/2)+2))
pos $((y)) 0
tput el
}
display_header() {
local header y x
header="SCORE"
((y=(Y_TERM/2)-9))
((x=(X_TERM-5)/2))
pos $((y)) $((x))
echo -n "$header"
header="$MODE MODE |"
((x=((X_TERM/2)-${#header})/2))
pos $((y)) $((x))
echo -n "$header"
header="| TOP: $(max "$SCORE" "$TOPSCORE")"
((x=(X_TERM/4)+((X_TERM-${#header})/2)))
pos $((y)) $((x))
echo -n "$header"
}
display_score() {
local y x
((y=(Y_TERM/2)-8))
[[ $1 ]] || ((x=(X_TERM-${#SCORE})/2))
[[ $1 ]] && ((x=(X_TERM-${#1})/2))
pos $((y)) $((x))
[[ $1 ]] || echo -n "$SCORE"
[[ $1 ]] && echo -n "$1"
}
display_energy() {
local msg y x index
((index=ENERGY_MAX-ENERGY))
((y=(Y_TERM/2)-7))
((ENERGY==ENERGY_MAX)) && {
pos $((y)) 0
tput el
return 0
}
msg="${ENERGY_BAR:0:$index} $index"
((x=(X_TERM-ENERGY_MAX)/2))
pos $((y)) $((x))
echo -n "$msg"
tput el
}
display_info() {
local msg y x
((y=(Y_TERM/2)+8))
msg="V: $WIN | S: $STREAK | xS: $MAXSTREAK | C: $CHAIN | xC: $CHAIN_MAX"
((x=(X_TERM-${#msg})/2))
pos $((y)) 0; tput el
pos $((y)) $((x))
echo -n "$msg"
}
display_top_word() {
[[ $TOPWORD ]] && {
local msg y x
msg="BEST: $TOPWORD $TOPWORDSCORE"
((y=(Y_TERM/2)+9))
((x=(X_TERM-${#msg})/2))
pos $((y)) 0; tput el
pos $((y)) $((x))
echo -n "$msg"
}
}
display_centered_message() {
local msg y x
msg="$1"
((y=Y_TERM/2))
((x=(X_TERM-${#1})/2))
pos $((y)) 0; tput el
[[ $msg ]] && {
pos $((y)) $((x))
echo -n "$msg"
}
}
chain() {
local e
((ENERGY>0)) && [[ $MODE == "EASY" ]] && {
((e=ENERGY_MAX-ENERGY))
((e==0)) || ((ENERGY--))
}
[[ $MODE == "EASY" ]] && ((SCORE+=(CHAIN-2)*50))
[[ $MODE == "NORMAL" ]] && ((SCORE+=(CHAIN-2)*100))
[[ $MODE == "HARD" ]] && ((SCORE+=(CHAIN-2)*150))
display_message "+$((SCORE-PREVSCORE)) !"
((PARTIALSCORE+=SCORE-PREVSCORE))
((ACTUALSCORE+=SCORE-PREVSCORE))
((PREVSCORE=SCORE))
display_score_animated
}
compute_target_score() {
local i len target=0
declare -A UNIQUE
[[ $MODE == "EASY" ]] && {
TARGETSCORE=0
return
}
for ((i=0;i<${#WORD};i++)); do
[[ ${WORD:$i:1} =~ [àâäéèêëîïôöùûüÀÂÄÉÈÊËÎÏÔÖÙÛÜçÇ] ]] && continue
UNIQUE+=("${WORD:$i:1}" 1)
done
((len=${#UNIQUE[*]}-2))
unset UNIQUE
for ((i=1;i<=len;i++)); do
[[ $MODE == "NORMAL" ]] && ((target+=i*100))
[[ $MODE == "HARD" ]] && ((target+=i*150))
done
((target+=(10-ENERGY)*${#WORD}))
[[ $MODE == "NORMAL" ]] && ((target+=500))
[[ $MODE == "HARD" ]] && ((target+=1000))
((STREAK>1)) && {
[[ $MODE == "NORMAL" ]] && ((target+=(STREAK-2+1)*2500))
[[ $MODE == "HARD" ]] && ((target+=(STREAK-2+1)*5000))
}
((TARGETSCORE=target))
}
compute_score() {
local msg y x
((y=Y_TERM/2))
clear_hidden_word
clear_letters
[[ $FLAWLESS ]] && {
((STREAK++))
((MAXSTREAK=MAXSTREAK<STREAK?STREAK:MAXSTREAK))
display_info;
[[ $MODE == "EASY" ]] && ((SCORE+=250))
[[ $MODE == "NORMAL" ]] && ((SCORE+=500))
[[ $MODE == "HARD" ]] && ((SCORE+=1000))
((ACTUALSCORE+=SCORE-PREVSCORE))
msg="FLAWLESS: +$((SCORE-PREVSCORE))"
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
display_score_animated
((PARTIALSCORE+=SCORE-PREVSCORE))
((PREVSCORE=SCORE))
sleep 1
pos $((y)) 0; tput el
}
((STREAK>=3)) && {
[[ $MODE == "EASY" ]] && ((SCORE+=(STREAK-2)*500))
[[ $MODE == "NORMAL" ]] && ((SCORE+=(STREAK-2)*2500))
[[ $MODE == "HARD" ]] && ((SCORE+=(STREAK-2)*5000))
((ACTUALSCORE+=SCORE-PREVSCORE))
msg="BONUS: +$((SCORE-PREVSCORE))"
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
display_score_animated
((PARTIALSCORE+=SCORE-PREVSCORE))
((PREVSCORE=SCORE))
sleep 1
pos $((y)) 0; tput el
}
((SCORE+=(10-ENERGY)*${#WORD}))
((ACTUALSCORE+=SCORE-PREVSCORE))
msg="SCORE: +$((SCORE-PREVSCORE))"
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
display_score_animated
((PARTIALSCORE+=SCORE-PREVSCORE))
((PREVSCORE=SCORE))
sleep 1
pos $((y)) 0; tput el
sleep 2
}
heal() {
((WIN%2==0 && ENERGY>0)) && {
case $MODE in
EASY ) return ;;
NORMAL) ENERGY=$((WIN%6==0?0:ENERGY-1)) ;;
HARD ) ENERGY=$((WIN%10==0?0:ENERGY-1))
esac
green
display_message "ENERGY+"
playsnd heal
display_energy
off
sleep 1
display_message
}
}
display_score_animated() {
local dif step i
((dif=SCORE-PREVSCORE))
if ((dif<100)); then ((step=1))
elif ((dif<1000)); then ((step=5))
else ((step=dif/100))
fi
playsnd point 2> /dev/null
for ((i=PREVSCORE;i<=SCORE;i+=step)); do
display_score "$i"
done
display_score
kill $SPID 2> /dev/null
unset SPID
}
display_word_letter_count() {
local msg y x
msg="${#WORD} LETTERS"
((y=Y_TERM/2))
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
}
unveil_hidden_word() {
local l i
l="${#WORD}"
for ((i=0;i<l;i++)); do
unveil $((i))
display_hidden_word
sleep .25
done
}
display_word_animated() {
local L y y2 x i
L="${#WORD}"
((y=Y_TERM/2))
((x=(X_TERM-L)/2))
for ((i=x;i<x+L;i++)); do
((y2=y))
while ((y2<Y_TERM-2)); do
pos $((y2)) $((i)); echo -n " "
pos $((y2+1)) $((i)); echo -n "${WORD:$((i-x)):1}"
((y2++))
done
pos $((y2)) $((i)); echo -n " "
done
}
display_end() {
local msg y x
msg=" - GAME OVER - "
((y=Y_TERM/2))
((x=(X_TERM-${#msg})/2))
tput clear
pos $((y)) $((x))
echo -n "$msg"
sleep 3
tput clear
}
get_player_name() {
local msg letter player y x i
((y=(Y_TERM/2)))
msg="NEW HIGH SCORE ! ENTER YOUR NAME :"
((x=(X_TERM-${#msg})/2))
pos $((y-1)) $((x))
echo -n "$msg"
msg="---"
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
i=0
while ((i<3)); do
read -rsn1 letter || continue
[[ $letter =~ [A-Za-z] ]] || continue
letter="${letter^^}"
pos $((y)) $((x+i))
echo -n "$letter"
playsnd correct1
player+="$letter"
((i++))
done
sleep 1
PLAYER="$player"
}
display_scoreboard() {
local y x i msg score
tput clear
off
((y=(Y_TERM/2)-6))
sleep 2
i=0
while read -r score; do
((x=(X_TERM-${#score})/2))
pos $((y+i)) $((x))
[[ $POSITION ]] && ((i == POSITION+1)) && blink
echo -n "$score"
[[ $POSITION ]] && ((i == POSITION+1)) && off
sleep 1
((i++))
done <<< "$(display_scores)"
}
refresh_screen() {
Y_TERM="$(tput lines)"
X_TERM="$(tput cols)"
tput clear
display
display_hidden_word
}
pause() {
local y x msg
msg="- PAUSE -"
tput clear
((y=Y_TERM/2))
((x=(X_TERM-${#msg})/2))
pos $((y)) $((x))
echo -n "$msg"
playsnd pause
read -rsn1
playsnd pause
refresh_screen
}
trap 'deinit_screen; exit' INT
trap refresh_screen WINCH
init_screen
MODE="NORMAL"
for opt in "${@}"; do
case $opt in
splash|s) shift; SPLASH=1 ;;
easy|e ) shift; MODE="EASY" ;;
hard|h ) shift; MODE="HARD" ;;
rank|r ) shift; RANK=1 ;;
quiet|q ) shift; QUIET=1
esac
done
(( RANK )) && {
display_scoreboard
sleep 5
deinit_screen
exit 0
}
(( SPLASH )) && screen_title
RUNNING=1
ENERGY_BAR="██████████"
WIN=0
CHAIN=0
CHAIN_MAX=0
STREAK=0
MAXSTREAK=0
MAXSCORE=0
PREVSCORE=0
SCORE=0
PARTIALSCORE=0
TOPSCORE="$(get_top_score)"
TOPWORDSCORE=0
TOPWORD=""
ENERGY=0
ENERGY_MAX=10
PLAYER="???"
while [[ $RUNNING ]]; do
LETTERS=() # Initialisation de la liste des letters.
WORD="$(word_random)" # (1)
HIDDEN="$(hide_word "$WORD")" # (3)
display
clear_hidden_word
clear_letters
display_word_letter_count
playsnd word
sleep 1.5
clear_hidden_word
display_letters
display_hidden_word
[[ $SPID ]] && kill "$SPID" 2>/dev/null
playsnd new
compute_target_score
FLAWLESS=1
PARTIALSCORE=0
ACTUALSCORE=0
while :; do
display
display_message
display_letters
IFS= read -rsn1 LETTER || continue
[[ $LETTER == " " ]] && pause && continue
[[ $LETTER =~ [àâäéèêëîïôöùûüÀÂÄÉÈÊËÎÏÔÖÙÛÜçÇ] ]] && continue # (5)
[[ $LETTER =~ [A-Za-z] ]] || continue # (5)
letter_used "$LETTER" && {
display_letter_used "$LETTER"
continue
} # (5)
is_extra "$LETTER" && {
[[ $CHAIN_MODE ]] || display_message "+1"
}
if guess "$LETTER"; then
((CHAIN++))
CHAIN_MAX="$(max $((CHAIN)) $((CHAIN_MAX)))"
if ((CHAIN<3)); then
playsnd correct1
elif ((ENERGY>0)); then
[[ $MODE == "EASY" ]] && playsnd heal
[[ $MODE == "EASY" ]] || playsnd correct2
else
playsnd correct2
fi
((CHAIN>=3)) && { CHAIN_MODE=1; chain; }
else
((ENERGY++))
unset FLAWLESS
CHAIN=0
unset CHAIN_MODE
playsnd incorrect
STREAK=0;
fi
LETTERS+=("${LETTER^^}")
display
display_hidden_word
display_letters
[[ $HIDDEN == "$WORD" ]] && { # (8)
CHAIN=0
unset CHAIN_MODE
((WIN++))
((PREVSCORE=SCORE))
display
display_message
clear_letters
((FLAWLESS)) && playsnd flawless
((FLAWLESS)) || playsnd win
display_hidden_word victoire
sleep 2
compute_score
heal
color
((TARGETSCORE>0)) && \
((SUCCESSRATIO=TARGETSCORE>0?100*ACTUALSCORE/TARGETSCORE:0))
if [[ $MODE != "EASY" ]]; then
display_centered_message "TOTAL: $PARTIALSCORE (${SUCCESSRATIO}%)"
else
display_centered_message "TOTAL: $PARTIALSCORE"
fi
sleep 1.5
((MAXSCORE+=TARGETSCORE))
display_centered_message
top_word
ACTUALSCORE=0
break
}
(( ENERGY == ENERGY_MAX )) && { # (7)
tput clear
display_hidden_word
clear_letters
unveil_hidden_word
playsnd lose
display_word_animated
((MAXSCORE+=TARGETSCORE))
display_end
unset RUNNING
break
}
done
done
screen_end
((SCORE>0)) && {
fetch_scores
compare_scores && {
playsnd end
get_player_name
compare_scores insert
write_scores
display_scoreboard
}
sleep 5
}
[[ $SPID ]] && kill "$SPID" 2> /dev/null
deinit_screen