Advertisement
Guest User

Untitled

a guest
Apr 30th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 KB | None | 0 0
  1. from Tkinter import *
  2. from random import randint
  3.  
  4. class Fighter(object):
  5. def __init__(self, name, avatar):
  6. #every charachter has health bar
  7. #moves
  8. #name
  9. #avatar img
  10. self.name = name
  11. self.avatar = avatar
  12. self.health = None
  13. self.moves = {}
  14. self.inventory = []
  15.  
  16. #decorators
  17. @property
  18. def name(self):
  19. return self._name
  20.  
  21. @name.setter
  22. def name(self, value):
  23. self._name = value
  24.  
  25. @property
  26. def avatar(self):
  27. return self._avatar
  28.  
  29. @avatar.setter
  30. def avatar(self,value):
  31. self._avatar = value
  32.  
  33. @property
  34. def health(self):
  35. return self._health
  36.  
  37. @health.setter
  38. def health(self,value):
  39. self._health = value
  40.  
  41. @property
  42. def moves(self):
  43. return self._moves
  44.  
  45. @moves.setter
  46. def moves(self,value):
  47. self._moves = value
  48.  
  49. @property
  50. def inventory(self):
  51. return self._inventory
  52.  
  53. @inventory.setter
  54. def inventory(self,value):
  55. self._inventory = value
  56.  
  57. def setHealth(self, health):
  58. self._health = health
  59.  
  60. #base attack function
  61. def attack(self):
  62. self._health -= 10
  63.  
  64. #potion adds 10 hp
  65. def potion(self):
  66. if potion == True:
  67. self._health += 10
  68.  
  69. #key = move/ value= health
  70. def addMove(self, move, dmg):
  71. self._moves[move] = dmg
  72.  
  73. #add item to the inventory
  74. def addDrop(self, items):
  75. self.items = ["sword", "gun", "healthkit"]
  76. self.inventory.append(items[randint(0, len(items))])
  77.  
  78. def __str__(self, enemy):
  79. s = "{} vs {}\n\n".format(self.name, enemy.name)
  80.  
  81. s += "Your move set: "
  82. for move in self.moves.keys():
  83. s += move + " - "
  84. s += "\n\n"
  85.  
  86. s += "Current health: {}\n\n".format(self.health)
  87.  
  88. s += "Enemy health: {}\n\n".format(enemy.health)
  89.  
  90. return s
  91.  
  92. ##########################################################################################################
  93. #the GUI and main gameplay mechanics
  94. class Main(Frame):
  95. def __init__(self, parent):
  96. Frame.__init__(self, parent)
  97.  
  98. #layout of the main menu
  99. self.title = Label(parent, text="Welcome to Fighthon!", font=("Comic Sans", 30, "bold"), pady=40, bg="white", fg="black")
  100. self.title.pack()
  101.  
  102. #starts the game
  103. self.start = Button(parent, text="Start Game", command=self.start, pady=20, width=60)
  104. self.start.pack()
  105.  
  106. #exits the game
  107. self.exit = Button(parent, text="Exit", command=exit, pady=2, width=10)
  108. self.exit.pack(side=BOTTOM)
  109.  
  110. #enemy function who you will fight
  111. def enemy(self):
  112. pass
  113.  
  114. #starts the game, changing the window
  115. #the gameplay window
  116. def start(self):
  117. global window
  118. menu.destroy()
  119. window = Tk()
  120. window.title("Fighthon - Now Playing")
  121. window.configure(background = "white", cursor = "arrow")
  122. window.attributes("-fullscreen", True)
  123.  
  124. #blank space followed by choose your fighter text
  125. self.blank = Label(window, text="", pady=50, bg="white")
  126. self.blank.pack()
  127.  
  128. self.choice = Label(window, text="CHOOSE YOUR FIGHTER", font=("Comic Sans", 45, "bold", "italic"), pady=75, bg="white", fg="black")
  129. self.choice.pack()
  130.  
  131. #choose your fighter buttons: gunsmith, magician, brawler, or demolitionist
  132. self.gunsmith = Button(window, text="Gunsmith", command=self.chooseGunsmith, pady=25, width=60)
  133. self.gunsmith.pack()
  134.  
  135. self.magician = Button(window, text="Magician", command=self.chooseMagician, pady=25, width=60)
  136. self.magician.pack()
  137.  
  138. self.brawler = Button(window, text="Brawler", command=self.chooseBrawler, pady=25, width=60)
  139. self.brawler.pack()
  140.  
  141. self.demo = Button(window, text="Demolitionist", command=self.chooseDemo, pady=25, width=60)
  142. self.demo.pack()
  143.  
  144. #exits the game
  145. self.exit = Button(window, text="Exit", command=exit, pady=2, width=10)
  146. self.exit.pack(side=BOTTOM)
  147.  
  148. window.mainloop()
  149.  
  150. def fightWindow(self):
  151. global window
  152. window.destroy()
  153. fight = Tk()
  154. fight.title("Fighthon - In Game")
  155. fight.configure(background = "white")
  156. fight.attributes("-fullscreen", True)
  157.  
  158. self.exit = Button(fight, text="Exit", command=exit, pady=2, width=10)
  159. self.exit.pack(side=BOTTOM)
  160.  
  161. img = PhotoImage(file ="gunsmith.gif")
  162. imgScreen = Label(fight, image=img)
  163. imgScreen.pack(side=BOTTOM)
  164. imgScreen.pack_propagate(False)
  165.  
  166. buttonPanel = Frame(fight)
  167. buttonPanel.pack(side=LEFT)
  168.  
  169. attackButton = Button(buttonPanel, text="Attack", command=Fighter.attack, pady=25, width=50)
  170. attackButton.pack()
  171.  
  172. potionButton = Button(buttonPanel, text="Potion", command=Fighter.potion, pady=25, width=50)
  173. potionButton.pack()
  174.  
  175. statPanel = Frame(fight)
  176. statPanel.pack(side=RIGHT)
  177.  
  178. statsList = Text(statPanel, bg="white")
  179. statsList.pack()
  180. statsList.insert(END, str(self.character))
  181. statsList.config(state=DISABLED)
  182.  
  183. fight.mainloop()
  184.  
  185. #button commands
  186. #choose gunsmith
  187. def chooseGunsmith(self):
  188. c1 = Fighter("Gunsmith" , "gunsmith.gif")
  189.  
  190. Main.character = c1
  191.  
  192. #Gunsmith stats
  193. c1.setHealth(50)
  194. c1.addMove("Buckshot" , 25)
  195. c1.addMove("Pistol Whip" , 50)
  196.  
  197. self.fightWindow()
  198. self.enemy()
  199.  
  200. #choose magician
  201. def chooseMagician(self):
  202. c2 = Fighter("Magician" , "magician.gif")
  203.  
  204. Main.character = c2
  205.  
  206. #Magician stats
  207. c2.setHealth(75)
  208. c2.addMove("Ace of Spades", 20)
  209.  
  210. self.fightWindow()
  211.  
  212. #choose brawler
  213. def chooseBrawler(self):
  214. c3 = Fighter("Brawler" , "brawler.gif")
  215.  
  216. #Brawler stats
  217. c3.setHealth(100)
  218. c3.addMove("Flying Knee", 30)
  219.  
  220. self.fightWindow()
  221.  
  222. #choose demolitionist
  223. def chooseDemo(self):
  224. c4 = Fighter("Demolitionist", "demo.gif")
  225.  
  226. #Demolitionist stats
  227. c4.setHealth(150)
  228. c4.addMove("Shell Shock", 20) #20 damage but -15 health to self
  229.  
  230. self.fightWindow()
  231.  
  232.  
  233. #########################################################################
  234. # create the window
  235. menu = Tk()
  236. menu.title("Fighthon")
  237. menu.geometry("800x500")
  238. menu.configure(background="white", cursor="arrow")
  239.  
  240. # create the GUI as a Tkinter canvas inside the window
  241. g = Main(menu)
  242.  
  243. # wait for the window to close
  244. menu.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement