예제 #1
0
        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();
        }
예제 #2
0
파일: Map.cs 프로젝트: alexandercessac/Lib
        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;
        }