Beispiel #1
0
        /// <summary>
        /// Place a ship on a the board
        /// </summary>
        /// <param name="ship">A battleship</param>
        /// <returns></returns>
        public PlayerActionResult PlaceShip(Battleship ship)
        {
            if (this.stateTracker.State != PlayerState.Init)
            {
                return(PlayerActionResult.InvalidState);
            }

            foreach (Coordinate section in ship.GetCoordinates())
            {
                if (this.stateTracker.TheBoard.ValidateShipPlacement(section) != true)
                {
                    return(PlayerActionResult.InvalidMove);
                }
            }

            this.stateTracker.Ships.Add(ship);

            foreach (Coordinate section in ship.GetCoordinates())
            {
                this.stateTracker.TheBoard.PlaceShipSection(section);
            }

            if (this.stateTracker.State == PlayerState.HasPlacedShips)
            {
                return(PlayerActionResult.AllShipsPlaced);
            }

            return(PlayerActionResult.MoreShipsRequired);
        }