установление серии побед в игре в кости - PullRequest
0 голосов
/ 05 мая 2020

Всем привет. Действительно, ДЕЙСТВИТЕЛЬНО застрял здесь. Я обновил свой код ниже. Я пытаюсь установить sh счетчик для отслеживания сыгранных игр, правильных предположений и> неверных предположений, плюс, когда количество последовательных правильных предположений = 4 или пользователь прекращает играть, предоставляется сводка игры. Я не могу заставить счетчик работать правильно. Помощь приветствуется!

import math
import dice
import random

# Print introduction and game explanation
print ("")
print ("")
print ("Would you like to play a game?")
print ("The game is...'Petals Around the Rose'. Cool eh?")
print ("Pay attention - the name of the game is important.")
print ("Each round, five dice are rolled and")
print ("You'll be asked for the score. (Hint? The score")
print ("will always be either 'zero' or an even number).")
print ("Your challenge is to deduce how the computer has")
print ("calculated the score.")
print ("You need to input your guess, after which")
print ("You'll learn if you were right. If not, you'll")
print ("be told the correct score & asked to roll again.")
print ("If you can guess correctly four times in a row,")
print ("You'll be declared the winner and receive the")
print ("majestic title of 'Potentate of the Rose'")
print ("")

# Define win count (four correct guesses in a row required)
win_count = 0

# Obtain input from user:    
answer = input("Are you up for the challenge? Enter 'y' or 'n' : ")
# If answer = no, exit game
if answer == 'n':
    print("Really? fine then. See ya!")
    exit()
# If answer = yes, commence game
elif answer == 'y':
    print("")
    print ("Ok...here comes the first roll!")
    print("")
    # import dice representation
    import dice

# Roll random dice x 5
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
die3 = random.randint(1, 6)
die4 = random.randint(1, 6)
die5 = random.randint(1, 6)
dice.display_dice(die1, die2, die3, die4, die5)


# Obtain player's guess for the roll
roll_guess = int(input("Enter your guess for this roll: "))

# Define die results for all dice for guess purposes to
# match the 'petals around the rose'. So, if roll a 2, 4 or 6,
# the result is zero. If return a 3, the result is 2. If
# return a 5, the result is 4.
def roll_result(die1):
    if die1 == 1 or die1 == 2 or die1 == 4 or die1 == 6:
        die1 = 0
    elif die1 == 3:
        die1 = 2
    elif die1 == 5:
        die1 = 4
    return die1
def roll_result(die2):
    if die2 == 1 or die2 == 2 or die2 == 4 or die2 == 6:
        die2 = 0
    elif die2 == 3:
        die2 = 2
    elif die2 == 5:
        die2 = 4
    return die2
def roll_result(die3):
    if die3 == 1 or die3 == 2 or die3 == 4 or die3 == 6:
        die3 = 0
    elif die3 == 3:
        die3 = 2
    elif die3 == 5:
        die3 = 4
    return die3
def roll_result(die4):
    if die4 == 1 or die4 == 2 or die4 == 4 or die4 == 6:
        die4 = 0
    elif die4 == 3:
        die4 = 2
    elif die4 == 5:
        die4 = 4
    return die4
def roll_result(die5):
    if die5 == 1 or die5 == 2 or die5 == 4 or die5 == 6:
        die5 = 0
    elif die5 == 3:
        die5= 2
    elif die5 == 5:
        die5 = 4
    return die5
# tally all 5 dice rolls
a = roll_result(die1)
b = roll_result(die2)
c = roll_result(die3)
d = roll_result(die4)
e = roll_result(die5)
total_roll_result = a + b + c + d + e

# Compare user input to dice result
if roll_guess == total_roll_result:
    print("")
    print('Well done! You guessed it!')
    print("")
elif guess % 2 == 0:
    print("")
    print("No sorry, it's", total_roll_result, "not", roll_guess)
    print("")
else:
    print("")
    print ("No, sorry, it's", total_roll_result, 'not', roll_guess,"")
    print ("Remember,the answer will always be an even number")
    print("")

# Obtain user input if continuing to play    
another_attempt = input("Are you up to play again? If so, enter y or n ")
print("")
# Commence loop and win count. 
while another_attempt == 'y' and win_count <4:
    # Commence win count
    win_count = 0
    # Commence games played count
    games_played = 0
    # Commence incorrect guesses count
    incorrect_guesses = 0
    # If user has not yet gotten 4 guesses in a row:
    if win_count < 4:
        die1 = random.randint(1,6)
        die2 = random.randint(1,6)
        die3 = random.randint(1,6)
        die4 = random.randint(1,6)
        die5 = random.randint(1,6)
        result = dice.display_dice(die1, die2, die3, die4, die5)
        a = roll_result(die1)
        b = roll_result(die2)
        c = roll_result(die3)
        d = roll_result(die4)
        e = roll_result(die5)
        total_roll_result = a + b + c + d + e
        roll_guess = int(input('Enter your guess for this roll: '))
        print("")
        if roll_guess == total_roll_result:
            # Update win count
            win_count += 1
            # Update games played count
            games_played += 1
            print("")
            print('Nice work - you got it right!')
        elif roll_guess %2 == 0:
            # reset win count
            win_count = 0
            # Update games played count
            games_played += 1
            # Update incorrect guesses count
            incorrect_guesses += 1
            print("")
            print("Nah, sorry, it's", total_roll_result, "not", roll_guess)
        else:
            # Reset win count
            win_count = 0
            # Update games played count
            games_played += 1
            # Update incorrect guesses count
            incorrect_guesses += 1
            print("")
            print ("Nah, sorry, it's", total_roll_result, 'not', roll_guess,"")
            print ("Remember,the answer will always be an even number")
        print("")
        another_attempt = input("Are you up to play again? ")
        # Quit loop if user no longer wishes to play
        # Provide game summary
        if another_attempt == 'n':
                print ("")
                print ("Game Summary")
                print ("------------")
                print ("")
                print ("You played ", games_played, "games.")
                print ("")
                print ("You had ", correct_guesses, "overall and ")
                print ("")
                print ("a total of ", incorrect_guesses, "overall ")
                print ("")
                print ("Cheerio!")
                exit()
    if win_count == 4:
        # Inform player has correctly guessed 4 in a row
        # Print congratulations message
        print ("")
        print ("")
        print ("You've done it! You've successfully guessed")
        print ("Four times in a row. Looks like you worked ")
        print ("out the secret. Now, stay stum & tell no one!")
        print ("")
        # Provide game summary
        print ("Game Summary")
        print ("")
        # Provide tally of games played & print:
        print ("You played ", games_played, "games.")
        print ("")
        # Provide tally of correct guesses & print:
        print ("You had ", correct_guesses, "overall and ")
        print ("")
        # Provide tally of total incorrect guesses & print:
        print ("a total of ", incorrect_guesses, "overall ")
        print ("")
        print ("Cheerio!")
        exit()

def game_stats():
    win_count
    games_played
incorrect_guesses

1 Ответ

1 голос
/ 05 мая 2020

Ты выглядишь здесь очень потерянным. Эта часть не имеет никакого смысла

def win_count():
    win_count() == 0
    correct == total_roll_result

Я думаю, вы имеете в виду что-то вроде этого

win_count = 0
correct = total_roll_result == roll_guess

Примечание

Когда вы говорите

def win_count:
   # some code

вы определяете win_count как функцию! Но очевидно, что вы хотите, чтобы win_count было целым числом, которое что-то считало.

...