天天看点

人机猜拳游戏(自己编写shell脚本)

#!/bin/bash

read -p "请输入你的选择(石头 剪刀 布):" b0

a0=$[RANDOM % 3 + 1]

#1为石头 2为剪刀 3为布

if [ $a0 -eq 1 ];then

if [ $b0 == 石头 ];then &>/dev/null

echo "平局"

elif [ $b0 == 剪刀 ];then &>/dev/null

echo "你输了= ="

elif [ $b0 == 布 ];then &>/dev/null

echo "恭喜你,你赢了!"

else

echo "请输入正确的选择"

fi

elif [ $a0 -eq 2 ];then

if [ $b0 == 石头 ];then &>/dev/null

echo "恭喜你,你赢了!"

elif [ $b0 == 剪刀 ];then &>/dev/null

echo "平局"

elif [ $b0 == 布 ];then &>/dev/null

echo "你输了= ="

else

echo "请输入正确的选择"

fi

else

if [ $b0 == 石头 ];then &>/dev/null

echo "你输了=_="

elif [ $b0 == 剪刀 ];then &>/dev/null

echo "恭喜你,你赢了!"

elif [ $b0 == 布 ]; then &>/dev/null

echo "平局"

else

echo "请输入正确的选择"

fi

fi

~

本文转自 英强云计算 51CTO博客,原文链接:http://blog.51cto.com/13404755/2050760,如需转载请自行联系原作者

继续阅读