在这个游戏中,我的任务是做的,其中一个部分是在游戏中的所有球员开始与0分,并必须努力达到100分,这是通过掷骰子赚取。玩家决定停止滚动后,显示每个玩家的得分。我的问题是,我不知道如何分别为每个玩家分配一个“分数”变量,这个变量与最初玩的玩家数量有关
玩家1:掷2和5 玩家1得分=+25 其他所有玩家
基本上,我需要帮助如何检查,例如用户在开始输入,3名球员正在玩,3个不同的变量将分配给每个球员,其中包含他们的分数,这将随着游戏的进展而改变。你知道吗
我不知道正确的代码应该包含什么,所以我要寻求帮助
import random
playerList = []
count = 0
def rollTurn():
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
print("Your first dice rolled a: {}".format(dice1))
print("Your second dice rolled a: {}".format(dice2))
print("-------------------------MAIN MENU-------------------------")
print("1. Play a game \n2. See the Rules \n3. Exit")
print("-------------------------MAIN MENU-------------------------")
userAsk = int(input("Enter number of choice"))
if userAsk == 1:
userNun=int(input("Number of players?\n> "))
while len(playerList) != userNun:
userNames=input("Please input name of player number {}/{}\n> ".format(len(playerList)+1, userNun))
playerList.append(userNames)
random.shuffle(playerList)
print("Randomizing list..:",playerList)
print("It's your turn:" , random.choice(playerList))
rollTurn()
while count < 900000:
rollAgain=input("Would you like to roll again?")
if rollAgain == "Yes":
count = count + 1
rollTurn()
elif rollAgain == "No":
print("You decided to skip")
break
我希望在一个玩家的回合中,在掷完骰子后,这两个掷骰子的值被加到该玩家的分数中,然后,记分板将显示大厅中所有玩家的当前分数,并继续到下一个玩家,在那里同样的事情发生。你知道吗
与其使用
playerList
的列表,不如使用dict:如果需要获取数据,可以迭代dict中的键。例如在Python3中:
添加数据的过程与此类似:
相关问题 更多 >
编程相关推荐