My Rock, Paper, Scissors game has a function that can calculate how many rocks, scissors, and papers the player has used, and can respond to that. However, in the function that decides the computer's weapon, I have a random number generator, and I haven't figured out a way to stop the generator from working after the first round.
Here is the code in question:
#will import random and set variables
import random
numrock = 0
numpaper = 0
numscissors = 0
fingers = 0
weapon = 0
win = 0
lost = 0
tie = 0
values = []
comvalues = []
respond == False
#will return rock, paper, or scissors randomly and save the computer's weapon in a list
def hand():
global fingers, comvalues, respond
while respond == False:
fingers = random.randint(1,3)
if fingers == 1:
print('I placed down rock!')
comvalues.append('r')
return 'r'
elif fingers == 2:
print('I placed down paper!')
comvalues.append('p')
return 'p'
else:
print('I place down scissors!')
comvalues.append('s')
return 's'
#will set the program to respond to previous entries
def respond(numrock, numpaper,numscissors):
global fingers
if int(numrock) > int(numpaper):
if int(numrock) > int(numscissors):
fingers == 2
hand()
respond == True
return respond
return fingers
else:
fingers == 1
hand()
respond == True
return respond
return fingers
else:
if int(numpaper) > int(numscissors):
fingers == 3
hand()
respond == True
return respond
return fingers
else:
fingers == 1
hand()
respond == True
return respond
return fingers
#Main Program
print('Welcome to Rock, Paper, and Scissors. You know the rules already. But, we will play for as long as you want. If you win more rounds, then you survive. If I win though, well... you already know.')
while True:
weapon = input('Choose a weapon(r for rock, p for paper, s for scissors, q for quit)!: ').lower()
if weapon == 'q':
record()
break
elif weapon == 'r' or weapon == 'p' or weapon == 's':
if game(weapon):
respond(numrock, numpaper, numscissors)
else:
print("Incorrect option! Please try again.")
continue
Aucun commentaire:
Enregistrer un commentaire