-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_5.sh
executable file
·71 lines (71 loc) · 1.34 KB
/
4_5.sh
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
#!/bin/bash
r=$( tput lines )
midx=$((r / 2))
c=$( tput cols )
midy=$((c / 2))
declare -A mat
for ((i=0;i<r;i++))
do
for ((j=0;j<c;j++))
do
mat[$i,$j]=0
done
done
x=$midx
y=$midy
d=6
col=$(($RANDOM % 7 ))
tput clear
tput cup $x $y
tput setab 7
tput clear
while [ 1 -eq 1 ]
do
read -n1 -t 1 -rs one
if [[ "$one" == $'\x1b' ]]
then
read -n1 -t 0.01 -rs sb
if [[ "$sb" == "[" ]]
then
read -n1 -t 0.01 -rs move
pdir=$d
case "$move" in
"A")d=8;;
"B")d=2;;
"C")d=6;;
"D")d=4;;
* );;
esac
if [ $pdir -ne $d ]
then
col=$(($RANDOM % 7 ))
fi
fi
fi
case $d in
8)((x--));;
2)((x++));;
6)((y++));;
4)((y--));;
*);;
esac
if [ $x -ge $r ] || [ $x -le 0 ] || [ $y -ge $c ] || [ $y -le 0 ] || [ ${mat[$x,$y]} -eq 1 ]
then
tput clear
x=$midx
y=$midy
d=6
for ((i=0;i<r;i++))
do
for ((j=0;j<c;j++))
do
mat[$i,$j]=0
done
done
fi
mat[$x,$y]=1
tput cup $x $y
tput setaf $col
echo -e "*\c"
tput cup $x $y
done