Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- enum Fractions
- {
- HUMAN,
- ELVEN,
- ORC,
- UNDEAD,
- DWARVE,
- GOBLIN
- }
- struct Position2D
- {
- public float x;
- public float y;
- };
- class Unit
- {
- protected const string type = "Unit";
- protected Position2D position;
- protected static Fractions fraction;
- protected double speed;
- protected int damage;
- protected int currentHp;
- protected int MaxHp { get; set; }
- protected double Speed
- {
- get { return speed; }
- set
- {
- if (value < 0)
- speed = 0;
- else
- speed = value;
- }
- }
- protected int Damage
- {
- get { return damage; }
- set
- {
- if (value < 0)
- damage = 0;
- else
- damage = value;
- }
- }
- protected int CurrentHp
- {
- get { return currentHp; }
- set
- {
- if (value >= MaxHp)
- currentHp = MaxHp;
- else
- currentHp = value;
- }
- }
- public virtual void die()
- {
- Console.WriteLine("Woops...");
- }
- public virtual void attack(Unit unit)
- {
- Console.WriteLine("Boom...");
- }
- public virtual void move(Position2D pos)
- {
- this.position = pos;
- }
- public void takeDamage(int dmg)
- {
- this.CurrentHp -= dmg;
- }
- public Unit(){
- position.x = 0;
- position.y = 0;
- Damage = 10;
- MaxHp = 100;
- CurrentHp = MaxHp;
- Speed = 1.0;
- }
- public Unit (int damage, int maxhp, double speed)
- {
- position.x = 0;
- position.y = 0;
- Damage = damage;
- MaxHp = maxhp;
- CurrentHp = MaxHp;
- Speed = speed;
- }
- };
- class Friendly : Unit
- {
- protected bool hostile;
- protected int confidence;
- protected int Confidence
- {
- get { return confidence; }
- set
- {
- if (value < 30)
- {
- if (value < 0)
- confidence = 0;
- hostile = true;
- }
- else
- {
- if (value > 100)
- confidence = 100;
- else
- confidence = value;
- hostile = false;
- }
- }
- }
- };
- class Enemy : Unit
- {
- public void say(string msg)
- {
- Console.WriteLine($"Enemy {type} from fraction {fraction} says: {msg}");
- }
- };
- class Swordman : Friendly
- {
- public override void attack(Unit unit)
- {
- Console.WriteLine($"{type} wordman from fraction {fraction} damaged in {damage} hp");
- unit.takeDamage(damage);
- }
- static Swordman()
- {
- fraction = Fractions.HUMAN;
- }
- public Swordman()
- {
- this.MaxHp = 300;
- this.Damage = 20;
- this.CurrentHp = this.MaxHp;
- this.position.x = 0;
- this.position.y = 0;
- this.Confidence = 50;
- this.speed = 2.4;
- }
- public Swordman(int damage, int maxhp, double speed)
- {
- this.MaxHp = maxhp;
- this.Damage = damage;
- this.CurrentHp = this.MaxHp;
- this.position.x = 0;
- this.position.y = 0;
- this.Confidence = 50;
- this.Speed = speed;
- }
- };
- class Skeleton : Enemy
- {
- public override void attack(Unit unit)
- {
- Random rnd = new Random();
- int dmg = this.Damage;
- int chance = rnd.Next(1, 100);
- if (chance <= 30)
- {
- dmg *= 2;
- }
- Console.WriteLine($"Skeleton from fraction {fraction} damaged your ally in {dmg} hp");
- unit.takeDamage(dmg);
- }
- static Skeleton()
- {
- fraction = Fractions.UNDEAD;
- }
- public Skeleton()
- {
- this.MaxHp = 100;
- this.Damage = 12;
- this.CurrentHp = this.MaxHp;
- this.position.x = 0;
- this.position.y = 0;
- this.speed = 1.8;
- }
- };
- namespace lab1
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement