Exemplo n.º 1
0
        public void MakeMove(Directions direction, int round)
        {
            var client = OperationContext.Current.GetCallbackChannel <IArenaCallback>();
            var robot  = avatarDictionary[client];

            if (direction == null || direction == Directions.NULL)
            {
                if (robot.ErrorNumber++ > 10)
                {
                    Disconnect(client);
                }
                client.reciveGamePlayData(_currentMap.getSmallerPartForRobot(robot.RobotPosition).SerializeMap(), new GamePlayServerResponse(_currentRound, avatarDictionary[client].RobotPosition, 0, 0, avatarDictionary[client].HasBigItem, avatarDictionary[client].SmallItem, MoveConsequence.InvalidMove, GamePlayServerResponse.InvalidMoveMessage("Direction of Move action cannot be null")));
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + robot.Login + " null Direction");
                _currentMovesQueue.Enqueue(new Move(MoveType.WrongAction, _currentMap, client, avatarDictionary, robot, Directions.NULL, _currentRound, _hostileMode));
                return;
            }
            else
            {
                if (round == _currentRound)
                {
                    if (!_currentMovesQueue.Enqueue(new Move(MoveType.MakeMove, _currentMap, client, avatarDictionary, robot, direction, _currentRound)))
                    {
                        if (robot.ErrorNumber++ > 10)
                        {
                            Disconnect(client);
                        }
                        client.reciveGamePlayData(_currentMap.getSmallerPartForRobot(robot.RobotPosition).SerializeMap(), new GamePlayServerResponse(_currentRound, avatarDictionary[client].RobotPosition, 0, 0, avatarDictionary[client].HasBigItem, avatarDictionary[client].SmallItem, MoveConsequence.InvalidMove, GamePlayServerResponse.InvalidMoveMessage("You cannot move two times in one round")));
                        EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + robot.Login + " moved two times in one round");
                    }
                    else
                    {
                        robot.ErrorNumber = 0;
                        EventLog.WriteMessageToLog(strLogPath, "Client: " + robot.Login + " Made move in direction " + direction.ToString() + " in round " + round.ToString());
                    }
                }
                else
                {
                    client.reciveGamePlayData(_currentMap.getSmallerPartForRobot(robot.RobotPosition).SerializeMap(), new GamePlayServerResponse(_currentRound, avatarDictionary[client].RobotPosition, 0, 0, avatarDictionary[client].HasBigItem, avatarDictionary[client].SmallItem, MoveConsequence.InvalidMove, GamePlayServerResponse.InvalidMoveMessage("Move not to this round")));
                    EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + robot.Login + " moved not in current round");
                }
            }
        }