sts-term

Une version rudimentaire de Slay The Spire dans le terminal - retour accueil

git clone git://bebou.netlib.re/sts-term
Log | Files | Refs | README |

commit 57e3c6ec4c4972e654af6f7f78ff5eaa084cfc97
parent 9587d58a2ed1a8e9f265ef5c7d8dfde714da2595
Auterice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Wed, 19 Jun 2024 19:13:00 +0200

Ajout d'un game over

aussi sed suit les liens symboliques, modif de fight/player modifie
player à la racine

Diffstat:
Mutils | 49+++++++++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/utils b/utils @@ -11,9 +11,9 @@ grayed="\x1b[90m" norm="\x1b[0m" makeui() { - [ ! -e "player" ] && { printf "player doesn't exist\n"; exit 1; } + [ ! -e "player" ] && { printf "No current game\n"; exit 1; } - currentenergy=$(grep energy player | cut -f2) + currentenergy=$(grep energy fight/player | cut -f2) grep cost fight/hand/* | awk "\$2>$currentenergy{print}" | cut -d':' -f1 | xargs -r -n1 basename > $tmpdir/nonexeccards @@ -51,14 +51,43 @@ makeui() { sed -E 's/-[0-9]/ /g;s,fight/([^ ]*),\1 ,g' } +makefight() { + rm -rf fight + + mkdir -p fight/ennemies + mkdir -p fight/stack + mkdir -p fight/hand + mkdir -p fight/discard + + echo "1" > fight/turn + + cp deck/* fight/stack + + for en in $(find "$1" -type f);do + ln -rs -f "$en" fight/ennemies/$(basename "$en") + done + + ln -rs -f player fight/player +} + setstat() { target="$1" stat="$2" value="$3" - sed -i -E "/$stat/ s/ .*/ $value/" "$target" + if [ "$stat" = "health" -a "$target" = "fight/player" -a "$value" -le '0' ];then + gameover + else + sed -i --follow-symlinks -E "/$stat/ s/ .*/ $value/" "$target" + fi refreshUI } +gameover() { + echo "game over" | toilet -f ansi > UI + sleep 2 + ./reset +} + status() { target="$1" stat="$2" @@ -91,7 +120,7 @@ hasstatus() { } _updatecardexecutability() { - currentenergy=$(grep energy player | cut -f2) + currentenergy=$(grep energy fight/player | cut -f2) grep cost fight/hand/* | awk "\$2<=$currentenergy{print}" | cut -d':' -f1 | @@ -108,12 +137,12 @@ _updatecardexecutability() { cost() { cost="$1" - currentenergy=$(grep energy player | cut -f2) + currentenergy=$(grep energy fight/player | cut -f2) newenergy=$(( $currentenergy - $cost )) - setstat player energy "$newenergy" + setstat fight/player energy "$newenergy" } -shufflefight/discard() { +shufflediscard() { mv fight/discard/* fight/stack } @@ -142,7 +171,7 @@ draw() { done } -newfight/hand() { +newhand() { find fight/hand -type f | while read card;do fight/discard "$card" @@ -150,7 +179,7 @@ newfight/hand() { draw 5 } -fight/discard() { +discard() { card="$1" chmod -x "$card" mv "$card" fight/discard @@ -182,7 +211,7 @@ nextmove() { tr ',' ' ' | tr ';' '\n' > $tmpdir/nextmove <<-. cat > $tmpdir/executablenextmove . ./utils - $(< $tmpdir/nextmove sed -E '/attack/ s/$/ player/;/defend/ s,$, fight/ennemies/*,') + $(< $tmpdir/nextmove sed -E '/attack/ s/$/ fight\/player/;/defend/ s,$, fight/ennemies/*,') refreshUI . chmod +x $tmpdir/executablenextmove