I’m working myself through this game in exercise 36
I have a function which contains a while loop and then when the while loop finishes it goes to an if statement to see if the player won the game or not.
If the player loses, I’m trying to have a counter that subtracts 1 from the live variable.
If the player wins, I’m trying to set the Villain_dead variable = True
I can’t figure out how to get a return out from the nested IF statement inside the game function.
Is this possible or am I going around it in the entirely wrong way?
def game(opponent):
villain_choice = ['Scissor', 'Rock', 'Paper']
my_options = ['1) Scissor', '2) Rock', '3) Paper']
my_choice = ['Scissor', 'Rock', 'Paper']
round_current = 0
win_current = 0
lost_current = 0
opponent_name = opponent
print('Lets go. Best out of 3.')
while win_current < 3 > lost_current:
print('\nYour options are:')
#make a for loop to print all the options from my_options list
for x in my_options:
print(x)
print("What's your move?")
choice = input('> ')
if choice == "1":
#randomised opponents move with random.choice() from the villain_choice list
villain_move = random.choice(villain_choice)
#shows what I chose and pics it out of my_choice list - the first option in a list is always 0
print("\nYou chose:", my_choice[0],"\nVillain chooses: ", villain_move )
#Makes 3 variables that is filled in from a return in game_rules.
win, round, lost = game_rules(my_choice[0], villain_move)
#Adds a 1 to every win a 1 to every lost and a 1 to every round.
win_current += win
round_current += round
lost_current += lost
print(f"You've won: {win_current}\nLost: {lost_current}\nRound: {round_current}")
elif choice == "2":
villain_move = random.choice(villain_choice)
print("You chose", my_choice[1] )
print("Villain chooses: '", villain_move,"'")
win, round, lost = game_rules(my_choice[1], villain_move)
win_current += win
round_current += round
lost_current += lost
print(f"You've won: {win_current}\nLost: {lost_current}\nRound: {round_current}")
elif choice == "3":
villain_move = random.choice(villain_choice)
print("You chose", my_choice[2] )
print("Villain chooses: '", villain_move,"'")
win, round, lost = game_rules(my_choice[1], villain_move)
win_current += win
round_current += round
lost_current += lost
print(f"You've won: {win_current}\nLost: {lost_current}\nRound: {round_current}")
else:
print("Not sure what that means")
#print('While = True - loop finised')
if win_current>2:
print(f"You lucky bastard you pulled it off!\nThe {opponent_name} is dead")
print("Lets fo back to the cross road")
return True
where_to_go(opponent_name, dead)
elif lost_current>2:
print(f"You're donzo.\nThe {opponent_name} fucked you up")
print("You'll have to start over!")
else:
print("Something is wrong here")
Villain_dead=False
lives = 3
def game('Villain')