Une version rudimentaire de Slay The Spire dans le terminal - retour accueil
git clone git://bebou.netlib.re/sts-term
Log | Files | Refs |
commit d8c3c439a1003f7c8bd5df8c9c000e4457394917 parent 2515171d95b8a6f760eed254a947f8fc8d2905a3 Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 19 Jun 2024 15:58:04 +0200 Gestion de l'exec des cartes en fonction de l'nrj Aussi compat sh/zsh, créer un tmpdir par partie, affichage du nextmove Diffstat:
M | makegame | | | 7 | ++++++- |
M | utils | | | 47 | +++++++++++++++++++++++++++++++++++------------ |
2 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/makegame b/makegame @@ -1,5 +1,8 @@ #! /bin/sh +export tmpdir=$(mktemp -d) +. ./utils + addcard() { nbcard=$(find deck -name "$2-*" | wc -l) [ "$nbcard" = '0' ] && count=1 || count=$nbcard @@ -38,7 +41,9 @@ c=$(./pickrandom characters) tr ' ' '\n' | uniq -c | while read line;do - addcard $line + nb=$(echo "$line" | cut -d ' ' -f1) + cardtype=$(echo "$line" | cut -d ' ' -f2) + addcard "$nb" "$cardtype" done < $c grep relic | cut -f2- | diff --git a/utils b/utils @@ -1,10 +1,10 @@ #! /bin/sh -tmpdir=$(mktemp -d) - showstat() { - [ "$2" = "name" ] && { basename $1; return; } - grep "$2" "$1" | sed 's/\t/ : /' + target="$1" + stat="$2" + [ "$stat" = "name" ] && { basename $target; return; } + grep "$stat" "$target" | sed 's/\t/ : /' } makeui() { @@ -27,6 +27,8 @@ makeui() { $(showstat map/1/* name) $(showstat map/1/* health) $(showstat map/1/* block) + $(echo "\nNext move :\n") + $(cat $tmpdir/nextmove) . paste $tmpdir/player $tmpdir/en | @@ -71,6 +73,22 @@ hasstatus() { echo } +_updatecardexecutability() { + currentenergy=$(grep energy player | cut -f2) + grep cost hand/* | + awk "\$2<=$currentenergy{print}" | + cut -d':' -f1 | + while read card;do + chmod +x "$card" + done + grep cost hand/* | + awk "\$2>$currentenergy{print}" | + cut -d':' -f1 | + while read card;do + chmod -x "$card" + done +} + cost() { cost="$1" currentenergy=$(grep energy player | cut -f2) @@ -96,6 +114,7 @@ _draw() { head -n 1) chmod +x "$card" mv "$card" hand + _updatecardexecutability refreshUI } @@ -107,6 +126,10 @@ draw() { } newhand() { + find hand -type f | + while read card;do + discard "$card" + done draw 5 } @@ -134,21 +157,21 @@ refreshUI() { ##### nextmove() { - <<-. cat > $tmpdir/nextmove - . ./utils - $(cat map/1/* | + cat map/1/* | grep moves | cut -f2- | tr ' ' '\n' | shuf | head -n1 | - tr ',' ' ' | tr ';' '\n' | - sed '/attack/ s/$/ player/;/defend/ s,$, map/1/*,') + tr ',' ' ' | tr ';' '\n' > $tmpdir/nextmove + <<-. cat > $tmpdir/executablenextmove + . ./utils + $(< $tmpdir/nextmove sed -E '/attack/ s/$/ player/;/defend/ s,$, map/1/*,') refreshUI . - chmod +x $tmpdir/nextmove - cat $tmpdir/nextmove + chmod +x $tmpdir/executablenextmove + refreshUI } execnextmove() { - $tmpdir/nextmove + $tmpdir/executablenextmove }