Странное использование BASH Я знаю, но я создаю игру в скрипте BASH 4.4. Проблема в том, что на карте отображаются нажатия клавиш как на карте, так и на левом краю. Не должно быть никакого вывода от команды чтения, потому что я использую опцию -s. Код для проекта можно найти здесь, https://github.com/neophyt1983/basch-crawl/ Соответствующие файлы: lungon.sh и map_lib.sh.
Мне было бы интересно узнать, если кто-нибудь еще увидит, что я сделалэто вызвало бы это. Спасибо за вашу помощь. До сих пор я просмотрел код и не смог найти ничего, что должно было вызвать это. Я попытался заменить echo на printf, но это не помогло.
Это lungon.sh
#!/bin/bash
. mutual_lib.sh
. map_lib.sh
#. chr_lib.sh
#game_pid=$(echo $!)
plyr_x=0 # Players current x location
plyr_y=0 # Players current y location
c_x=0 # Players previous x location
c_y=0 # Players previous y location
quitter=0
finish=0 # Temporary
x=2 # Temporary
y=4 # Temporary
tput civis
map_builder
map_screen_draw
while [ $x -le $size_x ] || [ $finish -ne 1 ]
do
while [ $y -le $size_y ] || [ $finish -lt 1 ]
do
if [ "${maps[$loc_lev,$x,$y,0]:0:1}" == "." ]; then
plyr_x=$x
plyr_y=$y
c_x=$x
c_y=$y
tput cup $y $x && echo "@"
finish=1
break 2
fi
y=$((y+1))
done
y=0
x=$((x+1))
done
while [ $quitter -ne 1 ]
do
tput cup $plyr_y $plyr_x && echo "@"
read -n1 -t 0.2 -s cmd
case "$cmd" in
w ) #Go Up
if [ "$plyr_y" -gt 2 ]; then
c_y="$plyr_y"
c_x="$plyr_x"
plyr_y=$((plyr_y-1))
tput cup "$plyr_y" "$plyr_x" && echo "@"
map_fill_path
fi
;;
a ) #Go Left
if [ "$plyr_x" -gt 2 ]; then
c_y="$plyr_y"
c_x="$plyr_x"
plyr_x=$((plyr_x-1))
tput cup "$plyr_y" "$plyr_x" && echo "@"
map_fill_path
fi
;;
s ) #Go Down
if [ "$plyr_y" -lt $((size_y-1)) ]; then
c_y="$plyr_y"
c_x="$plyr_x"
plyr_y=$((plyr_y+1))
tput cup "$plyr_y" "$plyr_x" && echo "@"
map_fill_path
fi
;;
d ) #Go Left
if [ "$plyr_x" -lt $((size_x-1)) ]; then
c_y="$plyr_y"
c_x="$plyr_x"
plyr_x=$((plyr_x+1))
tput cup "$plyr_y" "$plyr_x" && echo "@"
map_fill_path
fi
;;
q ) #Quit
tput cup 1 1 && echo "Are you sure? y/n"
read -n1 -s sure
if [ "$sure" == 'y' ]; then
quitter=1
else
x=1
while [ "$x" -le 18 ];
do
true
tput cup 1 $x && echo "e"
x=$((x+1))
done
tput cup "$plyr_y" "$plyr_x"
tput bold
quitter=0
fi
;;
i ) #Inventory
;;
c ) #Consume 1,2,3,4,... Quick Bar
;;
'<' ) #Up Stairs
;;
'>' ) #Down Stairs
;;
o ) #Open Door
;;
c ) #Close Door
;;
e ) #Enter
;;
1 ) #Action 1
;;
2 ) #Action 2
;;
3 ) #Action 3
;;
5 ) #Action 4
;;
5 ) #Action 5
;;
6 ) #Action 6
;;
7 ) #Action 7
;;
8 ) #Action 8
;;
9 ) #Action 9
;;
0 ) #Action 0
;;
h ) #Help
;;
~ ) #Save
;;
*)
;;
esac
done
#read -n1
tput reset
exit 0
Это map_lib.sh #! / Bin / bash
#trap "set +x; sleep 5; set -x" DEBUG
#Libraries
. mutual_lib.sh
declare -A maps
#declare -A maps_oper
declare -A map_error
declare -A NPC
map_err_count=0
tput bold
#NPC[0,0,0,0]=3 # This variable will hold a list of NPC's in the current stage
loc_lev=1
loc_x=1
loc_y=1
tput_x=$(tput cols)
tput_y=$(tput lines)
if [ $tput_x -gt 20 ] && [ $tput_y -gt 20 ]; then
size_x=$((tput_x-2))
size_y=$((tput_y-4))
else
exit 1
fi
timer=1
top=0
btm=0
final=0
generated=0
map_fill_path()
{
vis_x=$((plyr_x-1))
vis_y=$((plyr_y-1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
vis_x=$((plyr_x+1))
vis_y=$((plyr_y+1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
vis_x=$((plyr_x+1))
vis_y=$((plyr_y-1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
vis_x=$((plyr_x-1))
vis_y=$((plyr_y+1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
vis_x=$((plyr_x+1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
vis_y=$((plyr_y+1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
vis_x=$((plyr_x-1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
vis_y=$((plyr_y-1))
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,0]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,1]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,2]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vis_y,3]:0:1}"
tput cup $vis_y $vis_x && echo "${maps[$loc_lev,$vis_x,$vix_y,10]:0:1}"
}
map_cell_blok()
{
#Cells are 4 by 4 walls with a door and blocks are 4 cells
cb_x=$((cbt_x-8))
cb_y=$((cbt_y-8))
while [ $cb_x -le $cbt_x ];
do
maps[$loc_sel,$cb_x,$cbt_y,0]="$bar"
cb_x=$((cb_x+1))
maps[$loc_sel,$cbt_x,$cb_y,0]="$bar"
cb_y=$((cb_y+1))
done
}
map_column()
{
#for making support columns
true
}
map_dungeon()
{
bar="W"
#Dungeon Builder - this function will work out the usable space of the building area and fill it
#with relevant structures and content.
if [ "${maps[$loc_sel,$loc_x,$loc_y,0]}" != "e" ]; then
odev=$set_x
odd_even
if [ $set_x -ne $odev ] && [ $set_x -gt $set_y ]; then
true
elif [ $set_x -ne $odev ] && [ $set_x -lt $set_y ]; then
true
else
true
fi
true
fi
}
map_forest()
{
bar="T"
#Turns out that the original random wall placement works pretty well for a forest map
temp_x=$((size_x-1))
temp_y=$((size_y-1))
loc_x=1
wall=0
if [ "${maps[$loc_sel,$loc_x,$loc_y,10]}" != "e" ];then
while [ $loc_x -le $temp_x ];
do
while [ $loc_y -le $temp_y ];
do
top=100
btm=3
rando
case $final in
1|2|3|4|5|6|7|8|9|10|11|12|13|15|15|16|17 )
maps[$loc_lev,$loc_x,$loc_y,1]="${bar}000"
wall=$((wall+1))
;;
21|22|23 ) #fallen trees
if [ "$maps{[$loc_lev,$loc_x,$loc_y,0]:0:4}" != "${bar:0:1}" ]; then
maps[$loc_lev,$loc_x,$loc_y,1]="t"
fi
;;
30 )
maps[$loc_lev,$loc_x,$loc_y,2]="${maps[$Loc_lev,$Loc_x,$loc_y,0]}n100"
;;
* )
maps[$loc_lev,$loc_x,$loc_y,0]='.000'
;;
esac
loc_y=$((loc_y+1))
done
loc_y=2
loc_x=$((loc_x+1))
done
fi
}
map_screen_draw()
{
tput reset
loc_x=1
loc_y=1
if [ $size_x -ge $(tput cols) ]; then
max_x=$(tput cols)
max_x=$((max_x-2))
else
max_x=$size_x
fi
if [ $size_y -ge $(tput lines) ]; then
max_y=$(tput lines)
max_y=$((max_y-2))
#This seems to be an issue with BASH 4.4 so to avoid drawing the map on 1 more line than is available
#I have to make sure that y never equals 43
if [ $max_y -eq 43 ]; then
max_y=42
fi
else
if [ $size_y -eq 43 ]; then
max_y=42
else
max_y=$size_y
fi
fi
while [ $loc_x -le $max_x ];
do
while [ $loc_y -le $max_y ];
do
dep="${#maps[$loc_lev,$loc_x,$loc_y,0]}"
n=0
while [ $n -le $dep ]
do
#tput cup $loc_y $loc_x && echo "${maps[$loc_lev,$loc_x,$loc_y,0]:${n}:1}"
#tput cup $loc_y $loc_x && echo "${maps[$loc_lev,$loc_x,$loc_y,1]:${n}:1}"
#tput cup $loc_y $loc_x && echo "${maps[$loc_lev,$loc_x,$loc_y,2]:${n}:1}"
#tput cup $loc_y $loc_x && echo "${maps[$loc_lev,$loc_x,$loc_y,3]:${n}:1}"
tput cup $loc_y $loc_x && echo "${maps[$loc_lev,$loc_x,$loc_y,10]:${n}:1}" "$(tput bold)"
n=$((n+4))
done
loc_y=$((loc_y+1))
done
loc_y=1
loc_x=$((loc_x+1))
done
}
map_builder()
{
generated=$((generated+1))
depth=$((depth+1))
# Make the initial outline of the level based on the set size from size_x and size_y variables
loc_x=1
loc_y=1
while [ $loc_x -le $size_x ];
do
maps[$loc_lev,$loc_x,$loc_y,10]='e'
loc_x=$((loc_x+1))
done
loc_x=1
while [ $loc_y -le $size_y ];
do
maps[$loc_lev,$loc_x,$loc_y,10]='e'
loc_y=$((loc_y+1))
done
loc_y=1
while [ $loc_x -le $size_x ];
do
maps[$loc_lev,$loc_x,$size_y,9]='e'
loc_x=$((loc_x+1))
done
while [ $loc_y -le $size_y ];
do
maps[$loc_lev,$size_x,$loc_y,10]='e'
loc_y=$((loc_y+1))
done
# Randomly select map type from a list and build
top=2
btm=1
rando
case $final in
1 )
#map_dungeon
map_forest
maps[$loc_lev,0,0,100]="dungeon"
;;
2 )
#This map uses randomly placed 'walls' or trees that go right up to the edge of the map container
maps[$loc_lev,0,0,100]="forest"
map_forest
;;
* )
#map_dungeon
map_forest
maps[$loc_lev,0,0,100]="forest"
;;
esac
}