public static BattleField GetBattleField(string battleFieldId)
        {
            BattleField battleField = BattleFieldSingleton.Instance.BattleFields.FirstOrDefault(r => r.BattleId == battleFieldId);

            if (battleField == null)
            {
                throw new ArgumentException($"Battlefield with id: '{battleFieldId}' does not exist.");
            }

            return(battleField);
        }
        public static void JoinBattleField(string battleFieldId, string robotId, PlayType playType)
        {
            BattleField battleField = GetBattleField(battleFieldId);

            battleField.RegisterRobot(robotId, playType);

            if (battleField.Robots.Count == 2)
            {
                battleField.StartBattle();
            }
        }
        public static string CreateBattleField(string hostId, string battleFieldName, RoomType roomType)
        {
            var battle = new BattleField(hostId, battleFieldName, roomType);

            BattleFieldSingleton.Instance.BattleFields.Add(battle);

            var battleWriter = new BattleWriter();

            battleWriter.AddBattle(battle);

            return(battle.BattleId);
        }
        public static RobotsLifePoints BattleStatus(string battleFieldId, string robotId)
        {
            BattleField battle = GetBattleField(battleFieldId);

            Robot robot = battle.GetRobot(robotId);

            return(new RobotsLifePoints
            {
                Robot = robot.Status.Life > 0 ? robot.Status.Life : 0,
                Enemy = robot.Enemy.Status.Life > 0 ? robot.Enemy.Status.Life : 0
            });
        }
        public static void LoadBattleField()
        {
            var battles = GetBattleFields();

            foreach (var battleField in battles)
            {
                var battle = new BattleField(
                    battleField.HostRobotId,
                    battleField.BattleName,
                    battleField.BattleType,
                    battleField.BattleId);

                BattleFieldSingleton.Instance.BattleFields.Add(battle);
            }
        }
        public void Start(Robot robot, string battleFieldId)
        {
            BattleField battle = BattleFields.GetBattleField(battleFieldId);

            int index = 0;
            List <RobotTurn> strategy = robot.RobotStrategy.Strategy;

            while (battle.BattleState == BattleState.Running)
            {
                var robotTurn = strategy[index % strategy.Count];

                IReceiver     robotAction = new RobotActions(robot, robotTurn.Level);
                ActionCommand command;

                switch (robotTurn.Action.ToString())
                {
                case "Attack":
                    command = new AttackAction(robotAction);
                    break;

                case "Defence":
                    command = new DefenceAction(robotAction);
                    break;

                case "Rest":
                    command = new RestAction(robotAction);
                    break;

                default:
                    throw new InvalidOperationException($"Action '{robotTurn.Action}' is invalid. Possible actions: 'Attack', 'Defence', 'Rest'.'");
                }

                command.Execute();

                Thread.Sleep(500);

                index++;
            }
        }