Exemplo n.º 1
0
        public World(SiegeGame game, string[] setup)
        {
            this.Game    = game;               //Sets game
            this.Enemies = new List <Enemy>(); //New list of enemies

            string[] worldSetup = setup[0].Split(',');

            if (worldSetup.Length == 4)
            {
                this.WaveController = new WaveController(this)
                {
                    WaveNumber = int.Parse(worldSetup[0])
                };

                //Money
                this.Money = int.Parse(worldSetup[1]);

                //Grid size
                worldSetup[2] = worldSetup[2].Trim(new Char[] { '[', ']' });
                this.CreateGrid(int.Parse(worldSetup[2].Substring(0, worldSetup[2].IndexOf("|"))), int.Parse(worldSetup[2].Remove(0, worldSetup[2].IndexOf("|") + 1)));

                //Total kills
                this.TotalKills = int.Parse(worldSetup[3]);
            }

            for (int i = 1; i < setup.Length; i++)
            {
                List <string> defenceInfo = new List <string>(setup[i].Split(','));

                if (defenceInfo[0] == new CrownDef().GetType().ToString())
                {
                    this.GetTileAt(this.GetCrownLocation()).Defence.Health = int.Parse(defenceInfo[2]);
                }
                else
                {
                    foreach (Defence d in Defence.Types)
                    {
                        if (defenceInfo[0] == d.GetType().ToString())
                        {
                            Defence defence = (Defence)Activator.CreateInstance(d.GetType());
                            defenceInfo[1] = defenceInfo[1].Trim(new Char[] { '[', ']' });
                            this.GetTileAt(int.Parse(defenceInfo[1].Substring(0, defenceInfo[1].IndexOf("|"))), int.Parse(defenceInfo[1].Remove(0, defenceInfo[1].IndexOf("|") + 1))).SetDefence(defence);
                            defenceInfo.RemoveRange(0, 2);
                            defence.LoadData(defenceInfo.ToArray());
                        }
                    }
                }
            }

            this.UpdateRiskMap(); //Updates the risk map


            //Testing def panel
            //this.defenceSelectPanel = new DefenceSelectPanel(this, new Rectangle(0, 0, 202, 390), new List<Defence>() { new StoneWallDef(), new GuardDef(), new DummyDef(Graphics.Graphics.archerDef), new DummyDef(Graphics.Graphics.catapultDef) });
            this.IsRunning = true;
            this.isPaused  = false;
        }