2016-11-15 3 views
0
ComputerChoice = "" 
x = 0 
wins = 0 
losses = 0 
ties = 0 
rounds = 0 
abc = 0 
CurrentStatus = 'started' 

Choices = ['Rock','Paper','Scissors'] 
################################################# 
def computerchoice(ComputerChoice, Choices, UserChoice): #number 
      listthing = Choices[:] 
      #listthing.remove[UserChoice] 
      ComputerChoice = random.choice(listthing) 
      ComputerChoice = Choices.index(ComputerChoice) 
      return ComputerChoice 
################################################# 
import easygui 
import random 
easygui.msgbox("Hello, This is a standard game of Rock, Paper, Scissors.","Welcome!","Next>>>") 

while x == 0: 
     UserChoice = easygui.buttonbox(' __ __ __ __ __ __ __ __ __ __ You just ' +CurrentStatus+ '. __ __ __ __ __ __ __ __ __ __ \n You currently have won '+str(wins)+ ' times, lost ' +str(losses)+' times, and tied '+ str(ties)+' times. \n\n\nClick your next move: ','Choice Picker 2000',['Rock','Paper','Scissors','Done']) 
     UserChoice = ['Rock','Paper','Scissors','Done'].index(UserChoice) 
     ComputerChoice = computerchoice(ComputerChoice, Choices, UserChoice) 
     if UserChoice == ComputerChoice: 
        ties = ties +1 
        rounds = rounds +1 
        CurrentStatus = "Tied" 


     if UserChoice== 3: 
        x = 1 
        break 

     elif UserChoice > ComputerChoice and UserChoice + ComputerChoice != 4: 
        wins = wins +1 
        rounds = rounds + 1 
        CurrentStatus = "Won" 

     elif UserChoice < ComputerChoice and UserChoice + ComputerChoice != 4: 
        losses = losses +1 
        rounds = rounds +1 
        CurrentStatus = "Lost" 

     elif UserChoice + ComputerChoice ==4 and UserChoice != ComputerChoice: 
        if Userchoice == 1: 
          score = score +1 
          rounds = rounds +1 
          CurrentStatus = "Won" 
        elif ComputerChoice == 1: 
          losses = losses +1 
          rounds = rounds +1 

          CurrentStatus = "Lost" 


result = ["Cool.","Okay.","I am a failure"] 
if wins>losses: 
     easygui.msgbox("You won "+str(wins)+ " times, lost " +str(losses)+" times, tied "+ str(ties)+ " and won " +str(int(float(wins)/float(rounds)*100))+ "% of the time.","",result[0]) 
elif wins==losses: 
     easygui.msgbox("You won "+str(wins)+ " times, lost " +str(losses)+" times, tied "+ str(ties)+ " and won " +str(int(float(wins)/float(rounds)*100))+ "% of the time.","",result[1]) 
elif wins<losses: 
     easygui.msgbox("You won "+str(wins)+ " times, lost " +str(losses)+" times, tied "+ str(ties)+ " and won " +str(int(float(wins)/float(rounds)*100))+ "% of the time.","",result[2]) 

私はこれを実行すると大丈夫ですが、 "ロック"を押すと、あなたはいつも結びつき、勝つことはありません。あなたが "はさみ"を押すと、あなたは常に結びつき/勝ち、失うことはありません。 これは同じ問題だとはかなり確信していますが、誰かがそれを見渡すことができれば、とても感謝しています。勝利と敗北の問題

答えて

0

勝者を決定するためのあなたのロジックは多少複雑です。たぶん単純化し、その一部をヘルパー関数に引き出すようにしてみてください。あなたのじゃんけんリストが位置cで任意の選択のために、それに勝る選択肢は位置になるような順序であることを

(この機能は、意図的に不必要に冗長です)

def userWon(userChoice, computerChoice): 
    if (userChoice == (computerChoice + 1 % 3)): 
     return True 
    if (computerChoice == (userChoice + 1 % 3)): 
     return False 
    if (computerChoice == userChoice): 
     return None 

注意。これを使用すると、ユーザーが勝った場合はTrueを返し、紛失した場合はFalseを返し、それが同軸ならNoneを返すこのヘルパー関数を使用することができます。

これを呼び出す前にQuitオプションを確認することができます。

関連する問題