Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace ChallangeHeroMonsterClassesPart1
  9. {
  10.    
  11.     public partial class Default : System.Web.UI.Page
  12.     {
  13.        
  14.         protected void Page_Load(object sender, EventArgs e)
  15.         {
  16.             Random random = new Random();
  17.             Dice dice = new Dice();
  18.             //Dice dice2 = new Dice();
  19.  
  20.             Characters hero = new Characters();
  21.             Characters monster = new Characters();
  22.  
  23.             EvaluateTheCharacters(hero, monster);
  24.             GiveBonusAttack(hero, monster);
  25.             ShowResult(hero, monster);
  26.             int i = 0;
  27.             while (monster.Health >= 0 && hero.Health >= 0)
  28.             {
  29.                 Label1.Text += "</br> Round: " + i++;
  30.                 ShowResult(hero, monster);
  31.                 hero.Defend(monster.Attack(dice, monster, random));
  32.                 monster.Defend(hero.Attack(dice, hero, random));
  33.                
  34.                 findTheWinner(hero, monster);
  35.             }
  36.            
  37.  
  38.  
  39.          
  40.  
  41.  
  42.  
  43.            
  44.         }
  45.         private string findTheWinner(Characters hero,Characters monster)
  46.         {
  47.             if (hero.Health <= 0)
  48.             {
  49.                 return Label1.Text += string.Format("</br> The Winner is: {0}", monster.Name);
  50.  
  51.             }
  52.             else if (monster.Health <= 0)
  53.             {
  54.                 return Label1.Text += String.Format("</br> The Winner is: {0}", hero.Name);
  55.             }
  56.             else return null;
  57.            
  58.         }
  59.         private void EvaluateTheCharacters(Characters hero,Characters monster)
  60.         {
  61.             hero.Name = "Hero";
  62.             hero.Health = 87;
  63.             hero.AttackBonus = false;
  64.             hero.DamageMaximum = 25;
  65.  
  66.  
  67.             monster.Name = "Monster";
  68.             monster.Health = 80;
  69.             monster.AttackBonus = true;
  70.             monster.DamageMaximum = 20;
  71.         }
  72.         private void GiveBonusAttack(Characters hero,Characters monster)
  73.         {
  74.             if (hero.AttackBonus) monster.Health -= GetBonusAttack(hero, monster);
  75.             else if (monster.AttackBonus) hero.Health -= GetBonusAttack(hero, monster);
  76.             else return;
  77.         }
  78.         private void ShowResult(Characters hero,Characters monster)
  79.         {
  80.             GetStats(hero);
  81.             GetStats(monster);
  82.  
  83.         }
  84.         private int GetBonusAttack(Characters hero,Characters monster)
  85.         {
  86.             int bonusdamage = 0;
  87.             if (hero.AttackBonus) bonusdamage = 5;
  88.             else if (monster.AttackBonus) bonusdamage = 5;
  89.             else bonusdamage = 0;
  90.             return bonusdamage;
  91.  
  92.         }
  93.         private void GetStats(Characters character)
  94.         {
  95.             Label1.Text += string.Format("<p> Name: {0} - Health: {1} - DamageMaximum: {2} - AttackBonus: {3} </p>",
  96.              character.Name, character.Health, character.DamageMaximum, character.AttackBonus);
  97.         }
  98.  
  99.    
  100.     }
  101.  
  102.  
  103.  
  104.     class Characters
  105.     {
  106.  
  107.        
  108.         public string Name { get; set; }
  109.         public int Health { get; set; }
  110.         public int DamageMaximum { get; set; }
  111.         public bool AttackBonus { get; set; }
  112.         public int myDamage { get; set; }
  113.  
  114.         public int Attack(Dice damage,Characters charc,Random random)
  115.         {
  116.             damage.sides = charc.DamageMaximum;
  117.             return damage.Roll(random);
  118.         }
  119.         public void Defend(int damage)
  120.         {
  121.             if(Health>0) Health -= damage;
  122.         }
  123.  
  124.     }
  125.     class Dice
  126.     {
  127.        
  128.        //Random random { get; set; }
  129.         public int sides { get; set; }
  130.        
  131.         public int Roll(Random random)
  132.         {
  133.            // random = new Random();
  134.             return random.Next(sides);
  135.  
  136.         }
  137.  
  138.     }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement