-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9blanc
executable file
·184 lines (173 loc) · 3.07 KB
/
9blanc
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
#!/bin/bash
# Written by Quentin RIBAC (2016)
# This is free software.
# See LICENSE file for legal information.
if [ "$1" == '-h' ] || [ "$1" == '--help' ]
then
echo "9blanc"
echo "======"
echo
echo "Règles"
echo "------"
echo -e "Une case est blanche (\e[47;30m.\e[m) ou noire (\e[40;37m.\e[m)."
echo "À gauche est le plateau de jeu, à droite les contôles."
echo "Deux cases sont dites adjacentes si elles sont reliées par un trait."
echo "Appuyer sur une case l'inverse ainsi que toutes celles adjacentes."
echo "La victoire s'obtient en blachissant toutes les cases."
echo "La touche 'E' permet de quitter le jeu à tout moment."
echo
echo "Controles"
echo "---------"
echo 'V-D-L-J'
echo '| | | |'
echo 'T-S-R-N'
echo '| | | |'
echo 'Q-G-H-F'
echo
echo "Bon jeu !"
exit 0
fi
clear
old_stty=$(stty -g)
stty -icanon
#Plateau
tput cup 0 0
echo
echo ' 9-BLANC'
echo ' Coups : '
echo ' 0'
echo
echo ' [ ] '
#Coordonnées
parc='0 1 2 3 4 5 6 7 8 9 10 11'
x=(0 2 4 6 0 2 4 6 0 2 4 6)
y=(0 0 0 0 2 2 2 2 4 4 4 4)
coups=0
#Constantes d’affichage
ca_no(){
tput cup $1 $2
echo -en '\e[40;37m \e[m'
tput cup "$(( $1+1 ))" $2
echo -en '\e[40;37m.\e[m'
tput cup $1 "$(( $2+1 ))"
echo -en '\e[40;37m \e[m'
tput cup "$(( $1+1 ))" "$(( $2+1 ))"
echo -en '\e[40;37m \e[m'
}
ca_bl(){
tput cup $1 $2
echo -en '\e[47;30m \e[m'
tput cup "$(( $1+1 ))" $2
echo -en '\e[47;30m.\e[m'
tput cup $1 "$(( $2+1 ))"
echo -en '\e[47;30m \e[m'
tput cup "$(( $1+1 ))" "$(( $2+1 ))"
echo -en '\e[47;30m \e[m'
}
#Initialisation
cases=()
for i in $parc
do
if [ $[($RANDOM % 2) + 1] = 1 ]
then
cases[$i]=0
ca_bl ${y[$i]} ${x[$i]}
else
cases[$i]=1
ca_no ${y[$i]} ${x[$i]}
fi
done
#Boucle principale
continuer=true
while $continuer
do
#Action
tput cup 5 10
read -n 1 touche
case "$touche" in
'v')
aInverser='0 1 4'
;; 'd')
aInverser='0 1 2 5'
;; 'l')
aInverser='1 2 3 6'
;; 'j')
aInverser='2 3 7'
;; 't')
aInverser='0 4 5 8'
;; 's')
aInverser='1 4 5 6 9'
;; 'r')
aInverser='2 5 6 7 10'
;; 'n')
aInverser='3 6 7 11'
;; 'q')
aInverser='4 8 9'
;; 'g')
aInverser='5 8 9 10'
;; 'h')
aInverser='6 9 10 11'
;; 'f')
aInverser='7 10 11'
;; 'e')
aInverser=''
continuer=false
;; *)
aInverser=''
esac
#Compteur
if [ -n "$aInverser" ]
then
(( coups++ ))
fi
#Affichage et inversion
for i in $aInverser
do
cases[$i]=$[1 - ${cases[i]}]
if [ ${cases[$i]} -eq 0 ]
then
ca_bl ${y[$i]} ${x[$i]}
else
ca_no ${y[$i]} ${x[$i]}
fi
done
tput cup 3 9
echo -n "$coups"
#Vérification
if [ "${cases[*]}" = "0 0 0 0 0 0 0 0 0 0 0 0" ]
then
echo -en '\e[47;30m'
tput cup 6 0
echo ' '
sleep 0.2
tput cup 6 2
echo 'V '
sleep 0.2
tput cup 6 4
echo 'I '
sleep 0.2
tput cup 6 6
echo 'C '
sleep 0.2
tput cup 6 8
echo 'T '
sleep 0.2
tput cup 6 10
echo 'O '
sleep 0.2
tput cup 6 12
echo 'I '
sleep 0.2
tput cup 6 14
echo 'R '
sleep 0.2
tput cup 6 16
echo 'E '
echo -en '\e[m'
continuer=false
fi
done
#Fin
tput cup 7 0
stty "$old_stty"
exit 0