Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace ChallangeHeroMonsterClassesPart1
- {
- public partial class Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Random random = new Random();
- Dice dice = new Dice();
- //Dice dice2 = new Dice();
- Characters hero = new Characters();
- Characters monster = new Characters();
- EvaluateTheCharacters(hero, monster);
- GiveBonusAttack(hero, monster);
- ShowResult(hero, monster);
- int i = 0;
- while (monster.Health >= 0 && hero.Health >= 0)
- {
- Label1.Text += "</br> Round: " + i++;
- ShowResult(hero, monster);
- hero.Defend(monster.Attack(dice, monster, random));
- monster.Defend(hero.Attack(dice, hero, random));
- findTheWinner(hero, monster);
- }
- }
- private string findTheWinner(Characters hero,Characters monster)
- {
- if (hero.Health <= 0)
- {
- return Label1.Text += string.Format("</br> The Winner is: {0}", monster.Name);
- }
- else if (monster.Health <= 0)
- {
- return Label1.Text += String.Format("</br> The Winner is: {0}", hero.Name);
- }
- else return null;
- }
- private void EvaluateTheCharacters(Characters hero,Characters monster)
- {
- hero.Name = "Hero";
- hero.Health = 87;
- hero.AttackBonus = false;
- hero.DamageMaximum = 25;
- monster.Name = "Monster";
- monster.Health = 80;
- monster.AttackBonus = true;
- monster.DamageMaximum = 20;
- }
- private void GiveBonusAttack(Characters hero,Characters monster)
- {
- if (hero.AttackBonus) monster.Health -= GetBonusAttack(hero, monster);
- else if (monster.AttackBonus) hero.Health -= GetBonusAttack(hero, monster);
- else return;
- }
- private void ShowResult(Characters hero,Characters monster)
- {
- GetStats(hero);
- GetStats(monster);
- }
- private int GetBonusAttack(Characters hero,Characters monster)
- {
- int bonusdamage = 0;
- if (hero.AttackBonus) bonusdamage = 5;
- else if (monster.AttackBonus) bonusdamage = 5;
- else bonusdamage = 0;
- return bonusdamage;
- }
- private void GetStats(Characters character)
- {
- Label1.Text += string.Format("<p> Name: {0} - Health: {1} - DamageMaximum: {2} - AttackBonus: {3} </p>",
- character.Name, character.Health, character.DamageMaximum, character.AttackBonus);
- }
- }
- class Characters
- {
- public string Name { get; set; }
- public int Health { get; set; }
- public int DamageMaximum { get; set; }
- public bool AttackBonus { get; set; }
- public int myDamage { get; set; }
- public int Attack(Dice damage,Characters charc,Random random)
- {
- damage.sides = charc.DamageMaximum;
- return damage.Roll(random);
- }
- public void Defend(int damage)
- {
- if(Health>0) Health -= damage;
- }
- }
- class Dice
- {
- //Random random { get; set; }
- public int sides { get; set; }
- public int Roll(Random random)
- {
- // random = new Random();
- return random.Next(sides);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement