我在做掷骰子的作业。这些规则是:
H 210H 1115轮结束时得分最高的人获胜。<>代码H 212F 213/code>基本上,我所做的是创建两个独立玩家在两轮游戏中滚动的变量,现在我试图把这些变量加在一起,这样玩家就可以将第一轮和第二轮的总和加起来。我的老师提到了一段时间的功能,但这是他唯一可以说的,而且我不知道该怎么做。
我觉得我所做的太复杂了,再加上它根本不起作用。
if (round2scoreP1 % 2) == 0 + (round1scoreP1 % 2) == 0:
addedscoreround2P1even=(totalround1scoreP1even)+(totalround2scoreP1even)
print(username1,"'s total for round 1 and 2 is",addedscoreround2P1even,".")
elif (round1scoreP1 % 2) != 0 + (round2scoreP1 % 2) != 0:
addedscoreround2P1odd=(totalround1scoreodd)+(totalround2scoreodd)
print(username1,"'s total for round 1 and 2 is",addedscoreround2P1odd,".")
elif (round1scoreP1 % 2) == 0 + (round2scoreP1 % 2) != 0:
addedscoreround2P1evenodd=(totalround1scoreP1even)+(totalround1scoreP1odd)
print(username1,"'s total for round 1 and 2 is",addedscoreround2P1evenodd,".")
elif (round1scoreP1 % 2) != 0 + (round2scoreP1 % 2) == 0:
addedscoreround2P1oddeven=(totalround1scoreP1odd)+(totalround1scoreP1even)
print(username1," obtained",addedscoreround2P1oddeven,".")发布于 2020-12-08 14:00:26
我不打算给你写整个作业,但是你可以考虑用一个游戏课来存储卷轴和总分:
class Player():
def __init__(self):
self.rolls = []
self.total_score = 0
def roll_dice():
self.rolls.append(random.randint(1, 6))https://stackoverflow.com/questions/65199984
复制相似问题