Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2. class Cowboy():
  3. def __init__(self, name):
  4. self.name = name
  5. self.bullets = 0
  6. self.life = 1
  7. self.points = 0
  8. self.move = ""
  9.  
  10. def setCurrentMove(self,move):
  11. if (move == "BLOCK" and self.move == "BLOCK") or \
  12. (move == "LOAD" and self.bullets >= 1) or \
  13. (move == "BANG" and self.bullets == 0):
  14. self.life = 0
  15.  
  16. if move == "LOAD":
  17. self.bullets += 1
  18.  
  19. self.move=move
  20.  
  21. def fight(self, cowboy2):
  22. if self.life == 0 and cowboy2.life == 1:
  23. cowboy2.points += 1
  24. return 2
  25. elif self.life == 1 and cowboy2.life == 0:
  26. self.points += 1
  27. return 1
  28. elif self.life == 0 and cowboy2.life == 0:
  29. return 0
  30.  
  31. if self.move == "BANG" and cowboy2.move == "LOAD":
  32. self.points += 1
  33. return 1
  34. elif cowboy2.move == "BANG" and self.move == "LOAD":
  35. cowboy2.points += 1
  36. return 2
  37.  
  38. return 0
  39.  
  40. def reset(self):
  41. self.life = 1
  42. self.bullets = 0
  43. self.move = ""
  44.  
  45.  
  46.  
  47. def round(cowboy1,cowboy2):
  48. ruch1 = input("podaj ruch, Cowboyu1: ")
  49. ruch2 = input("podaj ruch, Cowboyu2: ")
  50.  
  51.  
  52. cowboy1.setCurrentMove(ruch1)
  53. cowboy2.setCurrentMove(ruch2)
  54. value = cowboy1.fight(cowboy2)
  55. if value == 1:
  56. print("Cowboy1 wygrał")
  57. cowboy1.reset()
  58. cowboy2.reset()
  59. if value == 2:
  60. print("Cowboy2 wygrał")
  61. cowboy1.reset()
  62. cowboy2.reset()
  63. if value == 0:
  64. print("Remis")
  65. print("punkty Cowboy1: "+ str(cowboy1.points) + " punkty Cowboy2: " + str(cowboy2.points))
  66.  
  67. cowboy1 = Cowboy("ania")
  68. cowboy2 = Cowboy("kasia")
  69.  
  70. maxPoints = int(input("Podaj po zdobyciu ilu punktów gracz wygrywa: "))
  71. while cowboy1.points < maxPoints and cowboy2.points < maxPoints:
  72. round(cowboy1,cowboy2)
  73. # else:
  74. # if cowboy1.points == maxPoints:
  75. # print("Cowboy1 wygrał grę!")
  76. # break
  77. # if cowboy2.points == maxPoints:
  78. # print("Cowboy2 wygrał grę")
  79. # break
  80. if cowboy1.points == maxPoints:
  81. print("Cowboy1 wygrał grę!")
  82. if cowboy2.points == maxPoints:
  83. print("Cowboy2 wygrał grę")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement