您的位置:首页 > 运维架构 > Linux

Linux:写一个与电脑玩石头剪刀布的脚本

2020-08-07 19:47 281 查看

人机石头剪刀布

#!/bin/bash
echo "Choice the numbers!"
read -p "Made your choice rock:1  paper:2  scissors:3 : " Choice
#echo $Choice

if [[ $Choice =~ [123] ]];
then
computer=$[ $RANDOM%3+1 ]
#    echo $computer
if [ $Choice -ne $computer ];
then
if [ $Choice -eq 1 ];
then
[ $computer -eq 3 ] && echo "Computer is scissors. YOU WIN!" && exit || echo "Computer is paper. YOU LOSE!" && exit
fi

if [ $Choice -eq 2 ];
then
[ $computer -eq 1 ] && echo "Computer is rock. YOU WIN!" && exit || echo "Computer is scissors. YOU LOSE!" && exit
fi

if [ $Choice -eq 3 ];
then
[ $computer -eq 2 ] && echo "Computer is paper. YOU WIN!" && exit || echo "Computer is rock. YOU LOSE!" && exit
fi
fi
echo "Tie!"
fi
echo "You gotta follow my tips like rock:1  paper:2  scissors:3."

玩起来!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: