繁体   English   中英

石头,剪刀,石头Python 2游戏统计

[英]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()
  1. 您将需要至少一个或可能更多的数据结构/变量来保存该数据。 考虑到代码的结构,似乎可以轻松地在main()上创建它们并将其保存在那里(也就是说,您甚至不需要将em传递给其他函数)。 我将使用哪种数据结构(如果有)来保存该数据。
  2. 因为现在有一些需要记住赢/输/借鉴main()的比例,好像你需要一些方法为主要实际找出一个圆形发生了什么,以便它可以被保存在说某些工作。 现在,main只要求另一个函数打印发生了什么,而不告诉他们发生什么,因此您可能需要更改辅助函数中的某些内容。
  3. 特别是,您可能想要一个具有与GameRules类似的检查功能的函数,该函数可以return ROUND_RESULT ,而ROUND_RESULT是您可能要用来表示“赢”,“输”或“平局”的任何东西。 一旦有了这些, GameRules就会变得有点多余,因此您可能想通过调用此新函数来对其进行清理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM