public override void SetUp()
 {
     base.SetUp();
     Bot.PositionTo(Battlefield, 1, 1);
     Attacker = Get <IBotWorkshop>().Create(TestBotAI.AttackFirstEnemy);
     Bot.TakeDamage(Bot.MaxHP + Bot.MaxHP, Attacker);
 }
Example #2
0
        public override void SetUp()
        {
            base.SetUp();
            Enemy = Get <IBotWorkshop>().Create(TestBotAI.Idle);
            var turnAction = TurnAction.Attack(Enemy.OutsideView);

            BotAI.TurnAction = turnAction;
            EnergyCost       = BotAI.TurnAction.EnergyCost;
        }
Example #3
0
 public BattlefieldBotViewModel(IBattleBot battleBot, int battlefieldWidth, int battlefieldHeight, IBattlefield battlefield)
 {
     myBattlefieldWidth  = battlefieldWidth;
     myBattlefieldHeight = battlefieldHeight;
     myBattlefield       = battlefield;
     Width  = 40;
     Height = 50;
     UpdateFrom(battleBot);
 }
Example #4
0
 public void Update(IBattleBot bot)
 {
     foreach (var botViewModel in Bots)
     {
         if (botViewModel.BotName == bot.Name)
         {
             botViewModel.UpdateFrom(bot);
         }
     }
 }
 public override void SetUp()
 {
     base.SetUp();
     Bot.PositionTo(Battlefield, 0, 0);
     BotAI.TurnAction = TurnAction.Move.East();
     Enemy            = BotWorkshop.Create(TestBotAI.Idle);
     Enemy.PositionTo(Battlefield, 1, 0);
     Bot.ExecuteTurnAction(new List <IBattleBot> {
         Enemy
     });
 }
Example #6
0
        public void Set(IBattleBot battleBot, int newX, int newY)
        {
            if (battleBot == null)
            {
                throw new ArgumentNullException(nameof(battleBot));
            }
            if (IsOutOfRange(newX, newY))
            {
                throw new ArgumentOutOfRangeException();
            }
            var oldPlace = this[battleBot];

            if (oldPlace != null)
            {
                Places[oldPlace.X, oldPlace.Y] = new BattlefieldPlace(oldPlace.X, oldPlace.Y);
            }
            Places[newX, newY] = new BattlefieldPlace(newX, newY, battleBot);
        }
Example #7
0
        private string ExecuteTurnAction(Attack attack, IEnumerable <IBattleBot> enemies)
        {
            if (attack.EnergyCost > EP)
            {
                return($"{Name} does not have enough energy to attack.");
            }

            var ownPlace    = Battlefield[this];
            var targetPlace = Battlefield[attack.Target];
            var distance    = ownPlace.DistanceTo(targetPlace);

            DrainEnergy(attack.EnergyCost);
            var damage = CalculateDamage(distance);
            var enemy  = enemies.FirstOrDefault(e => e.OutsideView == attack.Target);

            if (enemy == null)
            {
                return($"{Name} wants to attack, but enemy is not found on battlefield.");
            }

            if (enemy.HP <= 0)
            {
                return($"{Name} attempts to attack {enemy.Name} but failed, target is already destroyed.");
            }

            if (distance > Attack.MaxRange)
            {
                return($"{Name} attempts to attack {enemy.Name} but failed, target is out of range.");
            }

            if (damage <= 0)
            {
                return($"{Name} attacks {enemy.Name} with no damage.");
            }

            enemy.TakeDamage(damage, this);
            Target = enemy;

            return(enemy.HP <= 0
                ? $"{Name} destroys {enemy.Name}."
                : $"{Name} attacks {enemy.Name} with {damage} damage.");
        }
Example #8
0
 public void TakeDamage(int damage, IBattleBot attacker)
 {
     SP -= damage;
     if (SP < 0)
     {
         HP += SP;
         SP  = 0;
         if (HP <= 0)
         {
             if (attacker != null)
             {
                 Destroy(attacker);
             }
             else
             {
                 Destroy("unknown force");
             }
         }
     }
 }
Example #9
0
        public IBattlefieldPlace this[IBattleBot battleBot]
        {
            get
            {
                if (battleBot == null)
                {
                    throw new ArgumentNullException(nameof(battleBot));
                }

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        if (Places[x, y].Object is IBattleBot bot && bot == battleBot)
                        {
                            return(Places[x, y]);
                        }
                    }
                }

                return(null);
            }
        }
Example #10
0
 public BotStateViewModel(IBattleBot battleBot)
 {
     BattleBot = battleBot;
 }
Example #11
0
 private string DisplayBot(IBattleBot bot) =>
 $"[HP: {bot.HP,3:F0}, SP: {bot.SP,3:F0}, EP: {bot.EP,3:F0}] ";
Example #12
0
 private void Destroy(IBattleBot attacker)
 {
     attacker.Kills++;
     Destroy(attacker.Name);
 }
Example #13
0
 private void Reset()
 {
     Target = null;
 }
Example #14
0
 public InsideView(IBattleBot battleBot)
 {
     BattleBot = battleBot;
 }
Example #15
0
 public OutsideView(IBattleBot battleBot)
 {
     BattleBot = battleBot;
 }
Example #16
0
 private void DisplayBot(int row, IBattleBot bot) =>
 DisplayRow(row,
            $"  * {bot.Name,-30} " +
            $"[HP: {bot.HP,3:F0}, SP: {bot.SP,3:F0}, EP: {bot.EP,3:F0}] " +
            $"[X: {bot.Position.X,2}, Y: {bot.Position.Y,2}]");