私は、プレイしたいラウンドの数を入力するようにユーザーに求めましたが、実際には別のラウンドでプログラムをプレイする方法はわかりません。コードの終わり近くで、私はスコアをラウンドに加えるようにしようとしています。どんな助け?ロック、ペーパー、ハサミのゲームをPythonで作成する。
import time
import random
print ("Welcome to the Rock, Paper, Scissors Game!")
time.sleep(1)
rounds = int(raw_input("How many rounds would you like to play?"))
while rounds not in range(3,11):
try:
rounds = int(raw_input("Sorry! I can only play between 3 and 10 rounds. Try again:"))
except:
print ("ERROR invalid input. Out of range or wrong type of data.")
if rounds in range(3,11):
time.sleep(1)
print ("Challenge accepted! I will play you for", rounds,"rounds! Let's begin!!!")
options = ("rock","paper","scissors")
userChoice = raw_input("Rock, Paper or Scissors, peasant?")
while userChoice not in options:
try:
userChoice = raw_input("Not an option lad. Rock, paper or scissors")
except:
print ("ERROR invalid input. Out of range or wrong type of data.")
cpuoption1 = "rock"
cpuoption2 = "paper"
cpuoption3 = "scissors"
cpuChoice = random.randint(1,3)
answer = ""
if cpuChoice == 1:
answer = cpuoption1
elif cpuChoice == 2:
answer = cpuoption2
elif cpuChoice == 3:
answer = cpuoption3
print ("I choose", answer,"!")
user= 0
cpu = 0
if userChoice == "rock" and answer == cpuoption1:
user += 1
cpu += 1
print ("Draw!")
elif userChoice == "paper" and answer == cpuoption2:
user+=1
cpu+=1
print("Draw!")
elif userChoice == "scissors" and answer == cpuoption3:
user+=1
cpu+=1
print ("Draw!")
elif userChoice == "rock" and answer == cpuoption2:
cpu+=1
print ("CPU wins the round!")
elif userChoice == "rock" and answer == cpuoption3:
user+=1
print ("Player wins the round!")
elif userChoice == "paper" and answer == cpuoption1:
user+=1
print ("Player wins the round!")
elif userChoice == "paper" and answer == cpuoption3:
cpu+=1
print ("CPU wins the round!")
elif userChoice == "scissors" and answer == cpuoption1:
cpu+=1
print ("CPU wins the round!")
elif userChoice == "scissors" and answer == cpuoption2:
user+=1
print ("Player wins the round!")
if cpu==rounds:
print("CPU beat the player!")
elif user==rounds:
print("Player beat the CPU!")
elif cpu==rounds and user==rounds:
print("Looks like that was a draw! Good game!")