嗨,我正在尝试做我的计算机科学课程,这是为了测试我的能力(我选择的是骰子游戏。我们被允许使用资源,所以我来到这里,我需要帮助,因为我必须创造一个评分系统,但我需要它随着整数的变化而变化,以便它可以添加变量以获得最终分数。任何帮助都会很棒!我在下面附上了我的代码:
import time
import random
def totalScore(n,s):
file = open("total.txt", "a")
file.write("name: " + n + ", total: " + str(s) + "\n")
file.close()
return
def login():
while True:
print("")
username = input('What is your username? ')
password = input('What is your password? ')
if username not in ('User1', 'User2'):
print("")
print('Incorrect username, try again')
if password != 'password':
print("")
print('Incorrect password, try again')
continue
print("")
print(f'Welcome, {username} you have been successfully logged in.')
break
user1 = login()
user2 = login()
print("")
print("")
time.sleep(0.5)
print(" Rules")
print(" -----")
time.sleep(1)
print("• The points rolled on each player’s dice are added to their score.")
time.sleep(2)
print("• If the final total is an even number, an additional 10 points are added to their score.")
time.sleep(2)
print("• If the final total is an odd number, 5 points are subtracted from their score.")
time.sleep(2)
print("• If they roll a double, they get to roll one extra die and get the number of points rolled added to their score.")
time.sleep(2)
print("• The score of a player cannot go below 0 at any point.")
time.sleep(2)
print("• The person with the highest score at the end of the 5 rounds wins.")
time.sleep(2)
print("• If both players have the same score at the end of the 5 rounds, they each roll 1 die and whoever gets the highest score wins (this repeats until someone wins).")
time.sleep(2)
print("")
print("")
round_number = 0
msg = "Press Enter to Start The Round:\n\n"
while True:
if input(msg).lower() != '':
continue
round_number += 1
print(f"Round Number {round_number}\n")
print("User1 goes first : ")
roll_number = 0
dice3 = 0
print("")
msg = "Press Enter to Roll The Dice: \n\n"
while True:
if input(msg).lower() != '':
continue
roll_number = 1
dice1 = random.randint(1, 6)
print(f"1> You got a {dice1}\n")
input ("Press Enter to Roll Again!")
roll_number = 2
dice2 = random.randint(1, 6)
print(f"2> You got a {dice2}\n")
if roll_number == 2:
break
print("You have used both of your rolls")
total = dice1 + dice2
print("your total for this round is " + str(total) + ".")
if dice1 == dice2:
input ("Lucky!, you get an additional roll : ")
roll_number = 3
dice3 = random.randint(1, 6)
print(f"Bonus Role> You got a {dice3}\n")
total = total + dice3
print("your final total for this round is " + str(total) + ".")
print("User2 its your turn now : ")
roll_number = 0
dice3 = 0
print("")
msg = "Press Enter to Roll The Dice: \n\n"
while True:
if input(msg).lower() != '':
continue
roll_number = 1
dice1 = random.randint(1, 6)
print(f"1> You got a {dice1}\n")
input ("Press Enter to Roll Again!")
roll_number = 2
dice2 = random.randint(1, 6)
print(f"2> You got a {dice2}\n")
if roll_number == 2:
break
print("You have used both of your rolls")
total = dice1 + dice2
print("your total for this round is " + str(total) + ".")
if dice1 == dice2:
input ("Lucky!, you get an additional roll : ")
roll_number = 3
dice3 = random.randint(1, 6)
print(f"Bonus Role> You got a {dice3}\n")
total = total + dice3
print("your final total for this round is " + str(total) + ".")
msg = "Press Enter to Start a new round! \n"
round_number
if round_number == 5:
break
print("All the rounds are complete")