0

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()
1
  • At the end of your script you have doubleDiceRoll = input("Roll Again?"), but that isn't inside while doubleDiceRoll == ''. Nothing changes the condition, which is always True Commented Apr 15, 2014 at 21:07

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

5 Comments

iirc doubleDiceRoll is supposed to be a prompt to the user "Do you want to play again?" I'd have to look back at his previous posting (to which I have the accepted answer) to be sure. EDIT: Yep at the end of his original while loop is the line doubleDiceRoll = raw_input ("Roll Again?"). Looks like the whole thing should be inside the while block.
Ok, either way doubleDiceRoll needs to be updated. I updated my answer.
Thanks Bill and mhelster. I tried to fix that issue but the code stops if I break the while statement by changing it to false... Any ideas?
@user3462223 How did you "break the while statement"?
Thanks everyone!!! I had to move that statement up into the While block as you all pointed out. I don't know why I didn't catch it last night :/
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.