我最近在学校开始学习python作为我的第一语言,并收到了一个家庭作业任务,要求我们创建一个简单的石头布剪刀游戏,但有一个扭曲(我的是一个RPG),我认为这将是一个很好的,如果我使它,所以你必须回答一个时间限制。我检查了一些其他线程,但是我不确定如何在我的程序中实现这些代码,所以我决定在这里询问。我对python非常陌生,所以如果可能的话,任何简单的答案都是首选。 提前谢谢! 编辑:tomh1012给了我一些建议,我接受了,但我的计时器仍然不工作。没有任何错误,它根本不工作!非常感谢您的帮助。另外,不管出于什么原因,我的老师还没有教我们函数,所以我对它们不是很了解。你知道吗
while keepPlaying == "y":
while playerHealth > 0 and cpuHealth > 0:
time.sleep(0.75)
print ("You have " + str(playerHealth) + " health.")
print ("The enemy has " + str(cpuHealth) + " health.")
print ("Rock")
time.sleep(0.75)
print ("Paper")
time.sleep(0.75)
print("Scissors")
time.sleep(0.75)
startTime=time.process_time()
playerChoice = input ("Shoot!")
endTime=time.process_time()
elapsedTime = startTime - endTime
cpuChoice = (random.choice(options))
time.sleep(0.75)
print ("Your opponent chose " + cpuChoice)
if elapsedTime > 300:
print("You're too slow!")
elif playerChoice == "r" and cpuChoice == "s" or playerChoice == "p" and cpuChoice == "r" or playerChoice == "s" and cpuChoice == "p":
damageDealt = 10 * combo
combo = combo + 1
time.sleep(0.75)
print("You deal " + str(damageDealt) + " damage!")
cpuHealth = cpuHealth - damageDealt
enemyCombo = 1
elif cpuChoice == "r" and playerChoice == "s" or cpuChoice == "p" and playerChoice == "r" or cpuChoice == "s" and playerChoice == "p":
enemyDamageDealt = fans * enemyCombo
playerHealth = playerHealth - enemyDamageDealt
enemyCombo = enemyCombo + 1
time.sleep(0.75)
print("Your enemy deals " + str(enemyDamageDealt) + " damage!")
combo = 1
elif cpuChoice == playerChoice:
time.sleep(0.75)
print ("You both chose the same!")
else:
time.sleep(0.75)
print ("...")
time.sleep(1)
print("Thats not a choice...")
enemyDamageDealt = fans * enemyCombo
playerHealth = playerHealth - enemyDamageDealt
enemyCombo = enemyCombo + 1
time.sleep(0.75)
print("Your enemy deals " + str(enemyDamageDealt) + " damage!")
if cpuHealth <= 0:
print ("You win and gained 5 fans!")
fans = fans + 5
keepPlaying = input("Play again (y or n)")
enemyHeal
elif playerHealth <= 0:
print("You lose, sorry.")
keepPlaying = input("Play again (y or n)")
下面是一个函数,用于显示提示用户输入的给定提示。如果用户在指定的超时时间内没有提供任何输入,那么函数返回
None
相关问题 更多 >
编程相关推荐