【发布时间】:2014-06-24 14:52:59
【问题描述】:
我正在编写的中间骰子游戏存在问题。我之前发布了另一个问题,该问题已得到回答,但我仍然有问题。 (请记住,我对一般编程非常陌生)
这是我得到的输出,如果两个骰子掷出相同的数字,就会出现“更高或更低”选项:
你想在 [y|n] 之间玩吗?是的
模具 1:1 模具 2:1
筹码数:100 下注:50
甚至史蒂文!
甚至-史蒂文!更高还是更低 [h|l]? h
死亡 3:9
* 你赢了! *
您现在有 150 个筹码! 再玩一次y|n?是的
死亡 3:9
* 对不起 - 你输了! *
您现在有 100 个筹码! 再玩一次[y|n]?
它不应该再次显示骰子 3 并说“你输了”,它应该再次滚动骰子 1 和 2(基本上从头开始,但保留已经赢/输的筹码)另外,如果玩家选择 'n' 它做同样的事情。如果玩家选择“n”,我希望游戏结束。
这是我的代码(我已将两个骰子上的数字更改为“1”以测试更高/更低的游戏):
import random
# Number of chips
chipBalance = 100
play = input('Would you like to play in-between [y|n]? ')
while play == 'y':
# First dice roll
die1 = 1
# Second dice roll
die2 = 1
# Swaps the values of the dice if die one is larger than die two
if die1 > die2:
temp = die1
die1 = die2
die2 = temp
# Displays value of the first and second die
print('\nDie 1:', die1, ' Die 2:', die2)
# Displays the number of chips held by player
print('\nNumber of chips:', chipBalance)
# Prompts player to place their bet
bet = int(input('Place your bet: '))
#Third dice roll
die3 = random.randint(1,12)
# Checks if the dice are the same or different
if die1 == die2:
print('\nEven-steven!')
guess = input('\nEven-steven! Higher or lower [h|l]? ')
print('\nDie 3:', die3)
if guess == 'h':
if die3 > die1:
print('\n*** You win! ***')
chipBalance = chipBalance + bet
elif die3 < die1:
print('\n*** Sorry - You lose! ***')
chipBalance = chipBalance - bet
elif die3 == die1:
print('\n*** You hit the post - You lose! ***')
chipBalance = chipBalance - bet
if guess == 'l':
if die3 > die1:
print('\n*** Sorry - You lose! ***')
chipBalance = chipBalance - bet
elif die3 < die1:
print('\n*** You win! ***')
chipBalance = chipBalance + bet
elif die3 == die1:
print('\n*** You hit the post - You lose! ***')
chipBalance = chipBalance - bet
# Displays when chip balance has reached zero
if chipBalance <= 0:
print('\nYou\'re all out of chips!\n\n*** GAME OVER ***')
else:
print('\nYou now have', chipBalance, 'chips!')
play = input('Play again y|n? ')
elif die1 != die2:
print('\nNot the same, let\'s play!')
# Value of the third die
print('\nDie 3:', die3)
# Results of dice roll
if die3 > die1 and die3 < die2:
print('\n*** You win! ***')
chipBalance = chipBalance + bet
elif die3 < die1 or die3 > die2:
print('\n*** Sorry - You lose! ***')
chipBalance = chipBalance - bet
elif die3 == die1 or die3 == die2:
print('\n*** You hit the post - You lose! ***')
chipBalance = chipBalance - bet
# Displays when chip balance has reached zero
if chipBalance <= 0:
print('\nYou\'re all out of chips!\n\n*** GAME OVER ***')
else:
print('\nYou now have', chipBalance, 'chips!')
# Update loop control
play = input('Play again [y|n]? ')
print('\nThanks for playing!')
任何关于我需要改变什么/改变什么的帮助将不胜感激!提前致谢。
【问题讨论】: