在我的编程课上,我们正在创建一个骰子扑克游戏。一旦一轮比赛结束,玩家收到了他们的分数,这个分数就应该作为下一轮比赛的新起点。在代码中你可以看到我试图让“newPlayPoints”变成“playingPoint”,但是我不确定这是否是正确的方法。我敢肯定,由于我的初学者身份,代码有点混乱,但主要部分要看的功能下“updatePlayPoints”和评论,读“#试图获得playingPoint成为新的”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()
您正在返回
newPlayPoints
,但没有将它们设置为任何值。您只需调用updatePlayPoints
,对返回值不做任何操作。您不需要trackscore
、updatePlayPoints
或newPlayPoints
。而是将fiveDieScore
添加到PlayingPoint
。而且,按照现在的设置,玩家可以无分开始游戏。我假设应该有一个初始点数,我把它设为10。所以现在每一回合你都要检查玩家是否有足够的点数来平衡比赛,并且他们是否立即减去这些点数。把它想象成一个街机游戏。你必须有四分之一的上场时间,你要做的第一件事就是付出场费。你减去分数的方法毫无用处。PlayingPoint - 10
是一个有效的行,但是您将它设置为nothing,所以它什么也不做。你知道吗为了总结这些变化,我去掉了
TrackScore
、UpdatePlayPoints
和newPlayPoints
。在开头而不是结尾增加了点检相关问题 更多 >
编程相关推荐