Ejemplo n.º 1
0
        public override void Execute()
        {
            MoveObjectRequest moveObjectRequest = request as MoveObjectRequest;
            var room = gameService.FindGameByID(moveObjectRequest.GameID);

            bool?IsMoved = gameService.MoveObject(moveObjectRequest.GameID, moveObjectRequest.UserID, moveObjectRequest.Direction);

            if (room.Status != StatusGame.FINISHED)
            {
                response = new MoveObjectResponse(IsMoved);
                SendMessage(moveObjectRequest.UserID);

                Guid curUser = gameService.CurUser(moveObjectRequest.GameID);
                SendMessage(curUser, new YourStep()); // Шлём другому пользователю, что может ходить
            }
            else
            {
                // TODO: Можно сделать два разных пакета для победителя и проигравшего
                foreach (var us in room.GetUsersID)
                {
                    response = new GameFinished(moveObjectRequest.UserID, room.FindMazeByID(room.FindUserByID(us).MazeID).GetMazeStruct());
                    SendMessage(us, response);
                }
            }
        }
Ejemplo n.º 2
0
        private void MoveObjectFinished(object sender, moveCompletedEventArgs e)
        {
            object[] state = (object[]) e.UserState;
            OperationFinished<MoveObjectResponse> moveObjectFinishedHandler = (OperationFinished<MoveObjectResponse>) state[0];
            MoveObjectResponse response;

            if (e.Error != null)
            {
                response = new MoveObjectResponse
                           	{
                           		Status = MoveObjectStatus.Failed,
                           		UserState = state[1],
                           		Error = e.Error
                           	};
            }
            else
            {
                response = new MoveObjectResponse
                           	{
                           		Status = StatusMessageParser.ParseMoveObjectStatus(e.Result),
                           		UserState = state[1]
                           	};

                response.Error = response.Status == MoveObjectStatus.Unknown
                                 	?
                                 		new UnknownOperationStatusException(e.Result)
                                 	:
                                 		null;
            }

            moveObjectFinishedHandler(response);
        }