Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class item:
- def __init__(self):
- self.name = ""
- self.type = ""
- self.image = ""
- self.stats = [0] * 5
- #class equipment:
- # def __init__(self):
- # self.status = False
- # self.item = item()
- #def take_off(self):
- class character:
- def __init__(self):
- self.name = ""
- self.stats = [0] * 5
- self.weapon = item()
- self.equipment = {
- "helmet": blank,
- "armor": blank
- "weapon": blank
- }
- self.backpack = [blank, blank, blank, blank, blank]
- self.available_points = 5
- # def add_stat(self, idx):
- #if self.availablePoints >= 1:
- # self.stats[idx] += 1
- # self.availablePoints -= 1
- class Game:
- def __init__(self, parent):
- self.myParent = parent
- self.myGame = tk.Frame(parent)
- self.myGame.grid()
- self.statsFrame = tk.Frame(self.myGame)
- self.statsFrame.grid()
- self.make_stat("Strength:", 0, 1, 1)
- self.make_stat("Agility", 1, 1, 2)
- self.make_stat("Intelligence", 2, 1, 3)
- self.make_stat("Vitality", 3, 1, 4)
- self.make_equipment("helmet", 4, 5)
- self.make_backpack(0, 5, 6)
- def make_stat(self, text, idx, column, row):
- label = tk.Label(self.statsFrame, text=text)
- label.grid(column=column, row=row)
- amount = tk.Label(self.statsFrame, text=my_character.stats[idx])
- amount.grid(column=column+1, row=row)
- def add_stat():
- if my_character.available_points >= 1:
- my_character.stats[idx] += 1
- my_character.available_points -= 1
- else:
- pass
- amount["text"] = my_character.stats[idx]
- button = tk.Button(self.statsFrame, text="+", command=add_stat)
- button.grid(column=column+2, row=row)
- def make_equipment(self, item_type, column, row): #item-type = "helmet" etc
- def update():
- button.update_idletasks()
- def take_off():
- if my_character.equipment[item_type] != blank:
- if my_character.backpack[0] == blank:
- my_character.equipment[item_type], my_character.backpack[0] = my_character.backpack[0], my_character.equipment[item_type]
- elif my_character.backpack[1] == blank:
- my_character.equipment[item_type], my_character.backpack[1] = my_character.backpack[1], my_character.equipment[item_type]
- photo = tk.PhotoImage(file=my_character.equipment[item_type].image)
- button = tk.Button(self.statsFrame, image=photo, command=take_off)
- button.image = photo
- button.grid(column=column, row=row)
- def make_backpack(self, slot, column, row):
- def take_on():
- if my_character.backpack[slot] != blank:
- type = my_character.backpack[slot].type
- my_character.backpack[slot], my_character.equipment[type] = my_character.equipment[type], my_character.backpack[slot]
- else:
- pass
- photo = tk.PhotoImage(file=my_character.backpack[slot].image)
- button = tk.Button(self.statsFrame, image=photo, command=take_on)
- button.image = photo
- button.grid(column=column, row=row)
- blank = item()
- blank.image = "avatar.png"
- my_character = character()
- my_character.backpack
- root = tk.Tk()
- myapp = Game(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement