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 322830c1f375307dc705366d0e092ebc9422923f
parent 942be54ea686256d045ddcd6a73f3ad92fdd8fbd
Auterice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Wed, 19 Jun 2024 19:26:20 +0200

Fonctions "internes" préfixées avec _

Pour le moment seules les cartes et endturn sont utilisées par la
personne qui joue

Diffstat:
Mutils | 107++++++++++++++++++++++++++++++++++++++-----------------------------------------
1 file changed, 52 insertions(+), 55 deletions(-)

diff --git a/utils b/utils @@ -1,6 +1,6 @@ #! /bin/sh -showstat() { +_showstat() { target="$1" stat="$2" [ "$stat" = "name" ] && { basename $target; return; } @@ -10,7 +10,7 @@ showstat() { grayed="\x1b[90m" norm="\x1b[0m" -makeui() { +_makeui() { [ ! -e "player" ] && printf "No current game\n" currentenergy=$(grep energy fight/player | cut -f2) @@ -28,17 +28,17 @@ makeui() { <<-. cat > $tmpdir/player Player - $(showstat player gold) - $(showstat player health) - $(showstat player block) - $(showstat player energy) + $(_showstat player gold) + $(_showstat player health) + $(_showstat player block) + $(_showstat player energy) . <<-. cat > $tmpdir/en Ennemies - $(showstat fight/ennemies/* name) - $(showstat fight/ennemies/* health) - $(showstat fight/ennemies/* block) + $(_showstat fight/ennemies/* name) + $(_showstat fight/ennemies/* health) + $(_showstat fight/ennemies/* block) $(echo "\nNext move :\n") $(cat $tmpdir/nextmove) . @@ -51,7 +51,7 @@ makeui() { sed -E 's/-[0-9]/ /g;s,fight/([^ ]*),\1 ,g' } -makefight() { +_makefight() { rm -rf fight mkdir -p fight/ennemies @@ -68,34 +68,35 @@ makefight() { done ln -rs -f player fight/player + _newhand } -setstat() { +_setstat() { target="$1" stat="$2" value="$3" if [ "$stat" = "health" -a "$target" = "fight/player" -a "$value" -le '0' ];then - gameover + _gameover else sed -i --follow-symlinks -E "/$stat/ s/ .*/ $value/" "$target" fi - refreshUI + _refreshUI } -gameover() { +_gameover() { echo "game over" | toilet -f ansi > UI sleep 2 ./reset } -status() { +_status() { target="$1" stat="$2" value="$3" - sed -i -E "/$stat/ s/ / $value,/" "$target" + sed --follow-symlinks -i -E "/$stat/ s/ / $value,/" "$target" } -attack() { +_attack() { damage="$1" target="$2" targethealth=$(grep health "$target" | cut -f2) @@ -103,19 +104,19 @@ attack() { newblock=$(( $targetblock - $damage )) newhealth=$(( $targethealth + $newblock )) [ "$newblock" -lt '0' ] && newblock=0 - setstat "$target" health "$newhealth" - setstat "$target" block "$newblock" + _setstat "$target" health "$newhealth" + _setstat "$target" block "$newblock" } -defend() { +_defend() { block="$1" target="$2" targetblock=$(grep block "$target" | cut -f2) newblock=$(( $targetblock + $block )) - setstat "$target" block "$newblock" + _setstat "$target" block "$newblock" } -hasstatus() { +_hasstatus() { echo } @@ -135,74 +136,70 @@ _updatecardexecutability() { done } -cost() { +_cost() { cost="$1" currentenergy=$(grep energy fight/player | cut -f2) newenergy=$(( $currentenergy - $cost )) setstat fight/player energy "$newenergy" } -shufflediscard() { +_shufflediscard() { mv fight/discard/* fight/stack } endturn() { find fight/hand -type f | while read card;do - fight/discard $card + _discard $card done } _draw() { - [ "$(find fight/stack -type f | wc -l)" = "0" ] && shufflefight/discard - card=$(find fight/stack -type f | - shuf | - head -n 1) - chmod +x "$card" - mv "$card" fight/hand - _updatecardexecutability - refreshUI -} - -draw() { nbtodraw="$1" for nb in $(seq $nbtodraw);do - _draw + [ "$(find fight/stack -type f | wc -l)" = "0" ] && _shufflediscard + card=$(find fight/stack -type f | + shuf | + head -n 1) + chmod +x "$card" + mv "$card" fight/hand + _updatecardexecutability + _refreshUI done } -newhand() { +_newhand() { find fight/hand -type f | while read card;do - fight/discard "$card" + _discard "$card" done - draw 5 + _draw 5 } -discard() { +_discard() { card="$1" chmod -x "$card" mv "$card" fight/discard - refreshUI + _refreshUI } -playcard() { - card="$1" - target="$2" - eval $(cat "$card" | sed "s,$, $target," | paste -s -d ';') - fight/discard "$1" - refreshUI -} +#playcard() { +# card="$1" +# target="$2" +# eval $(cat "$card" | sed "s,$, $target," | paste -s -d ';') +# fight/discard "$1" +# _refreshUI +#} -refreshUI() { - makeui > UI +_refreshUI() { + _makeui > UI } ##### # Ennemies ##### -nextmove() { +_nextmove() { cat fight/ennemies/* | grep moves | cut -f2- | @@ -212,12 +209,12 @@ nextmove() { <<-. cat > $tmpdir/executablenextmove . ./utils $(< $tmpdir/nextmove sed -E '/attack/ s/$/ fight\/player/;/defend/ s,$, fight/ennemies/*,') - refreshUI + _refreshUI . chmod +x $tmpdir/executablenextmove - refreshUI + _refreshUI } -execnextmove() { +_execnextmove() { $tmpdir/executablenextmove }