public int Attack(Dice playerDice)
        {
            playerDice.Sides = 20;
            playerDice.Roll();
            return playerDice.Roll();

        }
        protected void Page_Load(object sender, EventArgs e)
        {                               

            Character hero = new Character();
            hero.Name = "Daniel";
            hero.Health = 100;
            hero.DamageMaximum = 10;
            hero.AttackBonus = true;
            
            Character monster = new Character();
            monster.Name = "Terrible Monster";
            monster.Health = 100;
            monster.DamageMaximum = 5;
            monster.AttackBonus = true;

                       
            
            Dice playerDice = new Dice();
            

            if (hero.AttackBonus == true)
            {
                Battle(monster, playerDice);


            }
            if (monster.AttackBonus == true)
            {
                Battle(hero, playerDice);

            }

            
            while ((hero.Health > 0) && (monster.Health > 0) )
            {
                Battle(hero, playerDice);
                Battle(monster, playerDice);
                DisplayResults(monster);
                DisplayResults(hero);
            }
            


        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Character hero = new Character();
            Dice dice = new Dice();

            hero.Name = "Hercules";
            hero.Health = 100;
            hero.DamageMaximum = 10;
            hero.AttackBonus = true;
            //heroDice.Sides = hero.DamageMaximum;

            Character monster = new Character();

            monster.Name = "Hydra";
            monster.Health = 75;
            monster.DamageMaximum = 15;
            monster.AttackBonus = false;
            //monsterDice.Sides = monster.DamageMaximum;

            string battle = "";
            if (hero.AttackBonus && !monster.AttackBonus)
            {
                battle += "Bonus Hero Attack! " + performAttack(hero, dice, monster) + "<br/><hr>";
            }
            else if (monster.AttackBonus && !hero.AttackBonus)
            {
                battle += "Surprise attack! " + performAttack(monster, dice, hero) + "<br/><hr>";
            }

            while (hero.Health > 0 && monster.Health > 0)
            {
                battle += performAttack(monster, dice, hero) + "<br/>";
                battle += performAttack(hero, dice, monster) + "<br/>";

                battle += "<hr>";
            }

            resultLabel.Text += battle;

            displayStats(hero, monster);
            displayResults(hero,monster);
        }
Exemple #4
0
 private string performAttack(Character attacker, Dice dice, Character defender)
 {
     int attack = attacker.Attack(dice);
     defender.Defend(attack);
     return String.Format("{0} attacks {1} and deals {2} damage!", attacker.Name, defender.Name, attack);
 }
 public void Battle(Character character,Dice playerDice)
 {
     character.Attack(playerDice);
     character.Defend(playerDice.Roll());
 }
Exemple #6
0
 public int Attack(Dice die)
 {
     die.Sides = this.DamageMaximum;
     return die.Roll();
 }