所以,我正在研究一个craps程序模拟器,通过浏览网页,并从论坛上的用户那里得到一些帮助。大部分时间我都能完成。至少,我认为我的游戏逻辑是对的。在
上次我用它的时候它还在运行,但我一定是在没有意识到的情况下改变了它,或者是因为while循环永远在运行。在这个程序中,骰子永远在不需要用户干预的情况下滚动。在
有人能看看代码有没有问题吗?我花了好几个小时都没找到。在
我再也不会赌博了!:/
from Dice import PairOfDice
print("Now Let's play with two dice!")
#
def MainDouble():
bdice = PairOfDice()
doubleDiceRoll = ''
global myPoint #declare global variable
input("Press Enter to Roll the Dice once")
while doubleDiceRoll == '': #Roll the dice (both die objects)
bdice.toss()
print ('The first die reads.. ' + str(bdice.getValue1()) + '\n')
print ('The second die reads.. ' + str(bdice.getValue2()) + '\n')
Val = bdice.getTotal()
##Beginning of conditional blocks##
if Val == 7 or Val == 11:
gamestatus = "WON"
elif Val == 2 or Val == 3 or Val == 12:
gamestatus = "LOST"
if Val != 7 and bdice.getTotal() != 11 and Val != 2 and Val != 3 and Val != 12:
gamestatus = "CONTINUE"
#
myPoint = Val
print("The Point is now " + myPoint + "/n") #display the user's point value
global pSum
pSum = 0
#The point
while gamestatus == "CONTINUE": #Checking the point
global point
point = myPoint
pSum = MainDouble()
if pSum == myPoint:
gamestatus == "WON"
elif pSum == 7:
gamestatus = "LOST"
if gamestatus == "WON":
print("Winner!")
else:
print("Sorry, Seven out!")
print ("Roll Again?")
doubleDiceRoll = input("Roll Again?")
MainDouble()
这个街区:
^{pr2}$doubleDiceRoll
从未从''
更改,因此此循环将永远运行。在这个街区的尽头(但仍在里面!),你应该做点什么我想你在以下几点之后弄乱了你的压痕:
##Beginning of conditional blocks##
此行以下的所有内容都在while循环之外,但可能应该在其中。在
相关问题 更多 >
编程相关推荐