Exemple #1
0
        public static AbsEntity Fight(AbsEntity firstEnt, AbsEntity secondEnt)
        {
            if (firstEnt.EntityState == State.InCombat || secondEnt.EntityState == State.InCombat)
            {
                throw new Exception("One of the entities is already in combat!");
            }
            if (firstEnt.EntityState == State.Dead || secondEnt.EntityState == State.Dead)
            {
                throw new Exception("One of the entities is already dead.");
            }
            if (!Distance.IsCloseEnough(firstEnt, secondEnt, 2))
            {
                throw new Exception("Entities are too far from each other to combat!");
            }

            //Fights are to the DEATH!
            while (firstEnt.EntityState == State.Alive && secondEnt.EntityState == State.Alive)
            {
                firstEnt.Hit(secondEnt);
                secondEnt.Hit(firstEnt);
            }

            if (firstEnt.EntityState == State.Dead)
            {
                return(firstEnt);
            }
            else
            {
                return(secondEnt);
            }
        }
Exemple #2
0
        public override void Move(Direction direction, AbsEntity entity)
        {
            int newPosX = entity.PosX;
            int newPosY = entity.PosY;

            switch (direction)
            {
            case Direction.Up:
                newPosY = entity.PosY + 1;
                break;

            case Direction.Down:
                newPosY = entity.PosY - 1;
                break;

            case Direction.Left:
                newPosX = entity.PosX - 1;
                break;

            case Direction.Right:
                newPosX = entity.PosX + 1;
                break;

            default:
                break;
            }
            if (Entities.Find(e => e.PosX == newPosX && e.PosY == newPosY) != null)
            {
                return;
            }

            entity.PosX = newPosX;
            entity.PosY = newPosY;
        }
Exemple #3
0
        public virtual void Hit(AbsEntity enemy)
        {
            var    statDif = AttackStat - enemy.DefenseStat;
            Random rand    = new Random();

            var hit = rand.Next(0, 10 + statDif);

            enemy.ChangeHP(hit);
        }
Exemple #4
0
 public abstract void Move(Direction direction, AbsEntity entity);