Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added rock-paper-scissor-0.py
Empty file.
58 changes: 58 additions & 0 deletions rock-paper-scissor-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import ClassVar


class Participant:
def __init__(self, name):
self.name = name
self.points = 0
self.choice = ""
def choose(self):
self.choice = input("{name}, select rock, paper or scissor: ".format(name= self.name))
print("{name} selects {choice}".format(name=self.name, choice = self.choice))
def toNumericalChoice(self):
switcher = {
"rock": 0,
"paper": 1,
"scissor": 2
}
return switcher[self.choice]

class GameRound:
def __init__(self, p1, p2):
self.rules = [
[0, -1, 1],
[1, 0, -1],
[-1, 1, 0]
]

p1.choose()
p2.choose()
result = self.compareChoices(p1,p2)
print("Round resulted in a {result}".format(result = self.getResultAsString(result) ))
def compareChoices(self, p1, p2):
return self.rules[p1.toNumericalChoice()][p2.toNumericalChoice()]
def awardPoints(self):
print("implement")
def getResultAsString(self, result):
res = {
0: "draw",
1: "win",
-1: "loss"
}
return res[result]

class Game:
def __init__(self):
self.endGame = False
self.participant = Participant("Spock")
self.secondParticipant = Participant("Kirk")
def start(self):
game_round = GameRound(self.participant, self.secondParticipant)

def checkEndCondition(self):
print("implement")
def determineWinner(self):
print("implement")

game = Game()
game.start()
65 changes: 65 additions & 0 deletions rock-paper-scissor-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import ClassVar


class Participant:
def __init__(self, name):
self.name = name
self.points = 0
self.choice = ""
def choose(self):
self.choice = input("{name}, select rock, paper or scissor: ".format(name= self.name))
print("{name} selects {choice}".format(name=self.name, choice = self.choice))
def toNumericalChoice(self):
switcher = {
"rock": 0,
"paper": 1,
"scissor": 2
}
return switcher[self.choice]
def incrementPoint(self):
self.points += 1

class GameRound:
def __init__(self, p1, p2):
self.rules = [
[0, -1, 1],
[1, 0, -1],
[-1, 1, 0]
]

p1.choose()
p2.choose()
result = self.compareChoices(p1,p2)
print("Round resulted in a {result}".format(result = self.getResultAsString(result) ))
if result > 0:
p1.incrementPoint()
elif result < 0:
p2.incrementPoint()

def compareChoices(self, p1, p2):
return self.rules[p1.toNumericalChoice()][p2.toNumericalChoice()]
def awardPoints(self):
print("implement")
def getResultAsString(self, result):
res = {
0: "draw",
1: "win",
-1: "loss"
}
return res[result]

class Game:
def __init__(self):
self.endGame = False
self.participant = Participant("Spock")
self.secondParticipant = Participant("Kirk")
def start(self):
game_round = GameRound(self.participant, self.secondParticipant)

def checkEndCondition(self):
print("implement")
def determineWinner(self):
print("implement")

game = Game()
game.start()
82 changes: 82 additions & 0 deletions rock-paper-scissor-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from typing import ClassVar


class Participant:
def __init__(self, name):
self.name = name
self.points = 0
self.choice = ""
def choose(self):
self.choice = input("{name}, select rock, paper or scissor: ".format(name= self.name))
print("{name} selects {choice}".format(name=self.name, choice = self.choice))
def toNumericalChoice(self):
switcher = {
"rock": 0,
"paper": 1,
"scissor": 2
}
return switcher[self.choice]
def incrementPoint(self):
self.points += 1

class GameRound:
def __init__(self, p1, p2):
self.rules = [
[0, -1, 1],
[1, 0, -1],
[-1, 1, 0]
]

p1.choose()
p2.choose()
result = self.compareChoices(p1,p2)
print("Round resulted in a {result}".format(result = self.getResultAsString(result) ))
if result > 0:
p1.incrementPoint()
elif result < 0:
p2.incrementPoint()
else:
print("No points for anybody")

def compareChoices(self, p1, p2):
return self.rules[p1.toNumericalChoice()][p2.toNumericalChoice()]
def awardPoints(self):
print("implement")
def getResultAsString(self, result):
res = {
0: "draw",
1: "win",
-1: "loss"
}
return res[result]

class Game:
def __init__(self):
self.endGame = False
self.participant = Participant("Spock")
self.secondParticipant = Participant("Kirk")
def start(self):
while not self.endGame:
GameRound(self.participant, self.secondParticipant)
self.checkEndCondition()

def checkEndCondition(self):
answer = input("Continue game y/n: ")
if answer == 'y':
GameRound(self.participant, self.secondParticipant)
self.checkEndCondition()
else:
print("Game ended, {p1name} has {p1points}, and {p2name} has {p2points}".format(p1name = self.participant.name, p1points= self.participant.points, p2name=self.secondParticipant.name, p2points=self.secondParticipant.points))
self.determineWinner()
self.endGame = True
def determineWinner(self):
resultString = "It's a Draw"
if self.participant.points > self.secondParticipant.points:
resultString = "Winner is {name}".format(name=self.participant.name)
elif self.participant.points < self.secondParticipant.points:
resultString = "Winner is {name}".format(name=self.secondParticipant.name)

print(resultString)

game = Game()
game.start()
86 changes: 86 additions & 0 deletions rock-paper-scissor-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from typing import ClassVar


class Participant:
def __init__(self, name):
self.name = name
self.points = 0
self.choice = ""
def choose(self):
self.choice = input("{name}, select rock, paper, scissor, lizard or spock: ".format(name= self.name))
print("{name} selects {choice}".format(name=self.name, choice = self.choice))
def toNumericalChoice(self):
switcher = {
"rock": 0,
"paper": 1,
"scissor": 2,
"lizard": 3,
"spock": 4
}
return switcher[self.choice]
def incrementPoint(self):
self.points += 1

class GameRound:
def __init__(self, p1, p2):
self.rules = [
[0, -1, 1, 1, -1],
[1, 0, -1, -1, 1],
[-1, 1, 0, 1, -1],
[-1, 1, -1, 0, 1],
[1, -1, 1, -1, 0]
]

p1.choose()
p2.choose()
result = self.compareChoices(p1,p2)
print("Round resulted in a {result}".format(result = self.getResultAsString(result) ))
if result > 0:
p1.incrementPoint()
elif result < 0:
p2.incrementPoint()
else:
print("No points for anybody")

def compareChoices(self, p1, p2):
return self.rules[p1.toNumericalChoice()][p2.toNumericalChoice()]
def awardPoints(self):
print("implement")
def getResultAsString(self, result):
res = {
0: "draw",
1: "win",
-1: "loss"
}
return res[result]

class Game:
def __init__(self):
self.endGame = False
self.participant = Participant("Spock")
self.secondParticipant = Participant("Kirk")
def start(self):
while not self.endGame:
GameRound(self.participant, self.secondParticipant)
self.checkEndCondition()

def checkEndCondition(self):
answer = input("Continue game y/n: ")
if answer == 'y':
GameRound(self.participant, self.secondParticipant)
self.checkEndCondition()
else:
print("Game ended, {p1name} has {p1points}, and {p2name} has {p2points}".format(p1name = self.participant.name, p1points= self.participant.points, p2name=self.secondParticipant.name, p2points=self.secondParticipant.points))
self.determineWinner()
self.endGame = True
def determineWinner(self):
resultString = "It's a Draw"
if self.participant.points > self.secondParticipant.points:
resultString = "Winner is {name}".format(name=self.participant.name)
elif self.participant.points < self.secondParticipant.points:
resultString = "Winner is {name}".format(name=self.secondParticipant.name)

print(resultString)

game = Game()
game.start()