public void SetUpBoard() { var ships = new Dictionary <ShipType, int>() { { ShipType.Destroyer, 2 }, { ShipType.Cruiser, 3 }, { ShipType.Submarine, 3 }, { ShipType.Battleship, 4 }, { ShipType.Carrier, 5 } }; foreach (KeyValuePair <ShipType, int> vessel in ships) { ShipPlacement response; do { Console.Clear(); ConsoleOutput.DisplayBoard(this, false); ConsoleOutput.DisplayPlacementMessage(this, vessel.Key, vessel.Value); PlaceShipRequest request = GetPlaceShipRequest(vessel.Key); response = Board.PlaceShip(request); Console.Clear(); ConsoleOutput.DisplayBoard(this, false); ConsoleOutput.DisplayShipResponse(request, response); ConsoleInput.Continue(); } while (response != ShipPlacement.Ok); } Console.Clear(); ConsoleOutput.DisplayBoard(this, false); ConsoleOutput.ClearScreenPrompt(); }
public static bool Attack(IPlayer player, IPlayer opponent) { bool isVictory; bool targetAcquired; FireShotResponse response; Coordinate radar; do { Console.Clear(); ConsoleOutput.DisplayBoard(opponent, true); Console.WriteLine($"\n{player.Name}, fire munitions at {opponent.Name}!"); radar = ConsoleInput.GetCoordinate(); response = opponent.Board.FireShot(radar); targetAcquired = ConsoleOutput.IsValidShot(response); } while (!targetAcquired); Console.Clear(); ConsoleOutput.DisplayBoard(opponent, true); isVictory = ConsoleOutput.OpponentFleetSunk(response, player); if (isVictory) { Continue(); Console.Clear(); ConsoleOutput.DisplayBoard(opponent, true); return(true); } Continue(); return(false); }
public static void SetUpBoard(User player) { ShipPlacement response; var ships = new Dictionary <ShipType, int>() { { ShipType.Destroyer, 2 }, { ShipType.Cruiser, 3 }, { ShipType.Submarine, 3 }, { ShipType.Battleship, 4 }, { ShipType.Carrier, 5 } }; foreach (KeyValuePair <ShipType, int> vessel in ships) { do { Console.Clear(); ConsoleOutput.DisplayBoard(player, false); ConsoleOutput.DisplayPlacementMessage(player, vessel.Key, vessel.Value); var request = new PlaceShipRequest() { Coordinate = ConsoleInput.GetCoordinate(), Direction = ConsoleInput.GetShipDirection(), ShipType = vessel.Key }; response = player.Board.PlaceShip(request); Console.Clear(); ConsoleOutput.DisplayBoard(player, false); ConsoleOutput.DisplayShipResponse(request, response); ConsoleInput.Continue(); } while (response != ShipPlacement.Ok); } Console.Clear(); ConsoleOutput.DisplayBoard(player, false); ClearScreenPrompt(); }