运维开发网

shell脚本小游戏:剪刀石头布

运维开发网 https://www.qedev.com 2021-01-14 12:19 出处:51CTO 作者:qq5ff570f22fb28
#!/bin/bashww=(剪刀石头布)num=$[RANDOM%3]computer=${ww[$num]}echo"1.剪刀"echo"2.石头"echo"3.布"read-p"输入1-3:"mtcase$mtin1)if[$num-eq0]thenecho"平局"elif[$num-eq1]thenecho"你赢"elseecho"计算机赢"fi;;2)if[$num-eq0]thenec
#!/bin/bash
ww=(剪刀 石头 布)
num=$[RANDOM%3]
computer=${ww[$num]}

echo "1.剪刀"
echo "2.石头"
echo "3.布"

read -p"输入1-3:" mt

case $mt in
1)
        if [ $num -eq 0 ]
        then
            echo "平局"
        elif [ $num -eq 1 ]
        then
            echo "你赢"
        else
            echo "计算机赢"
        fi
        ;;

2)
        if [ $num -eq 0 ]
        then
            echo "你赢"
        elif [ $num -eq 1 ]
        then
            echo "平局"
        else
            echo "计算机赢"
        fi
        ;;

3)
        if [ $num -eq 0 ]
        then
            echo "计算机赢"
        elif [ $num -eq 1 ]
        then
            echo "你赢"
        else
            echo "平局"
        fi
        ;;

*)
        echo "请输入1-3: "
esac

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号