Created
July 27, 2019 11:52
-
-
Save Syy9/a3e06f0f64f997e0897a885ab7ab8d59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cpuWinCount=0 | |
playerWinCount=0 | |
# 0: あいこ, 1: プレイヤー勝利, 2: cpu勝利, | |
battle() | |
{ | |
if [ $1 -eq $2 ]; then | |
return 0 | |
fi | |
if [ $1 -eq 3 ]; then | |
$1=0 | |
fi | |
# プレイヤーの勝ち | |
if [ $(($1 + 1)) -eq $2 ]; then | |
return 1 | |
fi | |
# CPUの勝ち | |
return 2 | |
} | |
until [ $cpuWinCount -eq 2 ] || [ $playerWinCount -eq 2 ]; do | |
cpuCard=$((RANDOM % 3 + 1)) | |
result=0 | |
until [ $result -ne 0 ]; do | |
read -r -p " じゃんけん何出す? 1)ぐー 2)ちょき 3)ぱー " playerCard | |
battle $playerCard $cpuCard | |
result=$? | |
: "d: result=$result" | |
case $result in | |
0) echo " あいこだった";; | |
1) echo " プレイヤーの勝ち"; playerWinCount=$((playerWinCount + 1));; | |
2) echo " CPUの勝ち"; cpuWinCount=$((cpuWinCount + 1));; | |
esac | |
done | |
done | |
echo " 決着ついた" | |
if [ $cpuWinCount -eq 2 ]; then | |
echo " CPUの勝利" | |
else | |
echo " プレイヤーの勝利" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment