Question

So, I'm working on a craps program simulator from looking around the web, and from some assistance from the users on this forum. I was able to get it done for the most part. At least, I THINK I have the logic of the game right.

It was running last time I used it but I must have changed something without realizing it or something because now the while loop is running forever. In the program, the dice are rolling forever without user intervention.

Can someone have a look and see if there's a problem with the code? I've been working on this for hours and getting no where.

I will never gamble again! :/

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()
Was it helpful?

Solution

This block:

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()

doubleDiceRoll is never changed from '', so this loop will run for ever. At the end of this block (but still inside it!), you should do something like

    doubleDiceRoll = raw_input("Roll Again?") #Edit thanks to @Adam Smith

OTHER TIPS

I think you messed up your indentation after:

##Beginning of conditional blocks##

Everything below this line is outside of the while loop, but should probably be in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top