Design an object-oriented model and implement the core battle logic for a turn-based fight between two teams of monsters. The system should simulate the battle and produce a detailed, chronological battle log, as well as the final result.
There are two teams: Team A and Team B.
Each team has an ordered list of monsters.
Each Monster has the following attributes:
name
: string
health
: positive integer (HP)
attack
: positive integer (attack power)
The battle continues until at least one team has no living monsters.
For each team, the active monster is defined as:
health > 0
.
health > 0
, that team immediately loses (unless this happens to both teams in the same round, see draw rule below).
The battle proceeds in rounds. Each round follows this exact sequence:
defender.health -= attacker.attack
.
<= 0
, that monster dies.
defender.health -= attacker.attack
.
<= 0
, that monster dies.
Death and replacement:
health <= 0
, it is considered dead and removed from battle.
health > 0
becomes the new active monster (if any).
You must generate a battle log in strict chronological order. The log should include at least:
attack
).
HP_before -> HP_after
.
"Team A wins"
"Team B wins"
"Draw"
You may choose the exact log format (e.g., a list of strings or structured records), but it must be sufficient to reconstruct the full sequence of events.
Use good object-oriented design. Do not put all logic into a single class or function. At minimum, design the following classes (you may add more helper classes if needed):
Monster
name
,
health
,
attack
and exposes any behavior needed (e.g., takeDamage, isAlive).
Team
Monster
instances.
BattleEngine
Team
instances.
BattleResult
winner
: one of
"Team A"
,
"Team B"
, or
"Draw"
.
log
: the ordered battle log.
Task:
Design and implement these classes and the core battle logic so that, given two teams of monsters as input, you can run the battle with BattleEngine and obtain a BattleResult containing the winner and the full battle log.