-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdll_graph
246 lines (215 loc) · 4.88 KB
/
dll_graph
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
#! /bin/bash
########################
SetBold()
{
case $1 in
("true") tput bold ;;
(*) tput sgr0 ;;
esac
}
########################
ClearBelow()
{
tput cd
}
########################
SetBackgroundColor()
{
case $1 in
("black") color="0" ;;
("red") color="1" ;;
("green") color="2" ;;
("yellow") color="3" ;;
("blue") color="4" ;;
("magenta") color="5" ;;
("cyan") color="6" ;;
("white") color="7" ;;
(*) color="0" ;;
esac
tput setab $color
}
########################
SetColor()
{
case $1 in
("black") color="0" ;;
("red") color="1" ;;
("green") color="2" ;;
("yellow") color="3" ;;
("blue") color="4" ;;
("magenta") color="5" ;;
("cyan") color="6" ;;
("white") color="7" ;;
(*) color="7" ;;
esac
tput setaf $color
}
########################
ShowSHips()
{
clear
SetColor
gotoXY 9 2
echo "Player $1"
gotoXY 2 2
echo " |a|b|c|d|e|f|g|h|j|k| "
for ((row=1; $row<11; row++))
do
gotoXY $((2+row)) 2
index=$(Ternary "$row = 10" "$row|" " $row|")
echo -n "$index"
for letter in $letters
do
case $(GetMatrixValue $player $letter $row) in
#1 - empty
("1") echo -n "_|" ;;
#2 - ship
("2") SetBackgroundColor green; echo -n " "; SetBackgroundColor; echo -n "|";;
#3 - round ship
("3") SetColor green; echo -n "x"; SetColor; echo -n "|" ;;
esac
done
echo -n "$row"
done
gotoXY $((2+row)) 2
echo " |a|b|c|d|e|f|g|h|j|k| "
ClearBelow
}
########################
ShowMatrix()
{
player=$1
yOffset=$(Ternary "$player == P1" 0 27)
SetColor
gotoXY 1 $((2+yOffset))
echo " Player $player"
gotoXY 2 $((2+yOffset))
echo " |a|b|c|d|e|f|g|h|j|k| "
for ((row=1; $row<11; row++))
do
gotoXY $((2+row)) $((2+yOffset))
index=$(Ternary "$row = 10" "$row|" " $row|")
echo -n "$index"
for letter in $letters
do
case $(GetMatrixValue $player $letter $row) in
#1 - empty
("1") echo -n "_|" ;;
#2 - ship
("2") if [ "$1" = "P1" ]
then
if [ "$HotSeat" = "No" ]
then
SetBackgroundColor green; echo -n " "; SetBackgroundColor; echo -n "|"
else
echo -n "_|"
fi
else
echo -n "_|"
fi;;
#3 - round ship
("3") echo -n "_|" ;;
("4") SetColor cyan; echo -n "x"; SetColor; echo -n "|" ;;
#4 - shotdone
#5 - shiphitted
("5") SetBackgroundColor green; SetColor red; echo -n "x"; SetBackgroundColor; SetColor; echo -n "|" ;;
#6 - shipdown
("6") SetBackgroundColor red; echo -n " "; SetBackgroundColor; echo -n "|" ;;
esac
done
echo -n "$row"
done
gotoXY $((2+row)) $((2+yOffset))
echo " |a|b|c|d|e|f|g|h|j|k| "
echo
tput ed
if [ "$Now_Shooting" = "2" ]
then echo "Player 1! It's your turn!"; echo
else
if [ "$HotSeat" = "Yes" ] ; then echo "Player 2! It's your turn!"; echo; fi
if [ "$BotMode" = "Yes" ] ; then echo "Player 2! It's your turn!"; echo; fi
fi
}
########################
About()
{
clear;
TypeWord "Sea_Battle" 3 1 red
TypeWord "$version" 8 1 blue
gotoXY 15 1
SetColor green
echo " Made by Sergii Dmytrenko"
echo " To make a shot, just type it. E.g. \"b7\"."
echo " Type \"rand\" to make random shot."
echo; SetColor
echo -n "Press [Return] to continue..."
read
}
########################
Menu()
{
answer=$1
while [ "$answer" != "exit" ]
do
case "$answer" in
("one") InitVars; HotSeat="No"; ReadAILevel; Game;;
("two") InitVars; Player2="Human"; Game;;
("bot") InitVars; Player1="AI"; HotSeat="No"; BotMode="Yes"; Game;;
("inf") About;;
("fin") InitVars; P1Shots=1; P2Shots=1; OnFinish;;
esac
clear
SetColor red; SetBackgroundColor; SetBold true
echo
echo
echo
echo " Sea Battle. BASH-script version $version_menu"
echo
SetBold false; SetColor yellow
echo " Please, make Your choice:"; echo
SetColor magenta; echo -n " 'one' "; SetColor cyan
echo "- single-player (against computer)."
SetColor magenta; echo -n " 'two' "; SetColor cyan
echo "- multi-player (two users on one computer)."
SetColor magenta; echo -n " 'bot' "; SetColor cyan
echo "- computer vs computer (just watch the battle)."
SetColor magenta; echo -n " 'inf' "; SetColor cyan
echo "- About program."
echo
SetColor green; echo -n " 'exit' "; SetColor cyan
echo "- Exit. [ Or press Ctrl+C ] "
SetColor
echo
echo -n " > "
read answer
echo
done
SetBackgroundColor
SetColor
clear
}
########################
ReadAILevel()
{
clear
echo
SetColor red; echo "Choose Bot level."
echo
SetColor magenta; echo -n "1"; SetColor cyan; echo " - Easy."
SetColor magenta; echo -n "2"; SetColor cyan; echo " - Normal."
SetColor magenta; echo -n "3"; SetColor cyan; echo " - Advanced."
SetColor magenta; echo -n "4"; SetColor cyan; echo " - Hard."
echo
OK=1
until [ "$OK" = "0" ]
do
SetColor green
echo -n "[Number]: "
SetColor
read level
case $level in
("1" | "2" | "3" | "4") OK=0;;
(*) OK=1;;
esac
done
}