namespace BombsAwayGame;
///
/// Plays the Bombs Away game using a supplied .
///
public class Game
{
private readonly IUserInterface _ui;
///
/// Create game instance using the given UI.
///
/// UI to use for game.
public Game(IUserInterface ui)
{
_ui = ui;
}
///
/// Play game. Choose a side and play the side's logic.
///
public void Play()
{
_ui.Output("YOU ARE A PILOT IN A WORLD WAR II BOMBER.");
Side side = ChooseSide();
side.Play();
}
///
/// Represents a .
///
/// Name of side.
/// Create instance of side that this descriptor represents.
private record class SideDescriptor(string Name, Func CreateSide);
///
/// Choose side and return a new instance of that side.
///
/// New instance of side that was chosen.
private Side ChooseSide()
{
SideDescriptor[] sides = AllSideDescriptors;
string[] sideNames = sides.Select(a => a.Name).ToArray();
int index = _ui.Choose("WHAT SIDE", sideNames);
return sides[index].CreateSide();
}
///
/// All side descriptors.
///
private SideDescriptor[] AllSideDescriptors => new SideDescriptor[]
{
new("ITALY", () => new ItalySide(_ui)),
new("ALLIES", () => new AlliesSide(_ui)),
new("JAPAN", () => new JapanSide(_ui)),
new("GERMANY", () => new GermanySide(_ui)),
};
}