using System; namespace Game { /// /// Represents the current state of the war. /// public abstract class WarState { /// /// Gets the computer's armed forces. /// public ArmedForces ComputerForces { get; } /// /// Gets the player's armed forces. /// public ArmedForces PlayerForces { get; } /// /// Gets a flag indicating whether this state represents absolute /// victory for the player. /// public virtual bool IsAbsoluteVictory => false; /// /// Gets the final outcome of the war. /// /// /// If the war is ongoing, this property will be null. /// public virtual WarResult? FinalOutcome => null; /// /// Initializes a new instance of the state class. /// /// /// The computer's forces. /// /// /// The player's forces. /// public WarState(ArmedForces computerForces, ArmedForces playerForces) => (ComputerForces, PlayerForces) = (computerForces, playerForces); /// /// Launches an attack. /// /// /// The branch of the military to use for the attack. /// /// /// The number of men and women to use for the attack. /// /// /// The new state of the game resulting from the attack and a message /// describing the result. /// public (WarState nextState, string message) LaunchAttack(MilitaryBranch branch, int attackSize) => branch switch { MilitaryBranch.Army => AttackWithArmy(attackSize), MilitaryBranch.Navy => AttackWithNavy(attackSize), MilitaryBranch.AirForce => AttackWithAirForce(attackSize), _ => throw new ArgumentException("INVALID BRANCH") }; /// /// Conducts an attack with the player's army. /// /// /// The number of men and women used in the attack. /// /// /// The new game state and a message describing the result. /// protected abstract (WarState nextState, string message) AttackWithArmy(int attackSize); /// /// Conducts an attack with the player's navy. /// /// /// The number of men and women used in the attack. /// /// /// The new game state and a message describing the result. /// protected abstract (WarState nextState, string message) AttackWithNavy(int attackSize); /// /// Conducts an attack with the player's air force. /// /// /// The number of men and women used in the attack. /// /// /// The new game state and a message describing the result. /// protected abstract (WarState nextState, string message) AttackWithAirForce(int attackSize); } }