shell实例第16讲:猜拳游戏
生活随笔
收集整理的這篇文章主要介紹了
shell实例第16讲:猜拳游戏
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#!/bin/bash
#Author:weibo
#TIME:2017.01.03game="石頭剪刀布游戲中機器人是:"while true
doecho "請根據(jù)下列提示選擇您的出拳手勢"echo "1.石頭"echo "2.剪刀"echo "3.布"num=$[RANDOM%3+1]computer="$game$num"read -p ">>>>>>>>>請選擇1-3:" persioncase $persion in1)if [ $num -eq 1 ];thenecho "平局"echo $computerelif [ $num -eq 2 ];thenecho "你贏"echo $computerelseecho "計算機贏"echo $computerfi;;2)if [ $num -eq 1 ];thenecho "計算機贏"echo $computerelif [ $num -eq 2 ];thenecho "平局"echo $computerelseecho "你贏"echo $computerfi;;3)if [ $num -eq 1 ];thenecho "你贏"echo $computerelif [ $num -eq 2 ];thenecho "計算機贏"echo $computerelseecho "平局"echo $computerfi;;*)echo "必須輸入1-3的數(shù)字"esac
done
運行結果:
總結
以上是生活随笔為你收集整理的shell实例第16讲:猜拳游戏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell实例第15讲:俄罗斯方块游戏
- 下一篇: shell实例第17讲:连续输入4个10