/// <summary>
        /// Change the number of directions in the image of monsters
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void RBLeftDirection_CheckedChanged(object sender, EventArgs e)
        {
            if (Convert.ToInt32(GBNumberOfDirections.Tag) == 0)//One handler for all RadioButtons,
            //Therefore, the Tag property is used to prevent double processing
            {
                GBNumberOfDirections.Tag = 1;
            }
            else
            {
                GBNumberOfDirections.Tag = 0;
                return;
            }
            if (!_realChange)
            {
                return;
            }
            MonsterParam tmp = _levelsConfig[_currentLevel - 1];

            if (RBLeftDirection.Checked)
            {
                tmp.NumberOfDirectionsInFile = 1;
            }
            else if (RBLetfAndUpDirections.Checked)
            {
                tmp.NumberOfDirectionsInFile = 2;
            }
            else if (RBAllFourDirections.Checked)
            {
                tmp.NumberOfDirectionsInFile = 4;
            }
            _levelsConfig[_currentLevel - 1] = tmp;
            BNewGameConfig.Tag = 1;
            DrawMonsterPhases(MonsterDirection.Left);
        }
        /// <summary>
        /// Draws the monster phases.
        /// </summary>
        /// <param name="direction">The direction.</param>
        private void DrawMonsterPhases(MonsterDirection direction)
        {
            MonsterParam tmp = _levelsConfig[_currentLevel - 1];

            try
            {
                if (tmp[MonsterDirection.Left, 0] == null)
                {
                    return;
                }
                Bitmap tmpForDrawing = new Bitmap(PBMosterPict.Width, (tmp[direction, 0].Height * tmp.NumberOfPhases) + ((20 * tmp.NumberOfPhases) - 1));
                PBMosterPict.Height = tmpForDrawing.Height;
                Graphics canva = Graphics.FromImage(tmpForDrawing);
                canva.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 0, PBMosterPict.Width, PBMosterPict.Height));
                for (int phaseNum = 0; phaseNum < tmp.NumberOfPhases; phaseNum++)
                {
                    canva.DrawImage(tmp[direction, phaseNum], (PBMosterPict.Width / 2) - (tmp[direction, phaseNum].Width / 2), (phaseNum * tmp[direction, phaseNum].Height + 20 * phaseNum),
                                    tmp[direction, phaseNum].Width, tmp[direction, phaseNum].Height);
                }
                PBMosterPict.Image = tmpForDrawing;
                PMonsterPict.Refresh();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }
        }
        /// <summary>
        /// Change setting of invisibility
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CBLevelInvisible_CheckedChanged(object sender, EventArgs e)
        {
            if ((_currentLevel <= 0) || (!_realChange))
            {
                return;
            }
            MonsterParam tmp = _levelsConfig[_currentLevel - 1];

            tmp.Base.Invisible = CBLevelInvisible.Checked;
            _levelsConfig[_currentLevel - 1] = tmp;
            BNewGameConfig.Tag = 1;
        }
        /// <summary>
        /// Canva speed setting validation
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void nUDCanvaSpeed_Validated(object sender, EventArgs e)
        {
            if ((_currentLevel <= 0) || (!_realChange))
            {
                return;
            }
            MonsterParam tmp = _levelsConfig[_currentLevel - 1];

            tmp.Base.CanvasSpeed             = Convert.ToInt32(nUDCanvaSpeed.Value);
            _levelsConfig[_currentLevel - 1] = tmp;
            BNewGameConfig.Tag = 1;
        }
        /// <summary>
        /// Shows the level settings.
        /// </summary>
        /// <param name="levelNum">Number of the level.</param>
        private void ShowLevelSettings(int levelNum)
        {
            if (_levelsConfig.Count < levelNum)
            {
                return;
            }
            _realChange                          = false;
            mTBGoldForKill.Text                  = _goldForKillMonster[levelNum - 1].ToString(CultureInfo.InvariantCulture);
            mTBHealthPoints.Text                 = _levelsConfig[levelNum - 1].Base.HealthPoints.ToString(CultureInfo.InvariantCulture);
            mTBNumberOfPhases.Text               = _levelsConfig[levelNum - 1].NumberOfPhases.ToString(CultureInfo.InvariantCulture);
            nUDCanvaSpeed.Value                  = Convert.ToDecimal(_levelsConfig[levelNum - 1].Base.CanvasSpeed);
            mTBArmor.Text                        = _levelsConfig[levelNum - 1].Base.Armor.ToString(CultureInfo.InvariantCulture);
            mTBNumberOfMonstersAtLevel.Text      = _numberOfMonstersAtLevel[levelNum - 1].ToString(CultureInfo.InvariantCulture);
            mTBGoldForSuccessfulLevelFinish.Text = _goldForSuccessfulLevelFinish[levelNum - 1].ToString(CultureInfo.InvariantCulture);
            CBLevelInvisible.Checked             = _levelsConfig[levelNum - 1].Base.Invisible;
            LCurrentNCountLevel.Text             = "Level: " + levelNum.ToString(CultureInfo.InvariantCulture) + "/" + _levelsConfig.Count.ToString(CultureInfo.InvariantCulture);
            //Monster picture
            MonsterParam tmp = _levelsConfig[levelNum - 1];

            if (tmp[MonsterDirection.Left, 0] != null)
            {
                DrawMonsterPhases(MonsterDirection.Left);
            }
            else
            {
                PBMosterPict.Image = null;
                PBMosterPict.Size  = new Size(210, 254);
            }
            switch (tmp.NumberOfDirectionsInFile)
            {
            case 1:
                RBLeftDirection.Checked = true;
                break;

            case 2:
                RBLetfAndUpDirections.Checked = true;
                break;

            case 4:
                RBAllFourDirections.Checked = true;
                break;
            }
            _realChange = true;
        }
        /// <summary>
        /// New level adding
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BAddLevel_Click(object sender, EventArgs e)
        {
            MonsterParam tmp = new MonsterParam(1, 100, 1, 1, "", 1);

            _levelsConfig.Insert(_currentLevel++, tmp);
            _numberOfMonstersAtLevel.Insert(_currentLevel - 1, 20);
            _goldForSuccessfulLevelFinish.Insert(_currentLevel - 1, 40);
            _goldForKillMonster.Insert(_currentLevel - 1, 10);
            LCurrentNCountLevel.Text = "Level: " + _currentLevel.ToString(CultureInfo.InvariantCulture) + "/" + _levelsConfig.Count.ToString(CultureInfo.InvariantCulture);
            if (_levelsConfig.Count == 2)//If number of levels>1, user needs to switch between them
            {
                BNextLevel.Enabled = true;
                BPrevLevel.Enabled = true;
            }
            if (_levelsConfig.Count == 1)
            {
                BLoadMonsterPict.Enabled     = true;//User can add monster picture
                GBNumberOfDirections.Enabled = true;
                CBLevelInvisible.Enabled     = true;
            }
            DefaultForNewLevel();//Set a level template
            BRemoveLevel.Enabled = true;
            BNewGameConfig.Tag   = 1;
        }
        /// <summary>
        /// Masked text box changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void maskedTextBoxChanged(object sender, EventArgs e)
        {
            if ((sender as MaskedTextBox) == null)
            {
                MessageBox.Show("BAD BAD BAD programmer! The method is used incorrectly");
                return;
            }
            if (_currentLevel <= 0 || ((sender as MaskedTextBox).Text == string.Empty) || (!_realChange))
            {
                return;
            }
            Check checkInput = (string inValue, int valueBeforeChange, out int checkResult) =>
            {
                checkResult = Convert.ToInt32(inValue.Replace(" ", string.Empty)) == 0 ?
                              valueBeforeChange : Convert.ToInt32(inValue.Replace(" ", string.Empty));
            };
            MonsterParam tmp        = _levelsConfig[_currentLevel - 1];
            bool         needRedraw = false;

            switch ((sender as MaskedTextBox).Name)
            {
            case "mTBHealthPoints":
                checkInput(mTBHealthPoints.Text, tmp.Base.HealthPoints, out tmp.Base.HealthPoints);
                break;

            case "mTBGoldForKill":
            {
                int tmpInt = _goldForKillMonster[_currentLevel - 1];
                checkInput(mTBGoldForKill.Text, tmpInt, out tmpInt);
                _goldForKillMonster[_currentLevel - 1] = tmpInt;
            }
            break;

            case "mTBNumberOfPhases":
                checkInput(mTBNumberOfPhases.Text, tmp.NumberOfPhases, out tmp.NumberOfPhases);
                needRedraw = true;
                break;

            case "mTBArmor":
                checkInput(mTBArmor.Text, tmp.Base.Armor, out tmp.Base.Armor);
                break;

            case "mTBNumberOfMonstersAtLevel":
            {
                int tmpInt = _numberOfMonstersAtLevel[_currentLevel - 1];
                checkInput(mTBNumberOfMonstersAtLevel.Text, tmpInt, out tmpInt);
                _numberOfMonstersAtLevel[_currentLevel - 1] = tmpInt;
            }
            break;

            case "mTBGoldForSuccessfulLevelFinish":
            {
                int tmpInt = _goldForSuccessfulLevelFinish[_currentLevel - 1];
                checkInput(mTBGoldForSuccessfulLevelFinish.Text, tmpInt, out tmpInt);
                _goldForSuccessfulLevelFinish[_currentLevel - 1] = tmpInt;
            }
            break;
            }
            _levelsConfig[_currentLevel - 1] = tmp;
            if (needRedraw)
            {
                DrawMonsterPhases(MonsterDirection.Left);
            }
            BNewGameConfig.Tag = 1;
        }
Пример #8
0
 public void SetTo(MonsterParam param)
 {
     HP        = param.HP;
     MoveSpeed = param.MoveSpeed;
     Damage    = param.Damage;
 }