void IAttackTimer.Stun(ActionStrength actionStrength)
 {
     for (var i = 0; i < ((int)actionStrength) + 1; i++)
     {
         Thread.Sleep(StunTimeInMiliseconds);
     }
 }
Пример #2
0
        private static int Defence(Robot robot, ActionStrength defenceStrength)
        {
            robot.Status.RobotState = RobotState.Defending;

            Thread.Sleep((int)defenceStrength * 1000);

            robot.Status.RobotState = RobotState.Idle;

            return(0);
        }
        public void Defence(string battleFieldId, string robotId, ActionStrength defenceStrength)
        {
            BattleField battleField = BattleFields.GetBattleField(battleFieldId);

            if (battleField.BattleState == BattleState.Running)
            {
                Robot robot = battleField.GetRobot(robotId);

                _robotAction = new RobotActions(robot, defenceStrength);
                new DefenceAction(_robotAction).Execute();
            }
        }
Пример #4
0
        public RobotActions(Robot robot, ActionStrength actionStrength)
        {
            if (robot == null)
            {
                throw new ArgumentNullException(nameof(robot));
            }

            _robot          = robot;
            _actionStrength = actionStrength;

            InitializeChainOfResponsibility();
        }
Пример #5
0
        public void Update(string robotId, Action action, ActionStrength level)
        {
            var   reader = new RobotReader();
            Robot robot  = reader.GetRobotInfo(robotId);

            robot.RobotStrategy.Strategy.Add(new RobotTurn {
                Action = action, Level = level
            });

            var writer = new StrategyWriter();

            writer.UpdateStrategy(robot.RobotId, robot.RobotStrategy);
        }
Пример #6
0
        private static int MakeDamage(Robot enemy, ActionStrength attackStrength)
        {
            var damage = 0;

            if (enemy.Status.RobotState != RobotState.Defending)
            {
                damage = CalculateInpact(attackStrength, 10);

                enemy.Status.Life              -= damage;
                enemy.Status.RobotState         = IsAlive(enemy) ? RobotState.Interrupted : RobotState.Dead;
                enemy.Status.LastReceivedDamage = damage;
            }

            return(enemy.Status.RobotState != RobotState.Dead ? damage : -99); //dead;
        }
        public int Rest(string battleFieldId, string robotId, ActionStrength restStrength)
        {
            var healPoints = 0;

            BattleField battleField = BattleFields.GetBattleField(battleFieldId);

            if (battleField.BattleState == BattleState.Running)
            {
                Robot robot = battleField.GetRobot(robotId);

                _robotAction = new RobotActions(robot, restStrength);
                healPoints   = new RestAction(_robotAction).Execute();
            }

            return(healPoints);
        }
Пример #8
0
        public int CalculateAttackDamage(ActionStrength actionStrength)
        {
            switch (actionStrength)
            {
            case ActionStrength.Weak:
                return(1 * _multiplier);

            case ActionStrength.Medium:
                return(2 * _multiplier);

            case ActionStrength.Strong:
                return(3 * _multiplier);

            default:
                return(0);
            }
        }
        public int Attack(string battleFieldId, string robotId, ActionStrength attackStrength)
        {
            int         damage;
            BattleField battleField = BattleFields.GetBattleField(battleFieldId);

            if (battleField.BattleState == BattleState.Running)
            {
                Robot robot = battleField.GetRobot(robotId);

                _robotAction = new RobotActions(robot, attackStrength);
                damage       = new AttackAction(_robotAction).Execute();
            }
            else
            {
                damage = -99; //battle not running
            }

            return(damage);
        }
        public static void Setup()
        {
            _robot = new Robot("TestId1", "TestUser1", "{\"Strategy\":[{\"Action\":\"Attack\",\"Level\":\"Weak\"}]}")
            {
                PlayType = PlayType.Auto,
                Status   = new RobotStatus()
            };

            _enemy = new Robot("TestId2", "TestUser2", "{\"Strategy\":[{\"Action\":\"Rest\",\"Level\":\"Medium\"}]}")
            {
                PlayType = PlayType.Auto,
                Status   = new RobotStatus()
            };

            _robot.Enemy = _enemy;
            _enemy.Enemy = _robot;

            _actionStrength = ActionStrength.Medium;
        }
Пример #11
0
        private static int Attack(Robot robot, ActionStrength attackStrength)
        {
            int damage;

            robot.Status.RobotState = RobotState.Attacking;

            Thread.Sleep((int)attackStrength * 1000);

            if (robot.Status.RobotState == RobotState.Attacking)
            {
                damage = MakeDamage(robot.Enemy, attackStrength);
                robot.Status.RobotState = RobotState.Idle;
            }
            else
            {
                damage = -1; //interupted
            }

            return(damage);
        }
Пример #12
0
        private static int Rest(Robot robot, ActionStrength restStrength)
        {
            int healthToRestore = 0;

            robot.Status.RobotState = RobotState.Resting;

            Thread.Sleep((int)restStrength * 1000);

            if (robot.Status.RobotState == RobotState.Resting)
            {
                //Magic formula
                healthToRestore    = CalculateInpact(restStrength, 5);
                robot.Status.Life += healthToRestore;

                if (robot.Status.Life > 500)
                {
                    robot.Status.Life = 500;
                }
            }

            return(healthToRestore);
        }
Пример #13
0
 public void Sleep(ActionStrength actionStrength)
 {
 }
Пример #14
0
 public void Stun(ActionStrength actionStrength)
 {
 }
Пример #15
0
 private static int CalculateInpact(ActionStrength actionStrength, int number)
 {
     return((number + ((int)actionStrength - 1) * 2) * (int)actionStrength);
 }