[英]Rock, Paper, Scissors Python 2 Game Statistics
我是Python的初学者,尝试使用Python 2创建RPS游戏。我相信自己已经编写了基本的游戏和规则,但是当我浏览不同的RPS python代码后,我感到困惑,不知道该怎么做。继续使用现有的def样式并满足我的要求。
我不知道如何跟踪每个游戏中发生了多少个“手势”(因为我需要计算最后每个游戏的平均手势数)。
我还需要实施编码,使我能够跟踪并显示以下各项的最终统计信息:玩家/计算机获胜率,玩家/计算机获胜率以及每个游戏的平均“手势”(用户输入)数,以确定优胜者。
请注意,我自己为此付出了很多时间(我在自学),我不仅在寻求“简单的答案”,而且我感到沮丧,无法独立寻求帮助。
任何帮助将不胜感激!
这是我当前的代码:
import random
def Welcome(Name):
print "Welcome " + Name
print "We're going to play rock, paper, scissors."
def ChoiceSelection(PlayerChoice,ComputerChoice):
print "You chose: " + PlayerChoice
print "The computer chose: " + ComputerChoice
def GameRules(PlayerChoice,ComputerChoice,Name):
if PlayerChoice == ComputerChoice:
print "Draw, nobody wins."
if PlayerChoice == "Rock" and ComputerChoice == "Scissors":
print Name + " wins!"
elif PlayerChoice == "Paper" and ComputerChoice == "Rock":
print Name + " wins!"
elif PlayerChoice == "Scissors" and ComputerChoice == "Paper":
print Name + " wins!"
if ComputerChoice == "Rock" and PlayerChoice == "Scissors":
print "The computer wins!"
elif ComputerChoice == "Paper" and PlayerChoice == "Rock":
print "The computer wins!"
elif ComputerChoice == "Scissors" and PlayerChoice == "Paper":
print "The computer wins!"
def main():
while True:
Name = raw_input("Player Name: ")
Welcome(Name)
print "Please make your selection: Rock, Paper, or Scissors"
print "Remember, your choices are case sensitive!"
PlayerChoice = raw_input("Your selection: ")
ComputerChoice = random.choice(["Rock","Paper","Scissors"])
ChoiceSelection(PlayerChoice,ComputerChoice)
GameRules(PlayerChoice,ComputerChoice,Name)
main()
GameRules
类似的检查功能的函数,该函数可以return ROUND_RESULT
,而ROUND_RESULT
是您可能要用来表示“赢”,“输”或“平局”的任何东西。 一旦有了这些, GameRules
就会变得有点多余,因此您可能想通过调用此新函数来对其进行清理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.