Exemplo n.º 1
0
 void winner(BasePlayer player)
 {
     winnerPanel.SetActive(true);
     winnerPanel.GetComponent <WinnerClass>().showWinner(player.getName(), true);
     winAnimation.SetActive(true);
     LudoDelegate.playClapSound();
 }
Exemplo n.º 2
0
        void onGotiWin(int index, string playerID)
        {
            BasePlayer player = this.getPlayerByID(playerID);

            if (player != null)
            {
                Debug.Log("Working");
                winAnimation.SetActive(true);
                LudoDelegate.playClapSound();
                StartCoroutine(stopAnimation());
            }
            if (PlayerPrefs.GetInt(LudoTags.GAME_TYPE) == LudoTags.OFFLINE)
            {
                this.reChance = true;
            }
        }
Exemplo n.º 3
0
        void onReceivedServerMessage(string sender, string message)
        {
            try{
                JSONNode s = JSON.Parse(message);
                switch (s[ServerTags.TAG])
                {
                case ServerTags.ROOM_INFO:
                {
                    JSONNode pl     = s[ServerTags.ROOM_DATA];
                    string   player = PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID);
                    for (int i = 0; i < pl.Count; i++)
                    {
                        JSONNode   data         = pl[i];
                        BasePlayer playerObject = this.getPlayerByColor(int.Parse(data[ServerTags.COLOR]));
                        if (playerObject != null)
                        {
                            Debug.Log(data[ServerTags.DISPLAY_NAME] + "assign " + data[ServerTags.PIC]);

                            string imageName  = "1";
                            string playerName = "";
                            string color      = "1";
                            try{
                                imageName = data[ServerTags.PIC];
                                if (imageName.Equals(""))
                                {
                                    imageName = "1";
                                }
                            }catch (System.Exception ex) {
                                imageName = "1";
                            }
                            try
                            {
                                color = data[ServerTags.COLOR];
                            }
                            catch (System.Exception ex)
                            {
                                color = "1";
                            }
                            try
                            {
                                playerName = UppercaseFirst(data[ServerTags.DISPLAY_NAME]);
                            }
                            catch (System.Exception ex)
                            {
                                playerName = "";
                            }
                            LudoDelegate.usedColor(UppercaseFirst(playerName), int.Parse(color));
                            try
                            {
                                playerObject.setPlayer(UppercaseFirst(playerName), data[ServerTags.PLAYER_ID], false, imageName);
                            }catch (System.Exception ex) {
                                Debug.Log(ex.Message + " " + UppercaseFirst(playerName) + "  " + data[ServerTags.PLAYER_ID] + "  " + imageName);
                            }
                        }
                        else
                        {
                            Debug.Log("No player Found");
                        }
                    }
                }

                break;

                case ServerTags.START_DEAL:
                {
                    LudoDelegate.gamePlay();
                    LudoController.isGameStart = true;
                }
                break;


                case ServerTags.TURN:
                {
                    for (int i = 0; i < 4; i++)
                    {
                        playerList[i].stopTurnAnimation();
                    }
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        player.TurnAnimation();
                    }

                    LudoDelegate.changeTurn(s[Tags.PLAYER]);
                }
                break;

                case ServerTags.TIMER:
                {
                    timerPanel.SetActive(true);
                    timerPanel.GetComponent <TimerScript>().startTimer(int.Parse(s[Tags.VALUES]));
                }
                break;

                case ServerTags.STOP_TIMER:
                {
                    timerPanel.SetActive(false);
                }
                break;

                case ServerTags.SMILEY:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        player.showSmiley(s[Tags.VALUES]);
                    }
                }

                break;



                case ServerTags.MESSAGE:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        player.showMessage(s[Tags.VALUES]);
                    }
                }

                break;


                case ServerTags.DICE_ROLL:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        Debug.Log("DICE_ROLL " + player.getUser());
                        if (player.getUser().Equals(PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID)))
                        {
                            player.playerTurn(int.Parse(s[Tags.VALUES]), true);
                        }
                        else
                        {
                            player.playerTurn(int.Parse(s[Tags.VALUES]), false);
                        }
                    }
                }
                break;


                case ServerTags.TOTAL_DICE:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        JSONArray sd = new JSONArray();
                        JSONNode  pl = s[Tags.VALUES];
                        for (int i = 0; i < pl.Count; i++)
                        {
                            sd.Add("" + pl[i]);
                        }
                        player.setNewTurnValue(sd);
                    }
                }
                break;

                case ServerTags.MOVE_GOTI:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        player.MoveGoti(int.Parse(s[Tags.INDEX]), int.Parse(s[Tags.LAST_POSITION]), int.Parse(s[Tags.TO_POSITION]));
                    }
                }
                break;

                case ServerTags.GOTI_WIN:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        Debug.Log("Working");
                        winAnimation.SetActive(true);
                        StartCoroutine(stopAnimation());
                        player.WinGoti(int.Parse(s[Tags.INDEX]));
                        LudoDelegate.playClapSound();
                    }
                }
                break;


                case ServerTags.READY_GOTI:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null)
                    {
                        player.readyGoti(int.Parse(s[Tags.INDEX]), s["STEPS"]);
                    }
                }
                break;

                case ServerTags.REMOVE_PLAYER:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null && player.getUser().Equals(PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID)))
                    {
                        if (!LudoController.isGameStart)
                        {
                            SceneManager.LoadSceneAsync("LobiScene");
                        }
                    }
                }
                break;

                case ServerTags.LEAVE_TABLE:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null && player.getUser().Equals(PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID)))
                    {
                        SceneManager.LoadSceneAsync("LobiScene");
                    }
                }
                break;



                case Tags.DICE_ROLL_DONE:
                {
                    BasePlayer player = this.getPlayerByID(s[Tags.PLAYER]);
                    if (player != null && !player.getUser().Equals(PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID)))
                    {
                        Debug.Log("startDiceAnimation " + player.getUser());
                        player.startDiceAnimation(int.Parse(s[Tags.VALUES]));
                    }
                    if (player != null)
                    {
                        player.addNumberInTurn(int.Parse(s[Tags.VALUES]));
                    }
                }
                break;

                case Tags.WINNER_PLAYER:
                {
                    string player_name = PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID);
                    string node        = s["PLAYER"];
                    string player_id   = s["PLAYER_ID"];
                    string Wincoin     = s["VALUE"];
                    if (player_id.Equals(player_name))
                    {
                        winnerPanel.SetActive(true);
                        winnerPanel.GetComponent <WinnerClass>().showWinner(node, true);
                        winAnimation.SetActive(true);
                        LudoDelegate.playClapSound();
                    }
                    else
                    {
                        lossPanel.SetActive(true);
                    }
                }

                break;

                case Tags.LOSS_GAME:
                {
                    string player_name = PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID);
                    string displayName = s["PLAYER"];
                    string player      = s["VALUE"];
                    if (player_name.Equals(player))
                    {
                        lossPanel.SetActive(true);
                    }
                }
                break;

                case ServerTags.ROOM_PRICE:
                {
                    try
                    {
                        string player = PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_ID);
                        if (player.Equals(s[ServerTags.PLAYER_ID]))
                        {
                            int fee = int.Parse(s[ServerTags.VALUES]);
                            if (fee > int.Parse(PlayerPrefs.GetString(GetPlayerDetailsTags.PLAYER_COIN)))
                            {
                                CoinValidationPanel.SetActive(true);
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.Log(ex.Message);
                    }
                }


                break;

                default:
                    break;
                }
            }
            catch (System.Exception ex)
            {
                Debug.Log(ex.Message);
            }
        }