Aug-30-2018, 06:35 PM
Hello, I want to make simple game with equipment system, shop and fights.
All will play around our character. If you want to be stronger, level up and try to buy better items, which will give you better stats.
I have one problem that I didn't expected. I have used first time __init__ ... Here is my code (full is here: https://pastebin.com/uXTgqcYC):
But first question is: Should I make method (like add_stat) inside character or it won't matter anyway?(I made function for adding stats inside button)
Second: I don't know how to acces things made this method (for example:
and I don't know how to acces it and
it
Third: Is there easier way to make equipment system? I have used here dicts and lists for eq and backpack.
It's my second attemp to made it. Please help me.
All will play around our character. If you want to be stronger, level up and try to buy better items, which will give you better stats.
I have one problem that I didn't expected. I have used first time __init__ ... Here is my code (full is here: https://pastebin.com/uXTgqcYC):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
class item: def __init__( self ): self .name = "" self . type = "" self .image = "" self .stats = [ 0 ] * 5 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 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) |
But first question is: Should I make method (like add_stat) inside character or it won't matter anyway?(I made function for adding stats inside button)
Second: I don't know how to acces things made this method (for example:
1 |
self .make_equipment( "helmet" , 4 , 5 ) |
1 |
update_idletasks() |
Third: Is there easier way to make equipment system? I have used here dicts and lists for eq and backpack.
It's my second attemp to made it. Please help me.