A quick and passionate project about a battle simulation against a legendary pokemon trainer. You play as Jimmy who has caugt a level 1 Rattata. Now face to face against the almighty legendary pokemon trainer. Can you make sure Jimmy wins?
A C++ battle system implementing the several Programming patterns, while delivering the true OOP.
- State Pattern for turn management
- Modern C++ features (smart pointers, move semantics)
- Pimpl Idiom for implementation hiding
- Polymorphic Move System for dynamic battle effects
Core Components
| Component | Purpose | Key Features |
|---|---|---|
| Battle | Manages battle | flow State transitions, player/enemy access |
| BattleState (Base) | Interface for all states | Enter(), Execute(), HandleInput(), Exit() |
| PlayerTurnState | Handles player moves | Move selection UI, damage calculation |
| EnemyTurnState | AI-controlled | turns Random move selection, state transition |
| TurnState | Determine which Pokemon to take a turn | Takes into consideration if a move had a effect before combat |
| BattleOverState | End-game handling | Win/loss detection, battle summary |
🔹 State Pattern
- Encapsulates each battle phase (player turn, enemy turn, etc.)
- Clean separation of turn logic
- Easy to extend with new states (e.g., ItemUseState)
🔹 Strategy Pattern (Moves)
- MoveBase polymorphic interface
- Concrete moves (Thunderbolt, Psychic) override ApplyEffect()
🔹 Pimpl Idiom
- Hides Pokémon implementation details
- Reduces compilation dependencies
Lines 24 to 42 in b247eb0
Lines 50 to 51 in b247eb0
stateDiagram-v2
direction LR
[*] --> PlayerTurn: "Battle starts"
PlayerTurn --> EnemyTurn: "Move selected"
EnemyTurn --> TurnState: "Move selected"
state TurnState {
direction LR
[*] --> DecidingTurnOrder
DecidingTurnOrder --> PriorityCheck
PriorityCheck --> SpeedCheck: If equal
}
TurnState --> BattleOccurs
BattleOccurs --> PlayerTurn : "Everyone survives"
BattleOccurs --> BattleIsOver : "Someone fainted"
Lines 21 to 46 in b247eb0
Context: QuickAttack is a move that priorities to begin first in the turn order, regardless of speed. Endeavor is a move that forces the opponent's health to be the same as the user.
Lines 10 to 18 in b247eb0
Lines 14 to 27 in b247eb0