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

脚本代码: 

#!/bin/bash
echo "接下来的是石头剪刀布的游戏"
echo "定义1:包子;2:剪刀;3:布"
echo "------------------------------"
NUM=`echo $[RANDOM%3+1]`
#1=包子
#2=剪刀
#3=布
read -p "请输入1-3:" key
case $key in
[1])
if [ $NUM -eq 1 ]
  then 
    echo "你们打成平局"
elif [ $NUM -eq 2 ]
  then
    echo "你赢啦,机器输了"
else
  echo "你输了,呜呜呜,机器赢了"
fi
;;
[2])
if [ $NUM -eq 1 ]
  then
    echo "你输了,呜呜呜,机器赢了"
elif [ $NUM -eq 2 ]
  then
    echo "你们打成平局"
else
  echo "你赢啦,机器输了"
fi
;;
[3])
if [ $NUM -eq 1 ]
  then
    echo "你赢啦,机器输了"
elif [ $NUM -eq 2 ]
  then
    echo "你输了,呜呜呜,机器赢了"
else
  echo "你们打成平局"
fi
;;
esac
echo "机器数字为:$NUM"

Shell脚本小游戏:石头剪刀布_第1张图片

你可能感兴趣的:(服务器,linux,数据库)