Skip to content

Instantly share code, notes, and snippets.

@ibuilder
Created September 3, 2021 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibuilder/2d9a819cee4e7ccc1959fd00f1395f02 to your computer and use it in GitHub Desktop.
Save ibuilder/2d9a819cee4e7ccc1959fd00f1395f02 to your computer and use it in GitHub Desktop.
Rock Paper Scissor Lizard Spock
import random
class Characters():
def __init__(self, weight, player, winphrase, losephrase):
self.weight = weight
self.player = player
self.winphrase = winphrase
self.losephrase = losephrase
def __str__(self):
return str(self.__dict__)
choice1 = Characters(1, "Rock", "crushes","crushes")
choice2 = Characters(2, "Paper", "covers","disproves")
choice3 = Characters(3, "Lizard", "eats","poisons")
choice4 = Characters(4, "Spock", "vaporizes", "smashes")
choice5 = Characters(5, "Scissor", "cuts","decpitates")
choices = [choice1, choice2, choice3, choice4, choice5]
#NPC Character variables
npc_choice = vars(random.choice(choices))
print(npc_choice)
npc_weight = npc_choice['weight']
npc_player = npc_choice['player']
npc_winphrase = npc_choice['winphrase']
npc_losephrase = npc_choice['losephrase']
#Player character variables
character = "Demon"
print("-----------------")
print("1. Rock")
print("2. Paper")
print("3. Lizard")
print("4. Spock")
print("5. Scissor")
print("6. Quit")
print("-----------------")
character = input("Pick a number? ")
if character == "1":
character = vars(choice1)
elif character == "2":
character = vars(choice2)
elif character == "3":
character = vars(choice3)
elif character == "4":
character = vars(choice4)
elif character == "5":
character = vars(choice5)
elif character == "6":
print("Game Over")
else :
print('player error')
char_weight = character['weight']
char_player = character['player']
char_winphrase = character['winphrase']
char_losephrase = character['losephrase']
print("You Picked: " + char_player)
print("Opposed by.. " + npc_player)
def rpsls(char_weight, npc_weight, char_player, npc_player, char_winphrase, npc_winphrase, char_losephrase, npc_losephrase):
diff = (char_weight - npc_weight)%5
if diff == 0:
print ("It's a draw")
elif diff >=3:
if char_weight > npc_weight:
print (char_player, char_winphrase, npc_player)
elif char_weight == npc_weight:
print ("It's a draw")
else:
print (npc_player, npc_winphrase, char_player)
elif diff <=2:
if char_weight < npc_weight:
print (char_player, char_losephrase, npc_player)
elif char_weight == npc_weight:
print ("It's a draw")
else:
print (npc_player, npc_losephrase, char_player)
else:
print ('Something went wrong')
rpsls(char_weight, npc_weight, char_player, npc_player, char_winphrase, npc_winphrase, char_losephrase, npc_losephrase)
@Bendrog
Copy link

Bendrog commented Sep 3, 2021

How come when you get lizard and the CPU gets Rock, "The rock crushes the Lizard". And when you que Rock and CPU Lizard, "The Lizard eats the Rock" ?

Isn't it supposed to be just:

diff = char_weight - npc_weight
if diff ==0: "It is draw"
elif diff>0: "It is win"
else : "it is lost"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment