Roguelike amb scripts
Ir a la navegación
Ir a la búsqueda
Pantalla amb mags
- # # # # # # # # # # # # # # # # # # # # # # # # #
- . . . . . . . . . . . @;100;25 . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . a;10;4 . # # # # . . . . . . . . . . . . . . #
- . . . . a;10;4 . # . $;1 # . . . . . . . . . . . . . . #
- . . . . a;10;4 . . . m;1 # . . . . . . . . . . . . . . #
- . . . . a;10;4 . # # # # . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . ᗡ;5 . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . . . . . . . . . . . . . . . . . . . . . . . #
- . . s;1;100 s;1;100 . . . . . . . . . . . . . . . . . . . m;2 #
- # # +;1 # # # # # # # # # # # # # # # # # # # # # #
m1-pantalla[6*mida+9]='s;1000;1000'
m2-pantalla[6*mida+9]='.'
Solució amb funcions fins a interacció amb soldats:
#!/bin/bash
## Declaració de variables
tecla=1
y=$(cat pantalla$1 | grep @ -n | cut -f1 -d":")
x=$(cat pantalla$1 | grep @ | tr " " "\n" | grep -n @ | cut -f1 -d":")
jugador=$(cat pantalla$1 | grep @ | cut -f$x -d" ")
x=$((x-1))
y=$((y-1))
pantalla=($(cat pantalla$1 | tr "\n" " "))
mida=$(cat pantalla$1 | head -1 | wc -w)
inventari=""
clear
## Declaració de funcions
function moviment {
dx=$1
dy=$2
destix=$((x+dx))
destiy=$((y+dy))
desti=${pantalla[$((destiy*mida+destix))]}
if [[ "$desti" == '.' ]]
then
pantalla[$((destiy*mida+destix))]=$jugador
pantalla[$((y*mida+x))]='.'
x=$destix
y=$destiy
fi
if [[ $desti == $\;[0-9] ]]
then
pantalla[$((destiy*mida+destix))]=$jugador
pantalla[$((y*mida+x))]='.'
x=$destix
y=$destiy
inventari="$inventari $desti"
fi
}
function interaccio {
dx=$1
dy=$2
elementx=$((x+dx))
elementy=$((y+dy))
enemic=${pantalla[$((elementy*mida+elementx))]}
if [[ "$enemic" == s* ]] # si és un soldat
then
soldat=$enemic
arma_soldat=$(echo $soldat | cut -d";" -f3)
vida_soldat=$(echo $soldat | cut -d";" -f2)
arma_jugador=$(echo $jugador | cut -d";" -f3)
vida_jugador=$(echo $jugador | cut -d";" -f2)
vida_jugador=$(($vida_jugador-$arma_soldat))
vida_soldat=$(($vida_soldat-$arma_jugador))
soldat="s;$vida_soldat;$arma_soldat"
jugador="@;$vida_jugador;$arma_jugador"
if [ $vida_soldat -le 0 ]
then
soldat='.'
fi
if [ $vida_jugador -le 0 ]
then
echo "Has mort!!"
exit
fi
pantalla[$((elementy*mida+elementx))]=$soldat
fi
}
## Joc principal
while [[ $tecla != 0 ]]
do
echo -en "\e[s\e[0;0H\n$(echo ${pantalla[*]} | sed "s/\(\([^ ]\+ \)\{$mida\}\)/\1\n/g" | sed 's/\(.\)\(;[0-9]\+\)\+/\1/g' | tr -d " " | sed -e 's/#/\\e[32m#\\e[0m/g' -e 's/@/\\e[31m@\\e[0m/g')\n\nJugador:$jugador Inventari:$inventari\e[u"
read -s -n 1 tecla
case $tecla in
a)
moviment -1 0
;;
d)
moviment 1 0
;;
w)
moviment 0 -1
;;
s)
moviment 0 1
;;
*)
echo "La tecla $tecla no val per a res"
clear
;;
esac
interaccio 0 1
interaccio 0 -1
interaccio 1 0
interaccio -1 0
done