Esempio n. 1
0
        private void AddEnemyButton_Click(object sender, EventArgs e)
        {
            EnemyInfo newEnemyInfo = new EnemyInfo();

            if (currentLevel != -1 && currentWave != -1 && LevelListBox.SelectedIndex > -1 && WaveListBox.SelectedIndex > -1)
            {
                newEnemyInfo.enemyType  = (EnemyType)EnemyTypeComboBox.SelectedValue;
                newEnemyInfo.numEnemies = (int)NumEnemiesNumericUpDown.Value;
                Levels[LevelListBox.SelectedIndex].WaveList[WaveListBox.SelectedIndex].EnemyInfoList.Add(newEnemyInfo);
                EnemyInfoListBox.Items.Add(newEnemyInfo.enemyType);
                EnemyInfoListBox.SelectedIndex = EnemyInfoListBox.Items.Count - 1;
            }
        }
Esempio n. 2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LevelListBox.Items.Clear();
            WaveListBox.Items.Clear();
            EnemyInfoListBox.Items.Clear();
            EnemyTypeComboBox.SelectedIndex = 0;
            NumEnemiesNumericUpDown.Value   = 0;
            Levels.Clear();

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "All Files|*.*|Xml Files|*.xml";
            dlg.FilterIndex = 2;

            if (DialogResult.OK == dlg.ShowDialog())
            {
                XElement xRoot = XElement.Load(dlg.FileName);

                IEnumerable <XElement> xLevels = xRoot.Elements();


                foreach (XElement xLevel in xLevels)
                {
                    Level newLevel = new Level();

                    XAttribute xNumLevel = xLevel.Attribute("numLevel");
                    int        numLevel  = Convert.ToInt32(xNumLevel.Value);
                    newLevel.numLevel = numLevel;

                    XAttribute xLevelShape = xLevel.Attribute("levelShape");
                    string     levelShape  = Convert.ToString(xLevelShape.Value);
                    newLevel.levelShape = levelShape;

                    Levels.Add(newLevel);

                    IEnumerable <XElement> xWaves = xLevel.Elements();

                    foreach (XElement xWave in xWaves)
                    {
                        Wave newWave = new Wave();

                        XAttribute xNumWave = xWave.Attribute("numWave");
                        int        numWave  = Convert.ToInt32(xNumWave.Value);
                        newWave.numWave = numWave;

                        newLevel.WaveList.Add(newWave);

                        IEnumerable <XElement> xEnemyInfos = xWave.Elements();

                        foreach (XElement xEnemyInfo in xEnemyInfos)
                        {
                            EnemyInfo newEnemyInfo = new EnemyInfo();

                            XAttribute xEnemyType = xEnemyInfo.Attribute("enemyType");
                            EnemyType  enemyType  = (EnemyType)Convert.ToInt32(xEnemyType.Value);
                            newEnemyInfo.enemyType = enemyType;

                            XAttribute xNumEnemies = xEnemyInfo.Attribute("numEnemies");
                            int        numEnemies  = Convert.ToInt32(xNumEnemies.Value);
                            newEnemyInfo.numEnemies = numEnemies;

                            newWave.EnemyInfoList.Add(newEnemyInfo);
                        }
                    }
                }

                for (int level = 0; level < Levels.Count; level++)
                {
                    LevelListBox.Items.Add(Levels[level].numLevel);
                }

                if (LevelListBox.Items.Count > 0)
                {
                    LevelListBox.SelectedIndex = 0;

                    if (WaveListBox.Items.Count > 0)
                    {
                        WaveListBox.SelectedIndex = 0;

                        if (EnemyInfoListBox.Items.Count > 0)
                        {
                            EnemyInfoListBox.SelectedIndex = 0;
                        }
                    }
                }
            }
        }