public IGameInfo CreateFromGame(IGame game, Guid playerId)
        {
            GameInfo gameInfo = new GameInfo();

            gameInfo.Id = game.Id;
            IPlayer player   = game.GetPlayerById(playerId);
            IPlayer oppenent = game.GetOpponent(player);

            gameInfo.HasBombsLoaded = player.HasBombsLoaded;
            gameInfo.OwnGrid        = _gridInfoFactory.CreateFromGrid(player.Grid);
            gameInfo.OpponentGrid   = _gridInfoFactory.CreateFromGrid(oppenent.Grid);
            gameInfo.OwnShips       = _shipInfoFactory.CreateMultipleFromFleet(player.Fleet);
            if (game.Settings.MustReportSunkenShip)
            {
                gameInfo.SunkenOpponentShips = _shipInfoFactory.CreateMultipleFromSunkenShipsOfFleet(oppenent.Fleet);
            }
            else
            {
                gameInfo.SunkenOpponentShips = new List <IShipInfo>();
            }
            if (player.Fleet.IsPositionedOnGrid && oppenent.Fleet.IsPositionedOnGrid)
            {
                gameInfo.IsReadyToStart = true;
            }
            else
            {
                gameInfo.IsReadyToStart = false;
            }
            return(gameInfo);
        }
Exemplo n.º 2
0
        public IGameInfo CreateFromGame(IGame game, Guid playerId)
        {
            var player1 = game.GetPlayerById(playerId);
            var player2 = game.GetOpponent(player1);

            return(new GameInfo
            {
                Id = game.Id,
                OwnGrid = _gridInfoFactory.CreateFromGrid(player1.Grid),
                OpponentGrid = _gridInfoFactory.CreateFromGrid(player2.Grid),
                HasBombsLoaded = player1.HasBombsLoaded,
                OwnShips = _shipInfoFactory.CreateMultipleFromFleet(player1.Fleet),
                SunkenOpponentShips = game.Settings.MustReportSunkenShip ? _shipInfoFactory.CreateMultipleFromSunkenShipsOfFleet(player2.Fleet) : new List <IShipInfo>(),
                IsReadyToStart = player1.Fleet.IsPositionedOnGrid && player2.Fleet.IsPositionedOnGrid,
            });
        }