一个 Shell的剪刀,石头,布的小游戏,喜欢的可以看看

vim a_猜石头,剪刀,布.sh

#!/bin/bash
game=(剪刀 石头 布)
num= [ R A N D O M c o m p u t e r = [ RANDOM%3 ] computer= [RANDOMcomputer={game[$sum]}

echo “-------必须输入系统提示的数字------”
echo “请根据以下提示选择你要出的手势”
echo “1. 剪刀”
echo “2. 石头”
echo “3. 布”

read -p “请选择 1 - 3 :” person
case KaTeX parse error: Expected 'EOF', got '#' at position 14: person in 1) #̲!/bin/bash game…[ RANDOM%3 ]
computer=KaTeX parse error: Expected '}', got 'EOF' at end of input: {game[sum]}

echo “-------必须输入系统提示的数字------”
echo “请根据以下提示选择你要出的手势”
echo “1. 剪刀”
echo “2. 石头”
echo “3. 布”

read -p “请选择 1 - 3 :” person
case $person 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

然后运行就OK了

猜你喜欢

转载自blog.csdn.net/weixin_52310457/article/details/109642670