Apr-23-2018, 09:30 PM
Hi, all. I'm super new to python and to OOP and was hoping for some help. I built a simple RPS game and wanted to include a check for user entry against a dictionary. If entry is invalid a simple print command asking for another entry and if the entry was valid, break and move onto the next line. The problem is when I tried within an existing loop, the break would skip additional steps. I couldn't figure it out so was hoping a kind stranger could help out this poor lost soul o_0.
My original code (without the horrible attempt at QC) is below. Could someone give me a hand as to how to have the choice input on line 51 QC'd against the user_legend dictionary on line 57? Thanks in advance!
My original code (without the horrible attempt at QC) is below. Could someone give me a hand as to how to have the choice input on line 51 QC'd against the user_legend dictionary on line 57? Thanks in advance!
#Version one with no QC check for rock, paper, scissor user entry
import sys
import random
import time
import math
#Ask for user name and greet user
user = input('Hi, what\'s your name? ')
#Intro yourself
print()
print('Hello,',user+'. I am RPS-Bot, and I am here to KILL you.')
time.sleep(1)
print()
print('Nah, I\'m just messin...')
time.sleep(1.5)
print('Seriously though, if you want to ',end="")
print ('live then play Rock, Paper, Scissors')
time.sleep(1.5)
print()
#print("Do you want to play until you're bored of a 'best of' match?")
#choice = input("Type 'U' for unlimited and 'B' for best of")
while 1==1:
best = input('How many "best of games" do you want to play? ')
try:
int(best)
break
except ValueError:
print(best,"??? I need a number. Humans, amirite?")
print()
continue
win_number = math.ceil(int(best)/2)
#Ask for user input for rock paper scissor. Can accept single letter or uppercase and lowercase full spelling
print()
print("Ok, best of",best+". First one to",str(win_number)+" wins!")
time.sleep(1)
print()
print("Pick Rock, Paper or Scissors \n"
"(R, P, S if you're lazy.)")
time.sleep(0.5)
#Set Scores to Zero
rps_score = 0
user_score = 0
#start RPS loop
while (user_score < win_number and rps_score < win_number):
print()
choice = input("Whats your throw? ")
#generate RPS-bot throw
rps = random.randint(1,3)
rpslegend = {1:"Rock", 2:"Paper", 3:"Scissors"}
# create RPS legend
userlegend = {'rock': 'Rock', 'r': 'Rock', 'paper': 'Paper', 'p': 'Paper', 's': 'Scissors', 'scissors': 'Scissors'}
# generate game possibilities
possible_outcomes = {"Rock : Rock": "Tie, shoot again!", 'Rock : Scissors': "You win!",
'Rock : Paper': "You lose, sucka!",
"Paper : Paper": "Tie, shoot again!", 'Paper : Scissors': "You lose, sucka!",
'Paper : Rock': "You win!",
'Scissors : Scissors': "Tie, shoot again!", "Scissors : Rock": "You lose, sucka!",
"Scissors : Paper": "You win!"
}
game = userlegend[choice]+' : '+rpslegend[rps]
#indicate winner
print(game)
time.sleep(0.25)
print(possible_outcomes[game])
#tally score
if (possible_outcomes[game]) == "You win!":
user_score += 1
if (possible_outcomes[game]) == "You lose, sucka!":
rps_score += 1
#print score
time.sleep(0.5)
print(user+':',str(user_score)+'. RPS-Bot: ',str(rps_score))
#if tie, start loop over
if (possible_outcomes[game])=='Tie, shoot again!':
time.sleep(.5)
continue
time.sleep(.75)
print()
if user_score == win_number:
print('I lost??! NOW YOU MUST DIEEE!')
else:
print('I won, RPS-Bot is the GREATEST OF ALL TIIIIIIIME!')
