Lots of unnecessary code here. Luckily this is kind of my wheelhouse, as a former casino dealer turned programmer :)
def MainDouble():
bDice = pairOfDice()
point = None
while True:
bDice.toss()
if point:
if bDice.getTotal() == 7:
# you lose
point = None
elif bDice.getTotal() == point:
# you win
point = None
else:
# roll again
else: # no point, this is the come out roll
if bDice.getTotal() in [7, 11]: # win
elif bDice.getTotal() in [2,3,12]: # lose
else:
point = bDice.getTotal()
You should really refactor a lot of this, though.
class CrapsGame(object):
def __init__(self):
self.dice = pairOfDice()
self.point = None
def rolldice(self):
self.dice.toss()
def playagain(self):
if input("Roll again? (y/n): ").lower() == 'y':
return True
return False
def score(self):
result = self.dice.getTotal()
if self.point:
if result == 7:
self.point = None
# lose
elif result == self.point:
self.point = None
# win
else:
# keep going
else:
if result in [7, 11]: # win
elif result in [2,3,12]: # lose
else:
self.point = result
def run(self):
while True:
self.rolldice()
self.score()
if not self.playagain():
return
if __name__ == "__main__":
game = CrapsGame()
game.run()