Exemple #1
0
        public void Attack(EnemyClass enemy)
        {
            int damage;

            //use a switch statement to perform the attack
            switch (ChooseAttack())
            {
            case AttackType.Sword:
                //70% chance to hit
                if (rng.Next(0, 101) > 3)
                {
                    //hit! deal 15-30 damage
                    damage = rng.Next(15, 31);
                    //deal the damage to the enemy
                    enemy.HP -= damage;
                    //write the output to the user
                    Console.WriteLine("{0} deals {1} damage to {2}", this.Name, damage, enemy.Name);
                }
                else
                {
                    //missed
                    Console.WriteLine("{0} missed {1} with the {2}", this.Name, enemy.Name);
                }

                break;

            case AttackType.Magic:
                //magic always deals 5-15 damage
                damage = rng.Next(1, 16);
                //deal damage to the enemy
                enemy.HP -= damage;

                Console.WriteLine("{0} deals {1} damage to {2}", this.Name, damage, enemy.Name);



                break;

            case AttackType.Heal:
                //always heal 10-20

                break;

            default:
                break;
            }
        }
 //Constructor
 public GameClass()
 {
     this.Player = new PlayerClass("The mighty Owen", 100);
     this.Enemy  = new EnemyClass("The mightier Dustin", 200);
 }