-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-maze.sh
executable file
·158 lines (158 loc) · 4.22 KB
/
text-maze.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
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
#!/bin/bash
WHEREAMI="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd && echo)"
cd $WHEREAMI
echo "---------------------------------------------------------"
echo "|Thomas's Text-maze system |"
echo "|v 1.1 |"
echo "---------------------------------------------------------"
echo ""
echo "these mazes were found:"
$WHEREAMI/MAZE/mazesearch.sh
echo ""
WHEREAMI="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd && echo)"
cd $WHEREAMI
echo "enter name of valid .MAZE file"
echo "only type .MAZE files found above"
echo "MAZE files should be in MAZE directory in the script's directory"
until [ "$FILEREAD" = "1" ]; do
read filed
file=$WHEREAMI/MAZE/$filed
if test -e "$file"; then
FILEREAD=1
else
echo "maze not found"
fi
done
LOOKUP=$WHEREAMI/lookup.sh
TIMG=$WHEREAMI/T-IMG.sh
CANTMOVE="cannot move in that direction."
FINISH="congradulations, you won."
START="Welcome to text-maze."
name="$(sed '1q;d' $file)"
MODID="$WHEREAMI/MAZE/$(sed '2q;d' $file)"
MODTABLE=$(cat $MODID)
sizey=$(sed '3q;d' $file)
sizex=$(sed '4q;d' $file)
starty=$(sed '5q;d' $file)
startx=$(sed '6q;d' $file)
endy=$(sed '7q;d' $file)
endx=$(sed '8q;d' $file)
Playy=$starty
Playx=$startx
echo "$START
$name"
until [[ "$end" = "1" || "$entry" = "quit" ]]; do
echo -n "maze view
1" > COMPOSITE.TIMG
yc=1
for y in $MODTABLE
do
xc=1
listC=$(echo $y | grep -o .)
echo "" >> COMPOSITE.TIMG
for x in $listC
do
if [[ "${xc},${yc}" = "${Playx},${Playy}" || "${xc},${yc}" = "${endx},${endy}" ]]; then
if [ "${xc},${yc}" = "${Playx},${Playy}" ]; then
echo -n "C" >> COMPOSITE.TIMG
else
if [ "${xc},${yc}" = "${endx},${endy}" ]; then
echo -n "G" >> COMPOSITE.TIMG
fi
fi
else
echo -n "$x" >> COMPOSITE.TIMG
fi
CNT2=$(echo "$xc+1" | bc)
xc=$CNT2
done
CNT1=$(echo "$yc+1" | bc)
yc=$CNT1
done
echo
echo "
!" >> COMPOSITE.TIMG
$TIMG "$WHEREAMI/COMPOSITE.TIMG"
entry=nullvalue
until [[ "$entry" = "up" || "$entry" = "down" || "$entry" = "left" || "$entry" = "right" || "$entry" = "quit" ]]; do
echo "valid options: up, down, left, right, quit"
read entry
done
tput clear
if [ "$entry" = "up" ]; then
if [ "$(echo "($Playy-1)<1" | bc)" = "1" ]; then
echo "$CANTMOVE"
else
BIND1=$(echo "$Playy-1" | bc)
echo "$Playx" > lookup.txt
echo "$BIND1" >> lookup.txt
echo "$MODID" >> lookup.txt
bidle=$($LOOKUP)
#echo $bidle
if [ "$($LOOKUP "$Playx\$BIND1\WHEREAMI/$MODID")" = "1" ]; then
echo "$CANTMOVE"
else
upcnt=$(echo "$Playy-1" | bc)
Playy=$upcnt
fi
fi
fi
if [ "$entry" = "down" ]; then
if [ "$(echo "($Playy+1)>$sizey" | bc)" = "1" ]; then
echo "$CANTMOVE"
else
BIND2=$(echo "$Playy+1" | bc)
echo "$Playx" > lookup.txt
echo "$BIND2" >> lookup.txt
echo "$MODID" >> lookup.txt
bidle=$($LOOKUP)
#echo $bidle
if [ "$(${LOOKUP} "$Playx\$BIND2\$MODID")" = "1" ]; then
echo "$CANTMOVE"
else
downcnt=$(echo "$Playy+1" | bc)
Playy=$downcnt
fi
fi
fi
if [ "$entry" = "left" ]; then
if [ "$(echo "($Playx-1)<1" | bc)" = "1" ]; then
echo "$CANTMOVE"
else
BIND3=$(echo "$Playx-1" | bc)
echo "$BIND3" > lookup.txt
echo "$Playy" >> lookup.txt
echo "$MODID" >> lookup.txt
#$LOOKUP
if [ "$(${LOOKUP} $Playy\$BIND3\$WHEREAMI/$MODID)" = "1" ]; then
echo "$CANTMOVE"
else
leftcnt=$(echo "$Playx-1" | bc)
Playx=$leftcnt
fi
fi
fi
if [ "$entry" = "right" ]; then
if [ "$(echo "($Playx+1)>$sizex" | bc)" = "1" ]; then
echo "$CANTMOVE"
else
BIND4=$(echo "$Playx+1" | bc)
echo "$BIND4" > lookup.txt
echo "$Playy" >> lookup.txt
echo "$MODID" >> lookup.txt
#$LOOKUP
if [ "$(${LOOKUP} $Playy\$BIND3\$WHEREAMI/$MODID)" = "1" ]; then
echo "$CANTMOVE"
else
rightcnt=$(echo "$Playx+1" | bc)
Playx=$rightcnt
fi
fi
fi
if [ "${Playx},${Playy}" = "${endx},${endy}" ]; then
echo "YOU WIN!!!"
end=1
fi
done
echo "press enter to exit"
read nullvaliue