在骰子游戏中建立连胜纪录

问题描述 投票:-1回答:1

大家好。真的,真的卡在这里。我已经在下面编写了代码。同时在循环状态下,我试图在>'keep_playing'下建立一个计时计数器,如果它们达到4胜,则根据代码进行选择。可是我不能工作出如何使它工作的方法-任何人都可以协助吗?知道的代码是否则麻烦(和反馈表示赞赏),但宁愿保留尽可能接近原始的图像。谢谢!

import math
import dice
import random

# def PetalsAroundTheRose



# print introduction
print ("Would you like to play a game?")
print ("The game is...'Petals Around the Rose'. Cool")
print ("and catchy eh? Now, pay attention though as")
print ("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 ("")

# Ask user if up for the challenge!
# If no, exit game.
# If yes, roll the dice
play_petals = input("Are you up for the challenge? Enter 'y' for yes or 'n' for no: ")
print ("")
if play_petals == 'n':
    print ("Really? Ok, see ya!")
    exit()
if play_petals == 'y':
    print ("Ok...here comes the first roll!")
else:
    print("Sorry, wrong key? Press either y or n to continue please")

# Capture & maintain tally of correct guesses
# Four consecutive correct guesses required
# If incorrect, reset winning streak to zero


# Generate random roll of five dice
# Display resulting dice roll
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)

# Define the roll result in line with rules
# Only include in total if is a 3 or a 5, other results in zero
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
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
# Get players guess for roll
roll_guess = int(input("please enter your guess for this roll: "))
if roll_guess == total_roll_result:
    print ("Well done! Correct!")
elif roll_guess % 2 == 0:
        print ("No, sorry, it's", total_roll_result, 'not', roll_guess,"")
else:
    print ("No, sorry, it's", total_roll_result, 'not', roll_guess,"")
    print ("Remember,the answer will always be an even number")

# "keep playing?" loop
keep_playing = input("keep playing? Enter y or n: ")
print ("")
if keep_playing == 'n':
    exit()
if keep_playing == 'y':
    print ("Ok...here comes the next roll!")
    def win_count():
        win_count() == 0
        correct == total_roll_result
while keep_playing == 'y':
    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("please enter your guess for this roll: "))
    if roll_guess == total_roll_result:
        print ("Well done! Correct!")
    elif roll_guess % 2 == 0:
        print ("No, sorry, it's", total_roll_result, 'not', roll_guess,"")
    else:
        print ("No, sorry, it's", total_roll_result, 'not', roll_guess,"")
        print ("Remember,the answer will always be an even number")
while keep_playing == 'y':
    def win_count():
        win_count() == 0
        correct == total_roll_result
    while win_count <= 4:
        if roll_guess(correct):
            win_count += 1
        else:
            win_count = 0
        if win_count == 4:
            print ("You keep getting this right!")
        stop_playing = input("Do you want to keep playing? Enter y or n ")
        if stop_playing == 'n':
            exit()
        if stop_playing == 'y':
            print ("")
            print ("Game Summary")
            print ("------------")
            print ("")
            print ("You played X games:")
            print ("")
            print ("")
            print ("Thanks for playing")
            exit()
python dice
1个回答
0
投票

您在这里看起来很迷路。这部分没有任何意义

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是一个整数,用于计数某物。

© www.soinside.com 2019 - 2024. All rights reserved.