protected void Page_Load(object sender, EventArgs e) { dice dice = new dice(); character hero = new character(); hero.Name = "Silly Sam"; hero.Health = 100; hero.DamageMaximum = 25; hero.AttackBonus = false; character monster = new character(); monster.Name = "Jenova"; monster.Health = 200; monster.DamageMaximum = 15; monster.AttackBonus = true; while (hero.Health > 0 && monster.Health > 0) { int damage = hero.Attack(dice); monster.Defend(damage); damage = monster.Attack(dice); hero.Defend(damage); displayCharacterStats(hero); displayCharacterStats(monster); } displayResults(hero, monster); }
private void displayResults(character opponent1, character opponent2) { if (opponent1.Health > 0 && opponent2.Health <= 0) { resultLabel.Text += String.Format("<p>{0} won.</p>", opponent1.Name); } else if (opponent2.Health > 0 && opponent1.Health <= 0) { resultLabel.Text += String.Format("<p>{0} won.</p>", opponent2.Name); } else if (opponent1.Health <= 0 && opponent2.Health <= 0) { resultLabel.Text += "They both lost."; } }
private void displayCharacterStats(character character) { resultLabel.Text += String.Format("<p>Name: {0} <br /> Health: {1} <br /> DamageMaximum: {2} <br /> AttackBonus: {3}</p>", character.Name, character.Health.ToString(), character.DamageMaximum.ToString(), character.AttackBonus.ToString()); }