Ejemplo n.º 1
0
        // Prepares the current player state for file output
        public void SavePlayers(List <Info_Player> players, bool update = true)
        {
            if (!update)
            {
                return;
            }

            int id = 0;
            List <CommanderType> commanders = new List <CommanderType>();

            foreach (Info_Player player in players)
            {
                // Reference to new variable
                CommanderType com = player.Commander;
                // Change data
                {
                    // Add each army and their positions
                    if (com.Armies != null)
                    {
                        com.Armies.Clear();
                    }
                    else
                    {
                        com.Armies = new List <ArmyType>();
                    }
                    foreach (Entity.Entity_PlayerArmy army in Otter.Scene.Instance.GetEntities <Entity.Entity_PlayerArmy>())
                    {
                        // Belong to this player
                        if (army.Player == id)
                        {
                            ArmyType armytype = new ArmyType();
                            {
                                armytype.Name           = "";
                                armytype.SystemPosition = army.System.Index;
                                armytype.Strength       = 1;
                            }
                            com.Armies.Add(armytype);
                        }
                    }
                    // Add each owned system
                    if (com.OwnedSystems != null)
                    {
                        com.OwnedSystems.Clear();
                    }
                    else
                    {
                        com.OwnedSystems = new List <int>();
                    }
                    foreach (Entity.Entity_StarSystem system in Otter.Scene.Instance.GetEntities <Entity.Entity_StarSystem>())
                    {
                        // Belong to this player
                        if (system.Owner == id)
                        {
                            com.OwnedSystems.Add(system.MapID);
                        }
                    }
                }
                commanders.Add(com);
                id++;
            }

            // Remove old player data
            if (Commanders != null)
            {
                Commanders.Clear();
            }

            // Add this new data
            Commanders = new List <CommanderType>(commanders);
        }
        private void NewGame()
        {
            // Create new
            CurrentGame = new Info_Game();
            {
                CurrentGame.StartDate  = DateTime.Today.ToShortDateString();
                CurrentGame.Players    = 2;
                CurrentGame.Commanders = new List <CommanderType>();
                for (int com = 0; com < CurrentGame.Players; com++)
                {
                    CommanderType commander = new CommanderType();
                    {
                        commander.PlayerName     = "Matthew";
                        commander.UberID         = "\"7420260152538080746\"";                 //"friends":"[\"11035761434068835310\",\"16024636805495278681\",\"6884095390246756552\"]",
                        commander.FactionName    = "Legion";
                        commander.ModelID        = 0;
                        commander.Colour         = Color.Random.ColorString;
                        commander.CommanderCards = new List <string>();
                        {
                            commander.CommanderCards.Add("Miner Upgrade");
                        }
                        commander.Cards = new List <string>();
                        {
                            commander.Cards.Add("Advanced Bots");
                        }
                        commander.Armies = new List <ArmyType>();
                        {
                            ArmyType army;
                            {
                                army.Name           = "";
                                army.Strength       = 1;
                                army.SystemPosition = Rand.Int(0, Galaxy.MaxSystems);
                            }
                            commander.Armies.Add(army);

                            // Store initial state
                            SetPlayerTurn(com);
                            DoTurn(Helper.ACTION_MOVE, army.SystemPosition, com, 0, false);
                        }
                    }
                    CurrentGame.Commanders.Add(commander);

                    // Revert back to player 1 having first turn
                    SetPlayerTurn(0);
                }

                // Generate the initial galaxy
                Galaxy.Generate();
            }
            Galaxy.Initialise();
            Galaxy.Generate_Info();
            SetupGame();

            // Add ownership of the starting locations to those players
            int playerid = 0;

            foreach (CommanderType player in CurrentGame.Commanders)
            {
                foreach (ArmyType army in player.Armies)
                {
                    Galaxy.GetSystemByID(army.SystemPosition).SetOwner(playerid);
                }
                playerid++;
            }

            IsNewGame = true;
            SaveGame();
        }