实施骰子游戏

时间:2019-10-28 17:16:04

标签: python

卡塔琳娜正在开发一款两人骰子游戏。 玩家各自掷出两个6面骰子,并根据自己的得分而获得积分 滚。一个游戏中有5个回合。在每个回合中,每个玩家掷出两个骰子。

规则是:

•每个玩家的骰子上累积的点数将添加到他们的分数中。 •如果总数是偶数,则将其得分再增加10分。

•如果总数为奇数,则从其分数中减去5分。

•如果掷双骰,他们将掷出一个额外的骰子,并获得掷骰点数 他们的分数。

•玩家的分数在任何时候都不能低于0。

•5个回合中得分最高的人获胜。

•如果两个玩家在5回合结束时得分均相同,则各自掷1个骰子,然后 得分最高者获胜(重复直到有人获胜)。 只允许授权玩家玩游戏。 在适当情况下,应验证用户的输入。

设计,开发,测试和评估以下程序:

  1. 允许两名玩家输入他们的详细信息,然后对其进行身份验证以确保他们 授权玩家。

  2. 允许每个玩家掷出两个6面骰子。

  3. 计算并输出每个ro的点 und和每个玩家的总得分。

  4. 允许玩家玩5回合。

  5. 如果在5个回合后两个玩家的得分均相同,则允许每个玩家掷1个骰子直到 有人赢。

  6. 输出在5回合结束时获胜的人。

  7. 将获胜者的得分及其姓名存储在一个外部文件中。

  8. 显示外部文件中前5个获胜得分的得分和玩家名称

这就是我所能做的一切,但我不知道该怎么做其余需要做的指令。谢谢,感谢您的帮助。

name = input("Enter Your Name")
if name == "Name":
    pwd= input ("Enter Password")
    if pwd == 'password':
        print ("Welcome")
    else:
        print("Incorrect login, checkdetails and try again")

else:
    print("Incorrect Username")


min = 1
max = 6
score =  0
roll = "yes"
answer = "no"

import time
import random

roll = input("Roll the dice?")
while roll == "yes" or roll =="y":
     print("Rolling...")
     dice1 = (random.randint(min,max))
     print(dice1)
     time.sleep(1)

     dice2 = (random.randint(min,max))
     print (dice2)
     time.sleep(1)

     total1 = dice1 + dice2
     score = (score + total1)
     if total1 == 1 or 3 or 5 or 7 or 9 or 11:
         score = (score +5)
     else:
          total1 == 2 or 4 or 6 or  8 or 10 or 12
          score = (score +10)
     roll == ("Your total score is", score)

我希望骰子滚动两次,给我两个数字,并显示不起作用的分数,骰子不断滚动。

1 个答案:

答案 0 :(得分:1)

还将roll = input("Roll the dice?")放在while循环的末尾,并添加print以获得得分:

while roll == "yes" or roll =="y":
     print("Rolling...")
     ...
     print("Your total score is", score)
     roll = input("Roll the dice?")