Please help I'm a beginner - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: Please help I'm a beginner (/thread-34836.html) |
Please help I'm a beginner - Nabi666 - Sep-05-2021 Sorry for possible language mistakes, I'm french I started programmation for a year but i don't remember anything about it, i'm a total beginner an i want to learn but i don't understand what's wrong with my program, can you help me please. (I tried to share my project but i'm not sure it works) RE: Please help I'm a beginner - Windspar - Sep-07-2021 Learn classes now. Start with them as simple containers. They will make your life so much easier. Classes are reference. So you never need to use global. Examples class Character: def __init__(self, max_life, attack, defense, shield): self.max_life = max_life self.life = max_life self.attack = attack self.defense = defense self.shield = shield self.alive = True player = Character(50, 3, 3, 3) for k, v in vars(player).items(): print(k, v) class Weapon: def __init__(self, name, attack): self.name = name self.attack = attack # Represent class as string instead object memory. def __repr__(self): return str(vars(self)) + '\n' class Weapons: def __init__(self): self.dagger = Weapon('Daque', 3) self.sword = Weapon('Epee', 6) self.bow = Weapon('Arc', 5) weapons = Weapons() def main(): print(vars(weapons)) print(weapons.sword) weapons.sword.attack += 1 print(weapons.sword) main() |