pol9na

Работа с классами

Mar 29th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Study
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Knight knight = new Knight(100, 50);
  13.             Barbarian barbarian = new Barbarian(100, 1, 20, 2);
  14.             barbarian.TakeDamage(500);
  15.             knight.TakeDamage(120);
  16.  
  17.             barbarian.ShowInfo();
  18.             knight.ShowInfo();
  19.         }
  20.     }
  21.     class Warrior
  22.     {
  23.         protected int Health;
  24.         protected int Armor;
  25.         protected int Damage;
  26.         public Warrior(int health, int armor, int damage)
  27.         {
  28.             Health = health;
  29.             Armor = armor;
  30.             Damage = damage;
  31.         }
  32.  
  33.         public void TakeDamage(int damage)
  34.         {
  35.             Health -= damage - Armor;
  36.        
  37.         }
  38.         public void ShowInfo() {
  39.             Console.WriteLine(Health);
  40.         }
  41.     }
  42.     class Knight :Warrior
  43.     {
  44.         public Knight(int health, int damage) : base(health, 5, damage)
  45.         {
  46.        
  47.         }
  48.         public void Pray()
  49.         {
  50.             Armor += 2;
  51.         }
  52.        
  53.  
  54.     }
  55.     class Barbarian:Warrior
  56.     {
  57.         public int AttackSpeed;
  58.  
  59.         public Barbarian(int health, int armor, int damage, int attackSpeed): base(health, armor, damage* attackSpeed)
  60.         {
  61.             AttackSpeed = attackSpeed;
  62.  
  63.         }
  64.         public void Waagh()
  65.         {
  66.             Armor -= 2;
  67.             Health += 10;
  68.         }
  69.        
  70.  
  71.     }
  72. }
Add Comment
Please, Sign In to add comment