# Created By Evan Ryan
# we import our random module and time module
from random import *
import time
# this will track our wins
comp_wins = 0
player_wins = 0
# this will let us know when the match is finished
endgame = 0
# here we use simple print and sleep function to display a welcome message
print("Welcome to Rock, Paper, Scissors, Lizard, Spock")
time.sleep(3)
print("This match will be best 3 out of 5")
time.sleep(3)
print("Good Luck")
time.sleep(1)
# this will be our function to allow the user to make a choice
# they have 5 choices
# if they make a typo or choose a non option they will be asked to choose again
# we will also convert their selection to a lowercase letter
def pick_option():
user_pick = input("Choose Rock, Paper, Scissors, Lizard, Spock: ")
if user_pick in ["Rock", "rock", "r", "R"]:
user_pick = "r"
elif user_pick in ["Paper", "paper", "p", "P"]:
user_pick = "p"
elif user_pick in ["Scissors", "scissors", "sc", "SC"]:
user_pick = "sc"
elif user_pick in ["Lizard", "lizard", "l", "L"]:
user_pick = "l"
elif user_pick in ["Spock", "spock", "sp", "SP"]:
user_pick = "sp"
else:
print("Are you speaking english buddy?")
pick_option()
return user_pick
# this will act as our function for the computer to choose
# they will random select a number 1-5
# these number are assinged to one of the five options the user has
def comp_option():
comp_pick = randint(1,5)
if comp_pick == 1:
comp_pick = "r"
if comp_pick == 2:
comp_pick ="p"
if comp_pick == 3:
comp_pick = "sc"
if comp_pick == 4:
comp_pick = "l"
if comp_pick == 5:
comp_pick = "sp"
return comp_pick
所以我遇到的麻烦就是这样。游戏运行良好,一旦计算机或用户取得 3 场胜利,我们就会收到获胜或失败的消息。发生这种情况后,系统会要求您再次玩游戏。如果您点击“否”,则代码结束。如果您点击“是”,游戏将正确重新启动,但在您第一次选择时,它会将您带回获胜或失败屏幕。似乎胜利计数器没有重置或者我有不正确的缩进?
任何帮助表示赞赏。
PS:我知道可能还有一种更简单的方法来制作游戏,而不是使用所有这些 elif 语句。也许是上课什么的?虽然我是新手,所以这对我来说是最简单的。
温温酱
慕容708150
神不在的星期二
相关分类