温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

bash 小脚本色子游戏

发布时间:2020-08-08 21:50:03 来源:ITPUB博客 阅读:176 作者:ahfhuang 栏目:建站服务器

#!/bin/bash
echo "<<<<< GAME STARTS! >>>>>"
choice='Big'
balance=1000
testtimes=3
while [ $choice != 'exit' ]
do
echo -e "Please choice Big or Small:"
read choice

if [ $choice == 'exit' ]
  then
  exit 0
fi

echo -e "How much you wanna bet :"
read amout

while [ $balance -lt $amout ]
do
    echo "Enter amout is bigger than balance , try again !"
    read amout
    testtimes=$[ $testtimes -1 ]
    if [ $testtimes -eq 1 ]
      then
       exit -1
    fi
done

function roll_dice()
{
echo "<<<<< ROLL THE DICE! >>>>>"
number=3
points=0
while (( number > 0 ))
do
point=$(($RANDOM%6+1))
echo $point
number=`expr $number-1`
let "points+=$point"
done
}
roll_dice

function caparoll_result()
{
if [ $points -le 18 ] && [ $points -ge 11 ]
  then
   result='Big'
elif [ $points -le 10 ] && [ $points -ge 3 ]
   then
   result='Small'
else
   echo 'Error'
   exit -1
fi
}
caparoll_result $points

if [ $choice == 'Big' ] || [ $choice == 'Small' ]
  then
   if [ $choice == $result ]
      then
       echo "The points are $points You win !"
       let "balance+=amout"
       echo "The gained $amout , You have $balance now !"
  else
      echo "The points are $points You lose !"
      let "balance-=amout"
      echo "The lost $amout , You have $balance now !"
  fi
else
    echo "Invalid Words"
fi

if [ $balance -eq 0 ]
  then
  echo "Game Over !"
  exit 0
fi
 
done

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI