/// <summary>
 /// Handles server result.
 /// </summary>
 /// <param name="response">Server Result.</param>
 public void HandleServerResult(string response)
 {
     //Check if close or move command.
     if (response == "{}\n")
     {
         this.OpponentExitStatus = true;
     }
     else
     {
         string direction = FromJsonConverter.PlayDirection(response);
         this.OpponentPosition =
             ExecuteMove(OpponentPosition, direction);
     }
 }
        /// <summary>
        /// Solves the game.
        /// </summary>
        /// <param name="name">Game name.</param>
        public void SolveMaze(string name)
        {
            new Task(() =>
            {
                //Disable controls.
                EnableControlsStatus = false;

                try
                {
                    string command;

                    //Set algorithm type.
                    string algorithmType = settingsModel.DefaultAlgo.ToString();

                    //Parse to solve command.
                    command =
                        CommandParser.ParseTOSolveCommand(name, algorithmType);

                    communicationClient.SendToServer(command);

                    solution = Reverse(
                        FromJsonConverter.MazeSolution(ServerResponse));

                    PlayerPosition = maze.InitialPos;

                    //Move according to directions.
                    foreach (char direction in solution)
                    {
                        switch (direction)
                        {
                        case '0':
                            PlayerPosition =
                                PerformMove(
                                    PlayerPosition, "right");
                            break;

                        case '1':
                            PlayerPosition =
                                PerformMove(
                                    PlayerPosition, "left");
                            break;

                        case '2':
                            PlayerPosition =
                                PerformMove(
                                    PlayerPosition, "up");
                            break;

                        case '3':
                            PlayerPosition =
                                PerformMove(
                                    PlayerPosition, "down");
                            break;
                        }

                        //Sleep between each move.
                        Thread.Sleep(250);
                    }
                }
                catch (ArgumentNullException)
                {
                    this.ConnectionLost?.Invoke(this, null);
                }

                //Enable controls.
                EnableControlsStatus = true;
            }).Start();
        }
 /// <summary>
 /// Handles list command.
 /// </summary>
 /// <param name="command">Command.</param>
 private void HandleListCommand(string command)
 {
     //Convert from Json.
     this.ListOfGames = FromJsonConverter.GamesList(command);
     ServerResponse   = null;
 }