Пример #1
0
        public bool AddShip(Ship newShip)
        {
            var battleField = _mockRepo.GetCurrentBattlefield();

            if (battleField == null)
            {
                _mockRepo.SetBattleField(new Battlefield()
                {
                    Boards =
                        new List <PlayerBoard>()
                    {
                        new PlayerBoard()
                        {
                            PlayerId = newShip.PlayerId, Ships = new List <Ship> {
                                newShip
                            }
                        },
                    }
                });
            }
            else
            {
                var board = GetPlayerBoard(newShip?.PlayerId);
                if (board == null)
                {
                    return(false);
                }
                if (!CanAddShip(board, newShip))
                {
                    return(false);
                }
                board.Ships.Add(newShip);
            }
            return(true);
        }