y=11 # B="" # x = 3 # -
r=$(( $x + $y )) # r=$(( ${x} + ${y} )) #
map[3]=4 map[${r}]="_" map=( 1 2 3 4 5 6 ) #
echo "Hello, world!" #, ! echo -en "\E[3;3f Hello, world!" # (3;3), echo "${x}" # echo -en "\E[${x};${y}f Hello!" #, escape-
read B # , B read -n 1 B # read -t 1 -n 1 B #
if [[ "$B" = "Q" ]] # , then # fi # if [[ "$B" -eq 3 ]] # then # fi #
while ( [ "$B" != "Q" ] ) do # - , # done case "$B" in # switch "W" ) 1;; # "S" ) 2;; [QZ] ) 3;; # , esac # case
for (( value=1 ; value<LIMIT; value++ )) do # LIMIT - # done
#!/bin/bash # Sokoban # map=( WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWW _ _ _ WWWWWWWWWWWW WWWWW = _ _ WWWWWWWWWWWW WWWWW _ _ = WWWWWWWWWWWW WWW _ _ = _ = _ WWWWWWWWWWW WWW _ W _ WW _ WWWWWWWWWWW W _ _ _ W _ WW _ WWWWWW _ _ oo W W _ = _ _ = _ _ _ _ _ _ _ _ _ _ _ oo W WWWWW _ WWW _ W _ WWW _ _ oo W WWWWW _ _ _ _ _ WWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWW ) # x=9 y=11 # B, B="" # ( ) LIMIT=20 # echo -en "\E[2J" # while ( [ "$B" != "q" ] ) do # for (( mx=1 ; mx<LIMIT; mx++ )) do for (( my=1 ; my<LIMIT; my++ )) do r=$(($mx*20+$my)) # , echo -en "\E[${mx};${my}f${map[${r}]}" done done # echo -en "\E[22;2fWASD - move, Q - quit" echo -en "\E[23;2fW - wall, X - hero, = and @ - chest, o - place for chest" # - ( , ) echo -en "\E[${x};${y}fX\E[${x};${y}f" # B="" # read -s -t 1 -n 1 B # , nx=0 ny=0 # , case "$B" in [wW] ) nx=$(( - 1));; [sS] ) nx=$(( 1));; [aA] ) ny=$(( - 1));; [dD] ) ny=$(( 1));; # , - CAPS LOCK [qQ] ) B="q";; esac # , r=$(( ($x + $nx) * $LIMIT + $y + $ny )) # - r2=$(( ($x + $nx + $nx) * $LIMIT + $y + $ny +$ny )) # , if [[ "${map[${r}]}" = "_" ]] then # x=$(( $x + $nx )) y=$(( $y + $ny )) fi # if [[ "${map[${r}]}" = "o" ]] then x=$(( $x + $nx )) y=$(( $y + $ny )) fi #, ? if [[ "${map[${r}]}" = "=" ]] then # , if [[ "${map[${r2}]}" = "_" ]] then map[${r2}]="=" map[${r}]="_" x=$(( $x + $nx )) y=$(( $y + $ny )) fi # - if [[ "${map[${r2}]}" = "o" ]] then map[${r2}]="@" map[${r}]="_" x=$(( $x + $nx )) y=$(( $y + $ny )) fi fi # , if [[ "${map[${r}]}" = "@" ]] then # - , if [[ "${map[${r2}]}" = "_" ]] then map[${r2}]="=" map[${r}]="o" x=$(( $x + $nx )) y=$(( $y + $ny )) fi # - if [[ "${map[${r2}]}" = "o" ]] then map[${r2}]="@" map[${r}]="o" x=$(( $x + $nx )) y=$(( $y + $ny )) fi fi # done # Q - echo -en "\E[2J"
Source: https://habr.com/ru/post/120198/
All Articles