Advertisement
naisyrk

Untitled

Aug 30th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.50 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3.  
  4. class item:
  5.     def __init__(self):
  6.         self.name = ""
  7.         self.type = ""
  8.         self.image = ""
  9.         self.stats = [0] * 5
  10.  
  11. #class equipment:
  12. #    def __init__(self):
  13. #        self.status = False
  14. #        self.item = item()
  15.     #def take_off(self):
  16.  
  17. class character:
  18.     def __init__(self):
  19.         self.name = ""
  20.         self.stats = [0] * 5
  21.         self.weapon = item()
  22.         self.equipment = {
  23.             "helmet": blank,
  24.             "armor": blank
  25.             "weapon": blank
  26.         }
  27.         self.backpack = [blank, blank, blank, blank, blank]
  28.         self.available_points = 5
  29.  
  30.    # def add_stat(self, idx):
  31.         #if self.availablePoints >= 1:
  32.            # self.stats[idx] += 1
  33.            # self.availablePoints -= 1
  34.  
  35.  
  36.  
  37.  
  38. class Game:
  39.     def __init__(self, parent):
  40.         self.myParent = parent
  41.         self.myGame = tk.Frame(parent)
  42.         self.myGame.grid()
  43.  
  44.         self.statsFrame = tk.Frame(self.myGame)
  45.         self.statsFrame.grid()
  46.  
  47.         self.make_stat("Strength:", 0, 1, 1)
  48.         self.make_stat("Agility", 1, 1, 2)
  49.         self.make_stat("Intelligence", 2, 1, 3)
  50.         self.make_stat("Vitality", 3, 1, 4)
  51.  
  52.         self.make_equipment("helmet", 4, 5)
  53.         self.make_backpack(0, 5, 6)
  54.  
  55.     def make_stat(self, text, idx, column, row):
  56.         label = tk.Label(self.statsFrame, text=text)
  57.         label.grid(column=column, row=row)
  58.  
  59.         amount = tk.Label(self.statsFrame, text=my_character.stats[idx])
  60.         amount.grid(column=column+1, row=row)
  61.  
  62.         def add_stat():
  63.             if my_character.available_points >= 1:
  64.                 my_character.stats[idx] += 1
  65.                 my_character.available_points -= 1
  66.             else:
  67.                 pass
  68.             amount["text"] = my_character.stats[idx]
  69.  
  70.         button = tk.Button(self.statsFrame, text="+", command=add_stat)
  71.         button.grid(column=column+2, row=row)
  72.  
  73.     def make_equipment(self, item_type, column, row): #item-type = "helmet" etc
  74.  
  75.         def update():
  76.             button.update_idletasks()
  77.  
  78.         def take_off():
  79.             if my_character.equipment[item_type] != blank:
  80.                 if my_character.backpack[0] ==  blank:
  81.                     my_character.equipment[item_type], my_character.backpack[0] = my_character.backpack[0], my_character.equipment[item_type]
  82.                 elif my_character.backpack[1] == blank:
  83.                     my_character.equipment[item_type], my_character.backpack[1] = my_character.backpack[1], my_character.equipment[item_type]
  84.  
  85.  
  86.  
  87.         photo = tk.PhotoImage(file=my_character.equipment[item_type].image)
  88.         button = tk.Button(self.statsFrame, image=photo, command=take_off)
  89.         button.image = photo
  90.         button.grid(column=column, row=row)
  91.  
  92.     def make_backpack(self, slot, column, row):
  93.  
  94.         def take_on():
  95.             if my_character.backpack[slot] != blank:
  96.                 type = my_character.backpack[slot].type
  97.                 my_character.backpack[slot], my_character.equipment[type] = my_character.equipment[type], my_character.backpack[slot]
  98.             else:
  99.                 pass
  100.  
  101.  
  102.  
  103.         photo = tk.PhotoImage(file=my_character.backpack[slot].image)
  104.         button = tk.Button(self.statsFrame, image=photo, command=take_on)
  105.         button.image = photo
  106.         button.grid(column=column, row=row)
  107.  
  108.  
  109.  
  110.  
  111.  
  112. blank = item()
  113. blank.image = "avatar.png"
  114. my_character = character()
  115. my_character.backpack
  116.  
  117. root = tk.Tk()
  118. myapp = Game(root)
  119. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement