I decided to improve my OOP design knowledge and learn python at the same time so I started to write a simple program which will be a fight "simulator".
For now, there are only 2 character types : Orc and Human.
CharacterFactory class is created so that I'll be able to handle
Human classes in a more abstract way or so.
GameState is meant to track the state of the game. Instances will be immediately registered to the
GameState as soon as they created. And for example, if a character dies, I want to remove it from the list as well. (
#abtract factory or something class CharacterFactory: def __init__(self, character=None, game_state=None): self.character = character game_state.register_character(self) def inspect(self): print(self.character.name) print(self.character.attack_dmg) print(self.character.health) print("\n") def attack(self, target): target.character.health = target.character.health - self.character.attack_dmg #Observable or so class GameState: def __init__(self): self.characters =  def register_character(self, character): self.characters.append(character) def show_characters(self): list(map(lambda x: x.inspect(), self.characters)) class Orc: def __init__(self,name): self.name = name self.attack_dmg = 50 self.health = 100 class Human: def __init__(self,name): self.name = name self.attack_dmg = 45 self.health = 105 def Main(): game_state = GameState() orc = CharacterFactory(Orc("Karcsi"),game_state) #orc.inspect() #orc.attack() human = CharacterFactory(Human("Nojbejtoo"),game_state) #human.inspect() #human.attack() print("Game state:\n") game_state.show_characters() orc.attack(human) game_state.show_characters() Main()
My question is:
Is this a good design? Or maybe a complete pain in the ... to work with? Is there something that I could improve?
Of course this code is really far from being finished, but I try to find the best approach possible to design things like this so that i can deepen my knowledge in design patterns and stuff like that.