Extension Project: Simple Game

This is a late-track extension project. The core goal is to build a battle-game foundation using abstract classes, inheritance, and polymorphism. A ready-made Singleton config is included as an optional extra idea, not the main task.

Core Design

         Character (ABC)
        /           \
     Hero          Enemy
  (override)    (override)
  attack()       attack()

  GameConfig (optional Singleton extension)

Core OOP Ideas

  • Abstraction: Character(ABC) enforces attack()
  • Polymorphism: same attack() call, different output per subclass
  • Inheritance: Hero and Enemy both extend Character
  • Encapsulation: take_damage protects hp from going below 0

Optional Extension: GameConfig

GameConfig is already provided as a Singleton so this project does not overload the core task. If you want an extra challenge, add more settings such as max rounds, enemy spawn rate, or starting difficulty.

Hints

  • take_damage: self.hp = max(0, self.hp - amount)
  • is_alive: return self.hp > 0
  • __str__: return something like f"Hero({self.name}, HP: {self.hp}"
  • Focus on the three classes with pass stubs first — that is what the check validates

Your Task

Implement all pass stubs in Character, Hero, and Enemy. Once the core works, you can extend the game with extra characters, a combat loop, a win condition, or more settings in GameConfig.

Section 1/5Core Design

Core Design

Explore this concept

Extension Project: Simple Game

This is a late-track extension project. The core goal is to build a battle-game foundation using abstract classes, inheritance, and polymorphism. A ready-made Singleton config is included as an optional extra idea, not the main task.

Core Design

         Character (ABC)
        /           \
     Hero          Enemy
  (override)    (override)
  attack()       attack()

  GameConfig (optional Singleton extension)

Output:

Click "Check" to run your code.