示例#1
0
        public static GameEngine.StartingGameUnits getStartingSettingsFromXML(string strFactionName, Model.StaticDataCards staticDataCards)
        {
            GameEngine.StartingGameUnits rtnStartingGameUnits = new GameEngine.StartingGameUnits();


            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(_DataPath + _StartingSettingsXMLPath);

            XmlNodeList xmlTerrainNodes = xmlDoc.GetElementsByTagName("StartingUnits");

            foreach (XmlNode curNode in xmlTerrainNodes)
            {
                //Get this factions starting units
                if (curNode.Attributes["FactionName"].InnerText == strFactionName)
                {
                    XmlNodeList xmlChildNodes = curNode.ChildNodes;

                    foreach (XmlNode curChildNode in xmlChildNodes)
                    {
                        //Consider a way to implement this...
                        //if (curChildNode.Attributes["Type"].InnerText == Model.DataCardType.Planet.ToString())
                        //{
                        //    GameEngine.PlayerInvObjs.InvUnit curInvUnit = new GameEngine.PlayerInvObjs.InvUnit(staticDataCards.getShipByName(curChildNode.Attributes["UnitName"].InnerText), curChildNode.Attributes["PlanetName"].InnerText);

                        //    rtnStartingGameUnits.startingUnits.Add(curInvUnit);
                        //}

                        if (curChildNode.Attributes["Type"].InnerText == "Resources")
                        {
                            rtnStartingGameUnits.startingResources = Model.Utilities.getIntOrN(curChildNode.Attributes["StartingAmount"].InnerText, -1);
                        }

                        if (curChildNode.Attributes["Type"].InnerText == Model.DataCardType.Facility.ToString())
                        {
                            GameEngine.PlayerInvObjs.InvUnit curInvUnit = new GameEngine.PlayerInvObjs.InvUnit(staticDataCards.getFacilityByName(curChildNode.Attributes["UnitName"].InnerText), curChildNode.Attributes["PlanetName"].InnerText);

                            rtnStartingGameUnits.startingUnits.Add(curInvUnit);
                        }

                        else if (curChildNode.Attributes["Type"].InnerText == Model.DataCardType.Ship.ToString())
                        {
                            GameEngine.PlayerInvObjs.InvUnit curInvUnit = new GameEngine.PlayerInvObjs.InvUnit(staticDataCards.getShipByName(curChildNode.Attributes["UnitName"].InnerText), curChildNode.Attributes["PlanetName"].InnerText);

                            rtnStartingGameUnits.startingUnits.Add(curInvUnit);
                        }

                        else if (curChildNode.Attributes["Type"].InnerText == Model.DataCardType.Troops.ToString())
                        {
                            GameEngine.PlayerInvObjs.InvUnit curInvUnit = new GameEngine.PlayerInvObjs.InvUnit(staticDataCards.getTroopsByName(curChildNode.Attributes["UnitName"].InnerText), curChildNode.Attributes["PlanetName"].InnerText);

                            rtnStartingGameUnits.startingUnits.Add(curInvUnit);
                        }
                    }
                }
            }


            return(rtnStartingGameUnits);
        }
        //Methods
        public void startNewGame(string gameID, string gameName, string userName, string factionName, GameUpdateClassComponents curGameUpdateClassComponents)
        {
            ID = gameID;
            Name = gameName;
            _gameIsRunning = true;

            //Start at galactic day 1
            curGalacticDayMang.CurrentGalacticDay = 1;

            //Create player 1. Give him 5 resources for the hell of it...
            Player1 = new Player(userName, factionName, 5);

            //Build the Galaxies and planets from the XML file
            curGameUniverse.TheUniverse = Model.DataUtilities.getGalaxiesFromXML();

            buildGameControls(curGameUpdateClassComponents);

            //Get all the units from XML files
            staticDataCards = new Model.StaticDataCards();

            GameEngine.StartingGameUnits startingUnits = Model.DataUtilities.getStartingSettingsFromXML(factionName, staticDataCards);
            Player1.curGameResourceMang.invRawMaterials = startingUnits.startingResources;

            curGameUniverse.getPlanetByName("Coruscant").Owner = new GameEngine.GalacticComponents.Owner(Player1);

            foreach (GameEngine.PlayerInvObjs.InvUnit curInvObj in startingUnits.startingUnits)
            {
                curInvObj.FacilityOwner = new GameEngine.GalacticComponents.Owner(Player1);

                //curInvObj.iuFacility._underConstruction = false;
                    //.player = Player1;

                if (curInvObj.invUnitType == Model.DataCardType.Facility)
                {//Add Facilities to the ground
                    curGameUniverse.getPlanetByName(curInvObj.startingLocation).GroundSpaces.Facilities.Add(curInvObj);
                }
                else if (curInvObj.invUnitType == Model.DataCardType.Ship)
                {//Add Ships to the orbit
                    curGameUniverse.getPlanetByName(curInvObj.startingLocation).Orbit.StarshipFleetsInOrbit.Add(curInvObj);
                }
                else if (curInvObj.invUnitType == Model.DataCardType.Troops)
                {//Add Troops to the ground
                    curGameUniverse.getPlanetByName(curInvObj.startingLocation).GroundSpaces.Troops.Add(curInvObj);
                }
                //Player1.playerUnits.Add(new GalacticConquest.GameEngine.PlayerInvObjs.InvUnit(curFacil));

            }

            //Player1.playerUnits

            //DataCards.GameUnit curUnit = new GalacticConquest.DataCards.Ship();
        }