bash从一个案例 /w另一个情况下加起来

发布于 2025-01-30 20:18:13 字数 2719 浏览 1 评论 0原文

我如何将诸如ATK,DEF等统计数据添加

。 echo“您的char统计数据是($ class($ atk) +($ warweps($ atk)”

#!/data/data/com.termux/files/usr/bin/zsh

echo "Welcome to Wurtex world. Select your starting class:
1 - Warrior
2 - Wizard
3 - Ranger"

read class

case $class in
        1)
              type="Warrior"
              hp=150
              atk=30
              ;;
        2)
              type="Wizard"
              hp=80
              atk=70
              ;;
        3)
              type="Ranger"
              hp=90
              atk=60
              ;;
esac
       
echo "You chosen the $type class. Your starting HP and ATK is ($hp , $atk)"

sleep 2

if [[ $type == "Warrior" ]]; then
  echo "Select your starting weapon:
                                    1 - Frulx Longsword
                                    2 - Ushtar Sword & Circle Shield"
                                    read warWeps
fi
if [[ $type == "Wizard" ]]; then
  echo "Select your starting weapon:
                                    1 - YuuRStaff
                                    2 - Olyen Wand & Circle Shield"
                                    read wizWeps
fi
if [[ $type == "Ranger" ]]; then
  echo "Select your starting weapon:
                                    1 - Jenzy Bow
                                    2 - Ehtar Crossbow & Basic Defender"
                                    read rangWeps
fi

case $warWeps in
        1)
              type="Longsword"
              name="Frulx Longsword"
              atk=20
              ;;
        2)
              type="Sword"
              name="Ushtar Sword & Circle Shield"
              atk=10
              def=10
              ;;
esac

if [[ $type == "Longsword" ]]; then
  echo "Your STATS: $atk"
fi
if [[ $type == "Sword" ]]; then
  echo "Your STATS: $atk, $def"
fi

case $wizWeps in
        1)
              type="Staff"
              name="YuuRStaff"
              atk=15
              ;;
        2)
              type="Wand"
              name="Olyen Wand & Circle Shield"
              atk=12
              def=10
              ;;
esac

if [[ $type == "Staff" ]]; then
  echo "Your STATS: $atk"
fi
if [[ $type == "Wand" ]]; then
  echo "Your STATS: $atk , $def"
fi

case $rangWeps in
        1)
              type="Bow"
              name="Jenzy Bow"
              atk=18
              stm=30
              ;;
        2)
              type="Crossbow"
              name="Ehtar Crossbow & Basic Defender"
              atk=16
              stm=15
              def=7
              ;;
esac

if [[ $type == "Bow" ]]; then
  echo "Your STATS: $atk , $stm"
fi
if [[ $type == "Crossbow" ]]; then
  echo "Your STATS: $atk, $stm , $def"
fi

How I can add up stats like atk, def... From class case /w warWeps case, wizWeps case and rangWeps...

ex. echo "Your char stats is ($class($atk) + ($warWeps($atk)"

#!/data/data/com.termux/files/usr/bin/zsh

echo "Welcome to Wurtex world. Select your starting class:
1 - Warrior
2 - Wizard
3 - Ranger"

read class

case $class in
        1)
              type="Warrior"
              hp=150
              atk=30
              ;;
        2)
              type="Wizard"
              hp=80
              atk=70
              ;;
        3)
              type="Ranger"
              hp=90
              atk=60
              ;;
esac
       
echo "You chosen the $type class. Your starting HP and ATK is ($hp , $atk)"

sleep 2

if [[ $type == "Warrior" ]]; then
  echo "Select your starting weapon:
                                    1 - Frulx Longsword
                                    2 - Ushtar Sword & Circle Shield"
                                    read warWeps
fi
if [[ $type == "Wizard" ]]; then
  echo "Select your starting weapon:
                                    1 - YuuRStaff
                                    2 - Olyen Wand & Circle Shield"
                                    read wizWeps
fi
if [[ $type == "Ranger" ]]; then
  echo "Select your starting weapon:
                                    1 - Jenzy Bow
                                    2 - Ehtar Crossbow & Basic Defender"
                                    read rangWeps
fi

case $warWeps in
        1)
              type="Longsword"
              name="Frulx Longsword"
              atk=20
              ;;
        2)
              type="Sword"
              name="Ushtar Sword & Circle Shield"
              atk=10
              def=10
              ;;
esac

if [[ $type == "Longsword" ]]; then
  echo "Your STATS: $atk"
fi
if [[ $type == "Sword" ]]; then
  echo "Your STATS: $atk, $def"
fi

case $wizWeps in
        1)
              type="Staff"
              name="YuuRStaff"
              atk=15
              ;;
        2)
              type="Wand"
              name="Olyen Wand & Circle Shield"
              atk=12
              def=10
              ;;
esac

if [[ $type == "Staff" ]]; then
  echo "Your STATS: $atk"
fi
if [[ $type == "Wand" ]]; then
  echo "Your STATS: $atk , $def"
fi

case $rangWeps in
        1)
              type="Bow"
              name="Jenzy Bow"
              atk=18
              stm=30
              ;;
        2)
              type="Crossbow"
              name="Ehtar Crossbow & Basic Defender"
              atk=16
              stm=15
              def=7
              ;;
esac

if [[ $type == "Bow" ]]; then
  echo "Your STATS: $atk , $stm"
fi
if [[ $type == "Crossbow" ]]; then
  echo "Your STATS: $atk, $stm , $def"
fi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气尐潴 2025-02-06 20:18:13
#!/bin/bash

choosedType(){
     echo
     echo "---------------------------------------------------------------------"
     echo "You chosen the $1 class. Your starting HP and ATK is ($2 , $3)"
     echo "---------------------------------------------------------------------"
     echo
     sleep 2
}

atk=0
def=0
stm=0
PS3="Select your starting class: "

echo "Welcome to Wurtex world."
echo "---------------------------------------------------------------------"

select class in Warrior Wizard Ranger quit
do
  case $class in
        Warrior)
              type="Warrior"
              hp=150
              atk=30
              choosedType $type $hp $atk
              PS3="Select your Warrior starting weapon: "
              select warWeps in "Frulx Longsword" "Ushtar Sword & Circle Shield"
              do
                case $warWeps in
                        "Frulx Longsword")
                                type="Longsword"
                                name="Frulx Longsword"
                                atk=$((atk+20))
                                ;;
                        "Ushtar Sword & Circle Shield")
                                type="Sword"
                                name="Ushtar Sword & Circle Shield"
                                atk=$((atk+10))
                                def=$((def+10))
                                ;;
                esac
                break
              done
              ;;
        Wizard)
              type="Wizard"
              hp=80
              atk=70
              choosedType $type $hp $atk
              PS3="Select your Wizard starting weapon: "
              select wizWeps in "YuuRStaff" "Olyen Wand & Circle Shield"
              do
                case $wizWeps in
                        "YuuRStaff")
                                type="Staff"
                                name="YuuRStaff"
                                atk=$((atk+15))
                                ;;
                        "Olyen Wand & Circle Shield")
                                type="Wand"
                                name="Olyen Wand & Circle Shield"
                                atk=$((atk+12))
                                def=$((def+10))
                                ;;
                esac
                break
              done
              ;;
        Ranger)
              type="Ranger"
              hp=90
              atk=60
              choosedType $type $hp $atk
              PS3="Select your Ranger starting weapon: "
              select rangWeps in "Jenzy Bow" "Ehtar Crossbow & Basic Defender"
              do
                case $rangWeps in
                        "Jenzy Bow")
                              type="Bow"
                              name="Jenzy Bow"
                              atk=$((atk+18))
                              stm=30
                              ;;
                        "Ehtar Crossbow & Basic Defender")
                              type="Crossbow"
                              name="Ehtar Crossbow & Basic Defender"
                              atk=$((atk+16))
                              stm=15
                              def=$((def+7))
                              ;;
                esac
                break
              done
              ;;
        quit) exit
  esac

  break
done

echo
echo "---------------------------------------------------------------------"
case $type in
        Longsword) echo "Your STATS: $atk";;
        Sword)     echo "Your STATS: $atk, $def";;
        Staff)     echo "Your STATS: $atk";;
        Wand)      echo "Your STATS: $atk , $def";;
        Bow)       echo "Your STATS: $atk , $stm";;
        Crossbow)  echo "Your STATS: $atk, $stm , $def";;
esac
echo "---------------------------------------------------------------------"

$ ./script.sh

Welcome to Wurtex world.
---------------------------------------------------------------------
1) Warrior
2) Wizard
3) Ranger
4) quit
Select your starting class: 3

---------------------------------------------------------------------
You chosen the Ranger class. Your starting HP and ATK is (90 , 60)
---------------------------------------------------------------------

1) Jenzy Bow
2) Ehtar Crossbow & Basic Defender
Select your Ranger starting weapon: 2

---------------------------------------------------------------------
Your STATS: 76, 15 , 7
---------------------------------------------------------------------
#!/bin/bash

choosedType(){
     echo
     echo "---------------------------------------------------------------------"
     echo "You chosen the $1 class. Your starting HP and ATK is ($2 , $3)"
     echo "---------------------------------------------------------------------"
     echo
     sleep 2
}

atk=0
def=0
stm=0
PS3="Select your starting class: "

echo "Welcome to Wurtex world."
echo "---------------------------------------------------------------------"

select class in Warrior Wizard Ranger quit
do
  case $class in
        Warrior)
              type="Warrior"
              hp=150
              atk=30
              choosedType $type $hp $atk
              PS3="Select your Warrior starting weapon: "
              select warWeps in "Frulx Longsword" "Ushtar Sword & Circle Shield"
              do
                case $warWeps in
                        "Frulx Longsword")
                                type="Longsword"
                                name="Frulx Longsword"
                                atk=$((atk+20))
                                ;;
                        "Ushtar Sword & Circle Shield")
                                type="Sword"
                                name="Ushtar Sword & Circle Shield"
                                atk=$((atk+10))
                                def=$((def+10))
                                ;;
                esac
                break
              done
              ;;
        Wizard)
              type="Wizard"
              hp=80
              atk=70
              choosedType $type $hp $atk
              PS3="Select your Wizard starting weapon: "
              select wizWeps in "YuuRStaff" "Olyen Wand & Circle Shield"
              do
                case $wizWeps in
                        "YuuRStaff")
                                type="Staff"
                                name="YuuRStaff"
                                atk=$((atk+15))
                                ;;
                        "Olyen Wand & Circle Shield")
                                type="Wand"
                                name="Olyen Wand & Circle Shield"
                                atk=$((atk+12))
                                def=$((def+10))
                                ;;
                esac
                break
              done
              ;;
        Ranger)
              type="Ranger"
              hp=90
              atk=60
              choosedType $type $hp $atk
              PS3="Select your Ranger starting weapon: "
              select rangWeps in "Jenzy Bow" "Ehtar Crossbow & Basic Defender"
              do
                case $rangWeps in
                        "Jenzy Bow")
                              type="Bow"
                              name="Jenzy Bow"
                              atk=$((atk+18))
                              stm=30
                              ;;
                        "Ehtar Crossbow & Basic Defender")
                              type="Crossbow"
                              name="Ehtar Crossbow & Basic Defender"
                              atk=$((atk+16))
                              stm=15
                              def=$((def+7))
                              ;;
                esac
                break
              done
              ;;
        quit) exit
  esac

  break
done

echo
echo "---------------------------------------------------------------------"
case $type in
        Longsword) echo "Your STATS: $atk";;
        Sword)     echo "Your STATS: $atk, $def";;
        Staff)     echo "Your STATS: $atk";;
        Wand)      echo "Your STATS: $atk , $def";;
        Bow)       echo "Your STATS: $atk , $stm";;
        Crossbow)  echo "Your STATS: $atk, $stm , $def";;
esac
echo "---------------------------------------------------------------------"

$ ./script.sh

Welcome to Wurtex world.
---------------------------------------------------------------------
1) Warrior
2) Wizard
3) Ranger
4) quit
Select your starting class: 3

---------------------------------------------------------------------
You chosen the Ranger class. Your starting HP and ATK is (90 , 60)
---------------------------------------------------------------------

1) Jenzy Bow
2) Ehtar Crossbow & Basic Defender
Select your Ranger starting weapon: 2

---------------------------------------------------------------------
Your STATS: 76, 15 , 7
---------------------------------------------------------------------
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文