Exemple #1
0
        public void PlaceShip(Ship ship)
        {
            var shipX = ship.OriginPosition.X;
            var shipY = ship.OriginPosition.Y;

            for (var i = 0; i < ship.Length; i++)
            {
                this.SetCell(shipX, shipY, CellStatus.Ship);

                if (ship.Direction == ShipDirection.Vertical)
                {
                    shipX++;
                }
                else
                {
                    shipY++;
                }
            }

            Ships.Add(ship);
        }
Exemple #2
0
        public bool ShipsOverlap(Ship ship)
        {
            var shipX = ship.OriginPosition.X;
            var shipY = ship.OriginPosition.Y;

            for (var i = 0; i < ship.Length; i++)
            {
                if (this.GetCell(shipX, shipY) == CellStatus.Ship)
                {
                    return true;
                }

                if (ship.Direction == ShipDirection.Vertical)
                {
                    shipX++;
                }
                else
                {
                    shipY++;
                }
            }

            return false;
        }