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); } }
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; }
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); }
public abstract void Move(Direction direction, AbsEntity entity);