-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecond.sh
executable file
·111 lines (96 loc) · 2.1 KB
/
second.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
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
#!/bin/bash
# No the position and stuff
xaxis=10
yaxis=10
mapwidth=30
mapheight=15
clear
while read -rsn1 ui; do
cols=$(tput cols)
lines=$(tput lines)
case "$ui" in
$'\x1b') # Handle ESC sequence.
read -rsn1 -t 0.01 tmp
if [[ "$tmp" == "[" ]]; then
read -rsn1 -t 0.01 tmp
case "$tmp" in
"A")
(( yaxis-- ))
;;
"B")
(( yaxis++ ))
;;
"C")
(( xaxis++ ))
;;
"D")
(( xaxis-- ))
;;
esac
fi
# Flush "stdin" with 0.1 sec timeout.
read -rsn5 -t 0.01
msg=""
if [[ $yaxis -lt 1 ]]; then
yaxis=1
msg=" < ouch! > "
fi
lines=$(( lines-1 ))
if [[ $yaxis -gt $lines ]]; then
yaxis=$lines
msg=" < ouch! > "
fi
ybound=$((mapheight+2))
if [[ $yaxis -gt $ybound ]]; then
yaxis=$ybound
msg=" < ouch! > "
fi
if [[ $xaxis -lt 1 ]]; then
xaxis=1
msg=" < ouch! > "
fi
cols=$(( cols-1 ))
if [[ $xaxis -gt $cols ]]; then
xaxis=$cols
msg=" < ouch! > "
fi
xbound=$((mapwidth+1))
if [[ $xaxis -gt $xbound ]]; then
xaxis=$xbound
msg=" < ouch! > "
fi
# printmap
mapstring=" "
# print top walls
for x in $(seq 0 $mapwidth)
do
mapstring="${mapstring}_"
done
# # print maps
for x in $(seq 0 $mapheight) ; do
mapstring="${mapstring}\n|"
for x in $(seq 0 $mapwidth); do mapstring="${mapstring} "; done;
mapstring="${mapstring}|"
done;
#
# print bottom walls
mapstring="${mapstring}\n|";
for x in $(seq 0 $mapwidth); do mapstring="${mapstring}_"; done;
mapstring="${mapstring}|";
# tput cup 0, 1
# /printmap
tput clear
printf "$mapstring"
echo -ne "\n\n\n"
echo -ne "\nposition(x,y) = $xaxis, $yaxis"
echo -ne "\nmessage = $msg"
tput cup $yaxis $xaxis
if [[ "$msg" != "" ]]; then
printf " $msg"
tput cup $yaxis $xaxis
fi
;;
# Other one byte (char) cases. Here only quit.
q) break;;
esac
done