public void Defend(int damage, bool bonus, Dice defenseDie) { //to make it more realistic, I'm going to detect a random amount from the incoming damage int defenseValue = defenseDie.Roll(); //to me, a bonus attack would be a straight additive term to the damage, but I didn't architect this. int bonusAttack = 1; if (bonus) { bonusAttack = 2; } //conceivably, the defense value could be greater than damage, resulting in IMPROVED health. This takes care of that scenario. this.Health -= Math.Max(damage * bonusAttack - defenseValue, 0); }
public int Attack(Dice dice) { dice.Sides = DamageMaximum; return(dice.Roll()); }
public int Attack(Dice number) { number.Sides = this.DamageMaximum; return(number.Roll()); }
protected void Page_Load(object sender, EventArgs e) { Character hero = new Character(); hero.Name = "Hero"; hero.Health = 100; hero.DamageMaximum = 15; hero.AttackBonus = false; Character monster = new Character(); monster.Name = "Monster"; monster.Health = 150; monster.DamageMaximum = 20; monster.AttackBonus = true; Dice d20 = new Dice(); d20.Sides = 20; Random random = new Random(); int bonusCheck = random.Next(); if (hero.AttackBonus) { resultLabel.Text += String.Format("<p>{0} was sneaky and attacked before {1} was ready!<p>", hero.Name, monster.Name); monster.Defend(hero.Attack(d20.Roll())); } if (monster.AttackBonus) { resultLabel.Text += String.Format("<p>{0} was sneaky and attacked before {1} was ready!<p>", monster.Name, hero.Name); hero.Defend(monster.Attack(d20.Roll())); } resultLabel.Text += "Let the battle begin!<br />"; int round = 0; while (hero.Health > 0 && monster.Health > 0) { round++; printStats(hero); printStats(monster); resultLabel.Text += "<p>Round " + round.ToString() + ": <p>"; int damage = hero.Attack(d20.Roll()); monster.Defend(damage); resultLabel.Text += String.Format("<p>{0} attacks, dealing {1} points of damage to {2}<p>", hero.Name, damage, monster.Name); damage = monster.Attack(d20.Roll()); hero.Defend(damage); resultLabel.Text += String.Format("<p>{0} attacks, dealing {1} points of damage to {2}<p>", monster.Name, damage, hero.Name); } displayResult(hero, monster); /*if (hero.Health <= 0 && monster.Health <= 0) * { * resultLabel.Text += String.Format("<p>After a long and protracted battle, {0} slew {1} but then, alas, {0} " + " succumbed to her own injuries.<p>", hero.Name, monster.Name); + resultLabel.Text += "<P> Final Stats: <p>"; + + printStats(hero); + printStats(monster); + } + else if (hero.Health <= 0) + { + resultLabel.Text += String.Format("<p>Pushed beyond the limits of her endurance, {0} stares into the abyss of {1} and goes utterly mad.", hero.Name, monster.Name); + resultLabel.Text += "<P> Final Stats: <p>"; + + printStats(hero); + printStats(monster); + } + else + { + resultLabel.Text += String.Format("<p>{0} stands triumphant, having defeated {1} unequivacably.", hero.Name, monster.Name); + resultLabel.Text += "<P> Final Stats: <p>"; + + printStats(hero); + printStats(monster); + } */ }
public int Attack(Dice Attack) { //Only allow the maximum amount (up to 2000) for a given hero (anything less, too, of course) return(Math.Min(Attack.Roll(), DamageMaximum)); }
public int Attack(Dice dice) { dice.Sides = DamageMaximum + 1; return dice.Roll(); }
public int Attack(Dice diceRoll) { diceRoll.Sides = this.DamageMaximum; //Sets the sides of the dice to the damage maximum return(diceRoll.Roll()); }