예제 #1
0
    void UpdateResultGui(CasinoWarPlayer player)
    {
        Hashtable table = (Hashtable)PhotonNetwork.CurrentRoom.CustomProperties["table"];
        Text      actorField;

        for (int seat = 1; seat <= 5; seat++)
        {
            if ((int)table[seat] == player.getActorID())
            {
                actorField      = Seats.transform.GetChild(ComputeSlot(seat)).GetChild(1).gameObject.GetComponent <Text>();
                actorField.text = "Card: " + player.getMycard().ToString() +
                                  "\nWin Result: " + player.getResult();
            }
        }
        if (player.getActorID() == PhotonNetwork.LocalPlayer.ActorNumber)
        {
            if (player.getResult() == 2)
            {
                WarButton.gameObject.SetActive(true);
            }
            PlayerSingleton.GetPlayer().setCredit(player.getNewCredit());
            PhotonNetwork.SetPlayerCustomProperties(new Hashtable()
            {
                { "credit", player.getNewCredit() }
            });
            UpdatePlayerGui(PhotonNetwork.LocalPlayer);
            UpdateUserInfoText();
            // UpdatePlayerGui(PhotonNetwork.LocalPlayer);
        }
    }
예제 #2
0
    public void DoBet()
    {
        if ((int)PhotonNetwork.LocalPlayer.CustomProperties["bet"] != 0 || (int)PhotonNetwork.CurrentRoom.CustomProperties["phase"] == 2 || (int)PhotonNetwork.CurrentRoom.CustomProperties["phase"] == 4)
        {
            return;
        }
        byte evCode = 66;

        CasinoWarPlayer player = PlayerSingleton.GetPlayer();

        player.setBet(100);
        player.setActorNumber(PhotonNetwork.LocalPlayer.ActorNumber);
        PhotonNetwork.SetPlayerCustomProperties(new Hashtable()
        {
            { "bet", 100 }
        });

        string playerString = JsonUtility.ToJson(player);

        UpdatePlayerGui(PhotonNetwork.LocalPlayer);

        Debug.Log(playerString);
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.All
        };                                                                                             // You would have to set the Receivers to All in order to receive this event on the local client as well
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent(evCode, playerString, raiseEventOptions, sendOptions);
    }
예제 #3
0
    public void LoginOnClick()
    {
        string          userid = inputField.text;
        string          url    = "http://107.21.13.205/api/values/" + userid;
        CasinoWarPlayer player = new CasinoWarPlayer();

        if ((player = JsonUtility.FromJson <CasinoWarPlayer>(Get(url))) != null)
        {
            // you know that the parsing attempt
            // was successful

            //PlayerSingleton.SetPlayer(userid, credit);

            Debug.Log(Get(url) + "\n" + JsonUtility.ToJson(player));
            PlayerPrefs.SetString("userid", userid);
            PlayerPrefs.SetString("username", player.getUserName());

            SceneManager.LoadScene(sceneName: "TestScene");
            PlayerSingleton.SetPlayer(player);
            Debug.Log("login as " + player.getUserName() + "credit: " + player.getNewCredit());
        }
        else
        {
            Debug.Log("invalid userid");
        }
    }
예제 #4
0
    void UpdateUserInfoText()
    {
        CasinoWarPlayer player = PlayerSingleton.GetPlayer();

        UserInfoText.text = "User ID: " + player.getID() +
                            "\nUser Name: " + player.getUserName() +
                            "\nCredit: " + player.getNewCredit();
    }
예제 #5
0
    public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
    {
        base.OnRoomPropertiesUpdate(propertiesThatChanged);
        if (propertiesThatChanged.ContainsKey("timer"))
        {
            this.InfoText.text = PhotonNetwork.CurrentRoom.CustomProperties["timer"].ToString();
        }
        if (propertiesThatChanged.ContainsKey("phase"))
        {
            //leave when didn't bet on times
            if ((int)propertiesThatChanged["phase"] == 2)
            {
                PhaseText.color = Color.yellow;
            }
            else if ((int)propertiesThatChanged["phase"] == 0)
            {
                WarButton.gameObject.SetActive(false);
                PhaseText.color = Color.white;
                ResetAllResults();
                DealerCardText.text = "";
            }
            else if ((int)propertiesThatChanged["phase"] == 1)
            {
                PhaseText.color = Color.red;
            }
            else if ((int)propertiesThatChanged["phase"] == 3)
            {
                PhaseText.color = Color.red;
            }
            else if ((int)propertiesThatChanged["phase"] == 4)
            {
                WarButton.gameObject.SetActive(false);
                PhaseText.color = Color.green;
            }

            if ((int)propertiesThatChanged["phase"] == 2 && (int)PhotonNetwork.LocalPlayer.CustomProperties["bet"] == 0)
            {
                //kicked by server
            }
            this.PhaseText.text = "Phase " + PhotonNetwork.CurrentRoom.CustomProperties["phase"].ToString();
        }
        if (propertiesThatChanged.ContainsKey("resultTable"))
        {
            Hashtable resultTable = (Hashtable)propertiesThatChanged["resultTable"];

            Debug.Log(resultTable.Keys.Count);
            CasinoWarCardImpl card = JsonUtility.FromJson <CasinoWarCardImpl>(resultTable["dealercard"].ToString());
            DealerCardText.text = "Dealer's Card: " + card.ToString();

            foreach (Player player in PhotonNetwork.PlayerList)
            {
                if (resultTable.ContainsKey(player.ActorNumber))
                {
                    CasinoWarPlayer casinoPlayer = JsonUtility.FromJson <CasinoWarPlayer>(resultTable[player.ActorNumber].ToString());
                    UpdateResultGui(casinoPlayer);
                }
            }
        }
        if (propertiesThatChanged.ContainsKey("WarTable"))
        {
            Hashtable WarTable = (Hashtable)propertiesThatChanged["WarTable"];

            CasinoWarCardImpl card = JsonUtility.FromJson <CasinoWarCardImpl>(WarTable["dealercard"].ToString());
            DealerCardText.text = "Dealer's Card: " + card.ToString();

            foreach (Player player in PhotonNetwork.PlayerList)
            {
                if (WarTable.ContainsKey(player.ActorNumber))
                {
                    CasinoWarPlayer casinoPlayer = JsonUtility.FromJson <CasinoWarPlayer>(WarTable[player.ActorNumber].ToString());
                    UpdateResultGui(casinoPlayer);
                }
                else
                {
                    ResetResult(ComputeSlot((int)player.CustomProperties["seat"]));
                }
            }
        }
    }
예제 #6
0
 public static void SetPlayer(CasinoWarPlayer player)
 {
     PlayerSingleton.player = player;
 }