Esempio n. 1
0
    private void GameInfoResponse(ResponseOrError <GameInfo> responseOrError)
    {
        if (responseOrError.IsSuccess)
        {
            GameInfo response = responseOrError.Response;
            UpdateView(response);

            if (response.PlayersNow == response.PlayersMax)
            {
                print("all players are present, ready to start");

                if (response.CreatorNickName == playerNickName)
                {
                    CreateAndSendGameState(response);
                }
                else
                {
                    SceneLoader.LoadGameReadyScene();
                }
            }
            else
            {
                Invoke("GetGameInfo", 2);
            }
        }
        else
        {
            Invoke("GetGameInfo", 2);
        }
    }
 private void GameStateResponse(ResponseOrError <GameState> responseOrError)
 {
     if (responseOrError.IsSuccess)
     {
         responseOrError.Response.SaveGameState();
         Invoke("OpenMainGameBoard", 1);
     }
     else
     {
         print("cannot get game state, retry in 3 sec");
         Invoke("GetGameState", 2);
     }
 }
    private void AllGameInfosResponse(ResponseOrError <List <GameInfo> > responseOrError)
    {
        if (responseOrError.IsSuccess)
        {
            CleanGarbageCollector();

            List <GameInfo> info = responseOrError
                                   .Response
                                   .FindAll((obj) =>
                                            obj.CreatorNickName != PlayerNickName &&
                                            obj.Available &&
                                            obj.PlayersNow < obj.PlayersMax);

            if (info.IsEmpty())
            {
                string text = "no games available";
                var    obj  = CardsGenerator.DrawObjectWithTextFromPrefab(new Vector2(0, 0), "DefaultTextWhite", text);
                GarbageCollector.Add(obj);
            }
            else
            {
                for (int i = 0; i < info.Count; i++)
                {
                    GameInfo game   = info[i];
                    float    y      = StartingAxisY - i * SpaceBetweenTexts;
                    string   text   = game.CreatorNickName + "'s game, players " + game.PlayersNow + "/" + game.PlayersMax;
                    var      obj    = CardsGenerator.DrawObjectWithTextFromPrefab(new Vector2(0, y), "DefaultTextWhite", text);
                    var      script = obj.AddComponent <ClickActionScript>();
                    script.ClickMethod    = OnGameItemClick;
                    script.ClickParameter = game;
                    GarbageCollector.Add(obj);
                }
            }
        }

        Invoke("GetAvailableGames", 2);
    }
Esempio n. 4
0
    private void GameStateResponse(ResponseOrError <GameState> responseOrError)
    {
        if (responseOrError.IsSuccess)
        {
            var newGameState = responseOrError.Response;

            if (!GSP.GameState.IsEqualTo(newGameState))
            {
                newGameState.SaveGameState();
                UpdateUI();
                print("game state has changed... how refreshing");
            }
            else
            {
                print("game state hasn't changed");
            }

            CheckTheTurn();
        }
        else
        {
            CheckTheTurn();
        }
    }