Ejemplo n.º 1
0
        /// <summary>
        /// plays out the attack sequence (player first then enemies)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAttack_Click(object sender, EventArgs e)
        {
            //Players attack
            //converts the string back to an int to do the maths
            int enemyHealth;

            int.TryParse(txtEnemyHealth.Text, out enemyHealth);

            enemyHealth -= char1.attack(); // the character attacks


            if (enemyHealth <= 0)                             //check if the monster died
            {
                MessageBox.Show("You defeated the monster!"); //show a message box
                txtEnemyHealth.Text = "0";
                e1 = new Enemy();
                char1.giveXP();
                char1.giveMoney(2); //take out magic number later
            }
            else //monster didnt die :(
            {
                txtEnemyHealth.Text = enemyHealth.ToString(); //update the string
            }


            //Enemy's attack, same as above but in reverse
            int playerHealth;

            int.TryParse(txtPlayerHealth.Text, out playerHealth);

            playerHealth -= e1.Attack();

            if (playerHealth <= 0)
            {
                MessageBox.Show("You died...");
                txtPlayerHealth.Text = "0";
            }
            else
            {
                txtPlayerHealth.Text = playerHealth.ToString();
            }
        }//end of Attack btn event handler