private static void Main(string[] args) { //Init map MyMap = new Map(10, 10); var ship = new Ship(GetShipCoordinates(), GetInput("Enter name of first Ship", ".+")); ship.OnSinking += () => Console.WriteLine($"{ship.Name} has been sunk!"); MyMap.SetShip(ship); var result = MyMap.Fire(new Coordinate(0, 0)) ? "Hit" : "Miss"; Console.WriteLine($"{result}!"); Console.WriteLine("Press any key to fire again"); Console.ReadKey(); result = MyMap.Fire(new Coordinate(0, 1)) ? "Hit" : "Miss"; Console.WriteLine($"{result}!"); Console.WriteLine("Press any key to end"); Console.ReadKey(); }
public bool SetShip(Ship newShip) { //Ships do not stack in this version if (!AreaClear(newShip.Hull.Keys)) return false; //Place Ship foreach (var hullPiece in newShip.Hull) { Tiles[hullPiece.Key] = hullPiece.Value; } return true; }