public void CreateAccount(string username, string password)
 {
     createAccountPresenter.Interactable = false;
     databaseService.AddUser(username, password, result => {
         createAccountPresenter.Interactable = true;
         if (result == StatusCode.OK)
         {
             NavigateToLogin();
             statusPresenter.SetStatus("Account created.", StatusPresenter.COLOR_SUCCESS);
         }
         else
         {
             statusPresenter.SetStatus(StatusText.For(result), StatusPresenter.COLOR_ERROR);
         }
     });
 }
 public void Login(string username, string password)
 {
     loginPresenter.Interactable = false;
     databaseService.LoginUser(username, password, result => {
         loginPresenter.Interactable = true;
         if (result == StatusCode.OK)
         {
             currentUser = username;
             NavigateToJoinCreateGame();
             statusPresenter.SetStatus("Logged in.", StatusPresenter.COLOR_SUCCESS);
         }
         else
         {
             statusPresenter.SetStatus(StatusText.For(result), StatusPresenter.COLOR_ERROR);
         }
     });
 }
    private void ShowGameStatus(StatusCode status)
    {
        switch (status)
        {
        case StatusCode.GAME_YOU_LOST:
            statusPresenter.SetStatus(StatusText.For(status), StatusPresenter.COLOR_ERROR, false);
            break;

        case StatusCode.GAME_YOU_WIN:
            statusPresenter.SetStatus(StatusText.For(status), StatusPresenter.COLOR_SUCCESS, false);
            break;

        case StatusCode.GAME_DRAW:
            statusPresenter.SetStatus(StatusText.For(status), StatusPresenter.COLOR_NOTICE, false);
            break;

        default:
            statusPresenter.SetStatus(StatusText.For(status), StatusPresenter.COLOR_ERROR);
            break;
        }
    }
    public void CreateGame()
    {
        if (currentUser == null)
        {
            return;
        }

        createOrJoinGamePresenter.Interactable = false;
        databaseService.CreateGame(currentUser, (result, gameId) => {
            createOrJoinGamePresenter.Interactable = true;
            if (result == StatusCode.OK)
            {
                currentGameId = gameId;
                Debug.Log("Game created: " + gameId);
                playingFieldPresenter.Clear();
                NavigateToPlayingField();
                statusPresenter.SetStatus("Game created.", StatusPresenter.COLOR_SUCCESS);
                databaseService.RegisterForGameUpdates(gameId, gameState => {
                    playingFieldPresenter.SetGameState(gameState);

                    StatusCode status = gameState.CanMakeMove(currentUser);
                    if (status != StatusCode.OK && status != StatusCode.GAME_NOT_YOUR_TURN)
                    {
                        ShowGameStatus(status);
                    }
                });
                databaseService.RegisterForChatUpdates(gameId, chatState => {
                    playingFieldPresenter.SetChatState(chatState);
                });
            }
            else
            {
                statusPresenter.SetStatus(StatusText.For(result), StatusPresenter.COLOR_ERROR);
            }
        });
    }