public static SinglePlayersViewOfTheGameboardViewModel FromGameContext(GameContext game, Player loggedInPlayer, bool fogOfWar = true)
        {
            var vm = new SinglePlayersViewOfTheGameboardViewModel
                {
                    Players = game.Players,
                    CurrentPlayer = game.CurrentPlayer,
                    Round = game.Turn,
                    Id = (Guid)game.Id,
                    Name = game.Name,
                    UncomittedActions = new List<GameActionBase>()
                };

            foreach (var system in game.Systems)
            {
                var planetExplorationHistory = game.ExplorationMap[system];

                var systemToAdd = fogOfWar
                                      ? (planetExplorationHistory.PlayerCanSeeSystem(loggedInPlayer)
                                             ? system
                                             : PlanetarySystem.UndiscoveredSystem(system.SystemNumber))
                                      : system;

                vm.Systems.Add(systemToAdd);
            }

            if (game.CurrentPlayer == loggedInPlayer)
            {
                foreach (var action in game.UncommittedActions)
                {
                    vm.UncomittedActions.Add(action);
                }
            }

            return vm;
        }
        public RedirectToRouteResult CreateGame(int opponentId)
        {
            var game = GameContext.Create(NamesRepository.RandomName())
                                    .WithSystems(_generator.Generate());

            var opponent = _db.X.UserProfile.FindByUserId(opponentId);
            var player1 = new Player(WebSecurity.CurrentUserId, WebSecurity.CurrentUserName);
            var player2 = new Player(opponentId, opponent.UserName.ToString());

            game.AddPlayer(player1);
            game.AddPlayer(player2);

            _storage.Save(game);

            var playerOneProfile = _storage.GetOrEmpty<UserProfileData>(WebSecurity.CurrentUserId);
            var playerTwoProfile = _storage.GetOrEmpty<UserProfileData>(opponentId);

            var activeGameReference = new ActiveGameReference
                {
                    Id = (Guid) game.Id,
                    Name = game.Name,
                    Players = new List<Player> { player1, player2 }
                };

            playerOneProfile.ActiveGames.Add(activeGameReference);
            playerTwoProfile.ActiveGames.Add(activeGameReference);

            _storage.Save(playerOneProfile);
            _storage.Save(playerTwoProfile);

            return RedirectToAction("View", "Game", new { id = game.Id });
        }
 public PlanetarySystem(string name, string systemNumber, int buildingCap, Player owner)
     : this()
 {
     Name = name;
     SystemNumber = systemNumber;
     BuildingCap = buildingCap;
     Owner = owner;
 }
 public ConstructionStarship(Player playerOwner)
 {
     Owner = playerOwner;
     Movement = 1;
 }
        public GameContext AddPlayer(Player player)
        {
            var offset = Players.Count * GameDimensions.SectorSize;
            Players.Add(player);

            var startingSystem = Systems[offset + GameDimensions.StartingPlanetarySystem];

            var action = new Move {DestinationPlanetId = startingSystem.SystemNumber, Starship = new ConstructionStarship(player)};
            var actionHandler = new MoveActionHandler(action);
            actionHandler.Execute(player, this);

            return this;
        }
 public bool PlayerCanSeeSystem(Player player)
 {
     return VisibleToUserInThisList.Contains(player);
 }