如何将最终玩家分数作为下一轮的起始分数?

时间:2015-09-18 19:00:10

标签: python function loops scoring

在我的编程课上,我们正在创建一个骰子扑克游戏。一轮完成并且玩家得到他们的分数后,该分数应该被用作下一轮的新起点。在代码中你可以看到我试图制作" newPlayPoints"成为" playingPoint"但是我不确定这是否是正确的方法。由于我的初学者身份,我确信编码有点混乱,但要查看的主要部分将在函数" updatePlayPoints"和评论#" #Attempting让playPoint成为新的" newPlayPoints"。谢谢你的帮助!

from random import randint

def rollFiveDie():

    allDie = []
    for x in range(5):
        allDie.append(randint(1,6))

    return allDie

def outputUpdate(P, F):

    print(P)
    print(F)

def rollSelect():

    rollSelected = input("Which die would you like to re-roll? (Choose 1, 2, 3, 4 and/or 5 from the list)   ")
    print("  ")
    selectList = rollSelected.split()

    return selectList

def rollPicked(toRollList, diceList):

    for i in toRollList:
        diceList[int(i) - 1] = randint(1,6)

def scoring(dList):

    counts = [0] * 7
    for value in dList:
        counts[value] = counts[value] + 1

    if 5 in counts:
        score = "Five of a Kind", 30
    elif 4 in counts:
        score = "Four of a Kind", 25
    elif (3 in counts) and (2 in counts):
        score = "Full House", 15
    elif 3 in counts:
        score = "Three of a Kind", 10
    elif not (2 in counts) and (counts[1] == 0 or counts[6] == 0):
        score = "Straight", 20
    elif counts.count(2) == 2:
        score = "Two Pair", 5
    else:
        score = "Lose", 0

    return score

def numScore(diList):

    counts = [0] * 7
    for v in diList:
        counts[v] = counts[v] + 1

    if 5 in counts:
        finScore = 30
    elif 4 in counts:
        finScore = 25
    elif (3 in counts) and (2 in counts):
        finScore = 15
    elif 3 in counts:
        finScore = 10
    elif not (2 in counts) and (counts[1] == 0 or counts[6] == 0):
        finScore = 20
    elif counts.count(2) == 2:
        finScore = 5
    else:
        finScore = 0

    return finScore

def printScore(fscore):
    print(fscore)
    print("  ")

def trackScore(score1, score2):

    comScore = (score1) + (score2)

    return comScore

#Starting Points
playPoints = 100
print("New round! Your points are: ", playPoints)
newPlayPoints = 100 - 10


def updatePlayPoints(nPP, PP):

    nPP = PP

    return nPP


def diceGame():

    contPlaying = True
    while contPlaying:


        playing = input("It takes 10 points to play. Would you like to play the Dice Game? (Answer 'y' or 'n'):  ")
        print('  ')

        if playing == 'y':

            #First Roll
            fiveDie = rollFiveDie()

            outputUpdate("Your roll is...", fiveDie)

            #Choosing Second Roll/Second Roll execution
            pickDie = input("Which die would you like to re-roll? (Choose 1, 2, 3, 4 and/or 5 from the list)   ")
            print("   ")
            pickDie = pickDie.split()

            rollPicked(pickDie, fiveDie)

            outputUpdate("Your next roll is...", fiveDie)

            #Choosing Last Roll
            pickDie = rollSelect()

            rollPicked(pickDie, fiveDie)

            outputUpdate("Your final roll is...", fiveDie)

            #Scoring output

            finalScore = numScore(fiveDie)

            print(scoring(fiveDie))

            fiveDieScore = numScore(fiveDie)

            finalPoints = newPlayPoints + finalScore

            print(finalPoints)

            #Attempting to get playingPoint to become new "newPlayPoints"
            playingPoint = trackScore(fiveDieScore, newPlayPoints)

            if playingPoint > 10:
                playingPoint - 10

            else:
                    print("No more points to spend. Game Over.")
                    contPlaying = False

            updatePlayPoints(newPlayPoints, playingPoint)

        else:

            contPlaying = False

def main():

    diceGame()

main()

1 个答案:

答案 0 :(得分:0)

您将返回newPlayPoints,但您没有将它们设置为任何内容。您只是调用updatePlayPoints并且不对返回值执行任何操作。您不需要trackscoreupdatePlayPointsnewPlayPoints。而是将fiveDieScore添加到PlayingPoint。此外,现在它的设置方式是玩家可以在没有积分的情况下开始游戏。我假设这个人应该有一个初始的分数,我把它设置为10.所以现在每转一圈你都会检查玩家是否有足够的分数甚至可以玩,如果他们立即减去这些分数。把它想象成是一个街机游戏。你必须有四分之一的时间来玩,你要做的第一件事就是玩游戏。你减去积分的方式什么也没做。 PlayingPoint - 10是一个有效的行,但您将其设置为空,因此它不执行任何操作。

def diceGame():

contPlaying = True
PlayingPoints = 10 #Initial points
while contPlaying:


    playing = input("It takes 10 points to play. Would you like to play the Dice Game? (Answer 'y' or 'n'):  ")
    print('  ')

    if playing == 'y' and PlayingPoint >= 10:

        #Subtract the points used for the turn
        PlayingPoint -= 10

        #First Roll
        fiveDie = rollFiveDie()

        outputUpdate("Your roll is...", fiveDie)

        #Choosing Second Roll/Second Roll execution
        pickDie = input("Which die would you like to re-roll? (Choose 1, 2, 3, 4 and/or 5 from the list)   ")
        print("   ")
        pickDie = pickDie.split()

        rollPicked(pickDie, fiveDie)

        outputUpdate("Your next roll is...", fiveDie)

        #Choosing Last Roll
        pickDie = rollSelect()

        rollPicked(pickDie, fiveDie)

        outputUpdate("Your final roll is...", fiveDie)

        #Scoring output

        finalScore = numScore(fiveDie)
        print(scoring(fiveDie))

        fiveDieScore = numScore(fiveDie)

        finalPoints = PlayingPoint + finalScore
        print(finalPoints)

        playingPoint += fiveDieScore            

    else:

        contPlaying = False

总结我删除的更改TrackScoreUpdatePlayPointsnewPlayPoints。将点检查添加到开头而不是结尾