标签:The 手势 case read and 游戏 echo rand 猜拳
#!/bin/bash
echo "1.剪刀 2.石头 3.布"
game=(剪刀 石头 布)
num=$[RANDOM%3]
sui=${game[$num]}
echo $sui
echo $num
while true
do
read -ep "是否开始游戏,请输入yes或no" aa
if [ aa == "yes"]
then
read -ep "请输入你的出拳手势" zj
case $zj in
1)
echo "你出的是剪刀"
if [ $num -eq 0 ]
then
echo "平局"
elif [ $num -eq 1 ]
then
echo "你输了"
else
echo "你赢了"
fi
;;
2)
echo "你出的是石头"
if [ $num -eq 0 ]
then
echo "你赢了"
elif [ $num -eq 1 ]
then
echo "你平了"
else
echo "你输了"
fi
;;
3)
echo "你出的是布"
if [ $num -eq 0 ]
then
echo "你输了"
elif [ $num -eq 1 ]
then
echo "你赢了"
else
echo "你平了"
fi
;;
*)
echo "请正确输入"
esac
else
echo "欢迎下次再来"
标签:The 手势 case read and 游戏 echo rand 猜拳
原文地址:https://www.cnblogs.com/hyydeali/p/12838644.html