Advertisement
pankovamg

Pokemon

Sep 26th, 2022
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. from tkinter import *
  2.  
  3.  
  4. class Pokemon:
  5.     def __init__(self, nm, atak=5, damf=5):
  6.         self.hp = 100
  7.         self.name = nm
  8.         self.atk = atak
  9.         self.df = damf
  10.         self.x = 100
  11.         self.y = 100
  12.  
  13.     def attack(self, other):
  14.         if self.hp == 0 or other.hp == 0:
  15.             return
  16.         else:
  17.             damage = self.atk - other.df
  18.             if damage > 0:
  19.                 if self.type == 'water' and other.type == 'fire':
  20.                     other.hp -= 3 * damage
  21.                 elif self.type == 'grass' and other.type == 'fire':
  22.                     other.hp -= damage
  23.                     other.df /= 2
  24.                 elif self.type == 'electric' and other.type == 'water':
  25.                     other.hp -= damage
  26.                     other.df = 0
  27.                 else:
  28.                     other.hp -= damage
  29.             else:
  30.                 other.hp -= 1
  31.  
  32.  
  33.  
  34.     def get_name(self):
  35.         return self.name
  36.  
  37.     def get_hp(self):
  38.         return self.hp
  39.  
  40.     def get_atk(self):
  41.         return self.atk
  42.  
  43.     def get_df(self):
  44.         return self.df
  45.  
  46.  
  47. class WaterPokemon(Pokemon):
  48.     type = 'water'
  49.  
  50.     def __init__(self, nm, atak, damf):
  51.         super().__init__(nm, atak, damf)
  52.         self.x = 100
  53.         self.y = 100
  54.         self.kind = PhotoImage(file="1.png")
  55.         self.ob = Label(root, image=self.kind)
  56.  
  57. class FirePokemon(Pokemon):
  58.     type = 'fire'
  59.  
  60.     def __init__(self, nm, atak, damf):
  61.         super().__init__(nm, atak, damf)
  62.         self.x = 150
  63.         self.y = 150
  64.         self.kind = PhotoImage(file="2.png")
  65.         self.ob = Label(root, image=self.kind)
  66.  
  67. class GrassPokemon(Pokemon):
  68.     type = 'grass'
  69.  
  70.     def __init__(self, nm, atak, damf):
  71.         super().__init__(nm, atak, damf)
  72.         self.x = 100
  73.         self.y = 100
  74.         self.kind = PhotoImage(file="1.png")
  75.         self.ob = Label(root, image=self.kind)
  76.  
  77. class ElectricPokemon(Pokemon):
  78.  
  79.     def __init__(self, atak, damf):
  80.         super().__init__(atak, damf)
  81.         self.x = 100
  82.         self.y = 100
  83.         self.kind = PhotoImage(file="1.png")
  84.         self.ob = Label(root, image=self.kind)
  85.         self.type = 'electric'
  86.  
  87.  
  88. root = Tk()
  89. root.geometry('800x600+200+100')
  90.  
  91. pikachu = WaterPokemon('Pikachu', 35, 60)
  92. pikachu.ob.place(x=100, y= 100)
  93.  
  94. kop = FirePokemon('KopKop', 35, 60)
  95. kop.ob.place(x=300, y= 100)
  96.  
  97.  
  98. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement