Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Character hero = new Character();

            hero.Name          = "Hero";
            hero.Health        = 100;
            hero.DamageMaximum = 20;
            hero.AttackBonus   = false;

            infoLabel.Text = String.Format("Greetings, O Formidable {0}! Your starting " +
                                           "health is {1}, your attack bonus is {2}, and the most damage you can " +
                                           "inflict is {3}. Your people are counting on you! Good luck. <br/>",
                                           hero.Name, hero.Health, hero.AttackBonus, hero.DamageMaximum);

            Character monster = new Character();

            monster.Name          = "Monster";
            monster.Health        = 100;
            monster.DamageMaximum = 17;
            monster.AttackBonus   = true;

            infoLabel.Text += String.Format("<br/>Greetings, O despicable {0}! " +
                                            "Your starting health is {1}, your attack bonus is {2}, and your defense " +
                                            "bonus is {3}. I'm sure you have a reason for fighting--Good luck.<br/><br/>  ", monster.Name, monster.Health.ToString(), monster.AttackBonus.ToString(), monster.DamageMaximum.ToString());

            Dice dice  = new Dice();
            int  round = 0;

            // Give bonus attack if either is true.
            int damage = (hero.AttackBonus == true) ? hero.PerformAttack(dice) : monster.PerformAttack(dice);

            if (hero.AttackBonus == true)
            {
                monster.Defend(damage);
            }
            else
            {
                hero.Defend(damage);
            }

            displayRoundHeader(round, hero, monster);

            while (hero.Health > 0 && monster.Health > 0)
            {
                round++;
                // monster attacks first
                damage = monster.PerformAttack(dice);
                hero.Defend(damage);

                // hero attacks second
                damage = hero.PerformAttack(dice);
                monster.Defend(damage);

                displayRoundHeader(round, hero, monster);
            }
            displayResult(monster, hero, round);
        }