namespace BombsAwayGame;
///
/// Represents a protagonist in the game.
///
internal abstract class Side
{
///
/// Create instance using the given UI.
///
/// UI to use.
public Side(IUserInterface ui)
{
UI = ui;
}
///
/// Play this side.
///
public abstract void Play();
///
/// User interface supplied to ctor.
///
protected IUserInterface UI { get; }
///
/// Random-number generator for this play-through.
///
private readonly Random _random = new();
///
/// Gets a random floating-point number greater than or equal to zero, and less than one.
///
/// Random floating-point number greater than or equal to zero, and less than one.
protected double RandomFrac() => _random.NextDouble();
///
/// Gets a random integer in a range.
///
/// The inclusive lower bound of the number returned.
/// The exclusive upper bound of the number returned.
/// Random integer in a range.
protected int RandomInteger(int minValue, int maxValue) => _random.Next(minValue: minValue, maxValue: maxValue);
///
/// Display messages indicating the mission succeeded.
///
protected void MissionSucceeded()
{
UI.Output("DIRECT HIT!!!! " + RandomInteger(0, 100) + " KILLED.");
UI.Output("MISSION SUCCESSFUL.");
}
///
/// Gets the Guns type of enemy artillery.
///
protected EnemyArtillery Guns { get; } = new("GUNS", 0);
///
/// Gets the Missiles type of enemy artillery.
///
protected EnemyArtillery Missiles { get; } = new("MISSILES", 35);
///
/// Gets the Both Guns and Missiles type of enemy artillery.
///
protected EnemyArtillery Both { get; } = new("BOTH", 35);
///
/// Perform enemy counterattack using the given artillery and hit rate percent.
///
/// Enemy artillery to use.
/// Hit rate percent for enemy.
protected void EnemyCounterattack(EnemyArtillery artillery, int hitRatePercent)
{
if (hitRatePercent + artillery.Accuracy > RandomInteger(0, 100))
{
MissionFailed();
}
else
{
UI.Output("YOU MADE IT THROUGH TREMENDOUS FLAK!!");
}
}
///
/// Display messages indicating the mission failed.
///
protected void MissionFailed()
{
UI.Output("* * * * BOOM * * * *");
UI.Output("YOU HAVE BEEN SHOT DOWN.....");
UI.Output("DEARLY BELOVED, WE ARE GATHERED HERE TODAY TO PAY OUR");
UI.Output("LAST TRIBUTE...");
}
}