Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Cowboy():
- def __init__(self, name):
- self.name = name
- self.bullets = 0
- self.life = 1
- self.points = 0
- self.move = ""
- def setCurrentMove(self,move):
- if (move == "BLOCK" and self.move == "BLOCK") or \
- (move == "LOAD" and self.bullets >= 1) or \
- (move == "BANG" and self.bullets == 0):
- self.life = 0
- if move == "LOAD":
- self.bullets += 1
- self.move=move
- def fight(self, cowboy2):
- if self.life == 0 and cowboy2.life == 1:
- cowboy2.points += 1
- return 2
- elif self.life == 1 and cowboy2.life == 0:
- self.points += 1
- return 1
- elif self.life == 0 and cowboy2.life == 0:
- return 0
- if self.move == "BANG" and cowboy2.move == "LOAD":
- self.points += 1
- return 1
- elif cowboy2.move == "BANG" and self.move == "LOAD":
- cowboy2.points += 1
- return 2
- return 0
- def reset(self):
- self.life = 1
- self.bullets = 0
- self.move = ""
- def round(cowboy1,cowboy2):
- ruch1 = input("podaj ruch, Cowboyu1: ")
- ruch2 = input("podaj ruch, Cowboyu2: ")
- cowboy1.setCurrentMove(ruch1)
- cowboy2.setCurrentMove(ruch2)
- value = cowboy1.fight(cowboy2)
- if value == 1:
- print("Cowboy1 wygrał")
- cowboy1.reset()
- cowboy2.reset()
- if value == 2:
- print("Cowboy2 wygrał")
- cowboy1.reset()
- cowboy2.reset()
- if value == 0:
- print("Remis")
- print("punkty Cowboy1: "+ str(cowboy1.points) + " punkty Cowboy2: " + str(cowboy2.points))
- cowboy1 = Cowboy("ania")
- cowboy2 = Cowboy("kasia")
- maxPoints = int(input("Podaj po zdobyciu ilu punktów gracz wygrywa: "))
- while cowboy1.points < maxPoints and cowboy2.points < maxPoints:
- round(cowboy1,cowboy2)
- # else:
- # if cowboy1.points == maxPoints:
- # print("Cowboy1 wygrał grę!")
- # break
- # if cowboy2.points == maxPoints:
- # print("Cowboy2 wygrał grę")
- # break
- if cowboy1.points == maxPoints:
- print("Cowboy1 wygrał grę!")
- if cowboy2.points == maxPoints:
- print("Cowboy2 wygrał grę")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement