/JTacticalSim.Component/Battle/Round.cs
https://github.com/Queztionmark/JTacticalSim · C# · 87 lines · 57 code · 15 blank · 15 comment · 8 complexity · a3ab94aba84351b62b7525690fd52b5c MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Configuration;
- using System.Text;
- using System.Threading.Tasks;
- using JTacticalSim.API;
- using JTacticalSim.API.Component;
-
- namespace JTacticalSim.Component.Battle
- {
- /// <summary>
- /// Represents a full round of battle
- /// </summary>
- public class Round : GameComponentBase, IRound
- {
- public event BattleRoundStart RoundStart;
- public event BattleRoundEnd RoundEnd;
- public event BattleSkirmishStart SkirmishStart;
- public event BattleSkirmishEnd SkirmishEnd;
-
- public ISkirmish CurrentSkirmish { get; private set; }
- private IBattle _battle { get; set; }
- public List<ISkirmish> Skirmishes { get; private set; }
-
- public Round(IBattle battle)
- {
- _battle = battle;
- Skirmishes = new List<ISkirmish>();
- }
-
- public void AddSkirmish(ISkirmish skirmish)
- {
- Skirmishes.Add(skirmish);
- skirmish.SkirmishEnd += SkirmishEnded;
- skirmish.SkirmishStart += SkirmishStarted;
- }
-
- public IEnumerable<IUnit> GetDefeatedUnits() { return Skirmishes.SelectMany(s => s.Destroyed); }
-
- public void DoBattle()
- {
- On_RoundStart(new EventArgs());
- Skirmishes.ForEach(s => s.DoBattle());
- On_RoundEnd(new EventArgs());
- }
-
- // Event Handlers
-
- public void On_RoundStart(EventArgs e)
- {
- if (RoundStart != null) RoundStart(this, e);
- }
-
- public void On_RoundEnd(EventArgs e)
- {
- if (RoundEnd != null) RoundEnd(this, e);
- }
-
-
-
- /// <summary>
- /// Pass up the skirmish so we can act at the UI level
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void SkirmishEnded(object sender, EventArgs e)
- {
- CurrentSkirmish = null;
-
- if (SkirmishEnd != null) SkirmishEnd(this, e);
- }
-
- /// <summary>
- /// Pass up the skirmish so we can act at the UI level
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void SkirmishStarted(object sender, EventArgs e)
- {
- // Set the current skirmish
- CurrentSkirmish = ((ISkirmish)sender);
-
- if (SkirmishStart != null) SkirmishStart(this, e);
- }
- }
- }