猜拳遊戲(shell指令碼)
阿新 • • 發佈:2018-12-21
read -p "是否開始遊戲(y/n)" a; while [ $a == y ] ;do read -p " * * * * * * * * 石頭(0) * * 剪刀(1) * * 布(2) * * 退出(3) * * * * * * * * " b; c=`echo $[$RANDOM%3]`; if [ $b -ge 0 ] ;then if [ $b -le 3 ] ;then if [ $b == $c ] ;then echo "玩家:$b"; echo "電腦:$c"; echo "平局!"; elif [ $b == 3 ] ;then echo "退出遊戲!"; else if [ $b == 1 -a $c == 2 ] || [ $b == 0 -a $c == 1 ] || [ $b == 2 -a $c == 0 ] ;then echo "玩家:$b"; echo "電腦:$c"; echo "玩家:勝!"; else echo "玩家:$b"; echo "電腦:$c"; echo "電腦:勝!"; fi fi if [ $b == 3 ] ;then break; fi else echo "請輸入正確選項!" fi else echo "輸入正確選項!" fi done #剛剛學習,請多指教!