在我的代码滚你只写R并按下回车键,但它似乎没有阅读并转到其他事物重新启动while循环。 得到它推出的唯一方法是通过键入的东西大于r其他比它是一个(standard_in)1:解析错误。
#!/bin/bash
#this is a game that is two player and it is a race to get to
#100 before the other player
echo "Player 1 name?"
read p1
echo "Player 2 name?"
read p2
echo "Okay $p1 and $p2. $p1 will go first"
p1s=0
p2s=0
pt=1
while [ $pt -eq 1 ]; do
echo "roll or stay"
read choice
if [ $choice == r ]; then
die=$(($RANDOM%6+1))
elif [ $die -eq 1 ]; then
p1s=$(echo "$p1s-$count" |bc)
echo "You rolled a 1. Your score is $p1s"
echo "$p2 turn now."
sleep 1
count=0
pt=2
elif [ $die -gt 1 ]; then
p1s=$(echo "$p1s+$die" |bc)
count=$(echo "$count+$die" |bc)
echo "You rolled a $die. Your score is $p1s"
pt=1
else
if [ $choice == s ]; then
echo "Okay $p1 your score is $p1s"
echo "$p2 turn now"
sleep 1
count=0
pt=2
else
if [ $p1s -gt 99 ]; then
echo "$p1 won. $p2 lost"
echo "would you like to play again?"
read again
elif [ $again yes ]; then
echo "Okay one second."
sleep 1
clear
bash num.sh
elif [ $again == no ]; then
exit
else
pt=1
fi
fi
fi
done
不要担心自己不会是第二,而第二的球员。 我砍了这一点,因为它完全相同的代码只是供玩家两项。
样品输入/输出
Player 1 name?
guy1
Player 2 name?
guy2
Okay guy1 and guy2. guy1 will go first
roll or stay
r
roll or stay
rr
(standard_in) 1: parse error
You rolled a 5. Your score is 5
roll or stay
roll
(standard_in) 1: parse error
You rolled a 5. Your score is 10
roll or stay
s
(standard_in) 1: parse error
You rolled a 5. Your score is 15
roll or stay