Esempio n. 1
0
    public void rpcFollow(int playerId)
    {
        // 扣除玩家金币
        IEnumerable <LeanCloud.Player> players = Play.Room.Players;

        LeanCloud.Player player = players.FirstOrDefault(p => p.ActorID == playerId);
        int gold = (int)player.CustomProperties[Constants.PROP_GOLD];

        gold -= 100;
        Hashtable goldProp = new Hashtable();

        goldProp.Add(Constants.PROP_GOLD, gold);
        player.CustomProperties = goldProp;

        // 增加房间金币
        int roomGold = (int)Play.Room.CustomProperties[Constants.PROP_ROOM_GOLD];

        roomGold += 100;
        Hashtable prop = new Hashtable();

        prop.Add(Constants.PROP_ROOM_GOLD, roomGold);
        Play.Room.CustomProperties = prop;

        int nextPlayerId = getNextPlayerId(playerId);

        notifyPlayerChoose(nextPlayerId);
    }
Esempio n. 2
0
    void Start()
    {
        this.pokerProvider = new PokerProvider();

        // 绑定 Player 和 GameObject
        List <LeanCloud.Player> playerList = Play.Players.ToList();
        int myIndex = playerList.FindIndex(p => p.IsLocal);
        int offset  = -myIndex;

        for (int i = 0; i < playerList.Count; i++)
        {
            LeanCloud.Player lcPlayer = playerList[i];
            int index = (i + offset + 4) % 4;
            scene.bind(lcPlayer, index);
            ui.bind(lcPlayer, index);
            ui.setPlayerName(lcPlayer, lcPlayer.UserID);
            if (lcPlayer.CustomProperties.ContainsKey(Constants.PROP_STATUS))
            {
                int status = (int)lcPlayer.CustomProperties[Constants.PROP_STATUS];
                ui.setPlayerStatus(lcPlayer, status);
            }
        }
        ui.setUI(Play.Player);

        if (Play.Player.IsMasterClient)
        {
            var p = new Hashtable();
            p.Add(Constants.PROP_STATUS, Constants.PLAYER_STATUS_READY);
            Play.Player.CustomProperties = p;
        }
    }
Esempio n. 3
0
    public void rpcDiscard(int playerId)
    {
        IEnumerable <LeanCloud.Player> players = Play.Room.Players;

        // 设置弃牌玩家状态
        LeanCloud.Player player = players.FirstOrDefault(p => p.ActorID == playerId);
        if (player != null)
        {
            Hashtable prop = new Hashtable();
            prop.Add(Constants.PROP_STATUS, Constants.PLAYER_STATUS_DISCARD);
            player.CustomProperties = prop;
        }
        // 从当前玩家列表中移除
        playerIdList.Remove(playerId);

        if (playerIdList.Count > 1)
        {
            // 请下一个玩家做出选择
            int nextPlayerId = getNextPlayerId(playerId);
            notifyPlayerChoose(nextPlayerId);
        }
        else
        {
            // 剩者为王
            int winnerId = playerIdList.First.Value;
            Play.RPC("rpcResult", PlayRPCTargets.All, winnerId);
        }
    }
Esempio n. 4
0
    void notifyPlayerChoose(int playerId)
    {
        IEnumerable <LeanCloud.Player> players = Play.Room.Players;

        LeanCloud.Player player = players.FirstOrDefault <LeanCloud.Player>((p) => p.ActorID == playerId);
        Play.RPC("rpcChoose", PlayRPCTargets.All, playerId);
    }
Esempio n. 5
0
    public override void OnNewPlayerJoinedRoom(LeanCloud.Player player)
    {
        Debug.Log("someone joined room");
        List <LeanCloud.Player> playerList = Play.Players.ToList();
        int myIndex = playerList.FindIndex(p => p.IsLocal);
        int index   = playerList.FindIndex(p => p.UserID == player.UserID);
        int offset  = index - myIndex;

        scene.bind(player, offset);
        ui.bind(player, offset);
        ui.setPlayerName(player, player.UserID);
    }
Esempio n. 6
0
    public Player GetPlayer(LeanCloud.Player lcPlaer)
    {
        Player player = null;

        if (playerDict.TryGetValue(lcPlaer.UserID, out player))
        {
            return(player);
        }
        // TODO Exception

        return(null);
    }
Esempio n. 7
0
    public void setPlayerStatus(LeanCloud.Player player, int status)
    {
        PlayerUI playerUI = null;

        if (playerUIDict.TryGetValue(player.UserID, out playerUI))
        {
            playerUI.setStatus(status);
        }
        else
        {
            // Exception
            Debug.LogError("not found player ui: " + player.UserID);
        }
    }
Esempio n. 8
0
    public void draw(LeanCloud.Player lcPlayer, Poker[] pokers)
    {
        Player player = null;

        if (playerDict.TryGetValue(lcPlayer.UserID, out player))
        {
            player.draw(lcPlayer, pokers);
        }
        else
        {
            // exception
            Debug.LogError("no player: " + lcPlayer.UserID);
        }
    }
Esempio n. 9
0
    public void updateGoldUI(LeanCloud.Player player, int gold)
    {
        PlayerUI playerUI = null;

        if (playerUIDict.TryGetValue(player.UserID, out playerUI))
        {
            playerUI.setGold(gold);
        }
        else
        {
            // Exception
            Debug.LogError("not found player ui: " + player.UserID);
        }
    }
Esempio n. 10
0
    void onPlayerPokerPropertiesChanged(LeanCloud.Player player, Hashtable updatedProperties)
    {
        string pokersJson = player.CustomProperties[Constants.PROP_POKER] as string;

        Poker[] pokers = JsonConvert.DeserializeObject <Poker[]>(pokersJson);
        if (player.IsLocal)
        {
            scene.draw(player, pokers);
        }
        else
        {
            scene.draw(player, pokers);
        }
    }
Esempio n. 11
0
    public void setPlayerName(LeanCloud.Player player, string name)
    {
        PlayerUI playerUI = null;

        if (playerUIDict.TryGetValue(player.UserID, out playerUI))
        {
            playerUI.setName(name);
        }
        else
        {
            // Exception
            Debug.LogError("not found player ui: " + player.UserID);
        }
    }
Esempio n. 12
0
 // 接口
 public void setUI(LeanCloud.Player lcPlayer)
 {
     if (lcPlayer.IsMasterClient)
     {
         Text text = this.startOrReadyButton.GetComponentInChildren <Text>();
         text.text = "Start";
         this.startOrReadyButton.onClick.AddListener(onStartButtonClicked);
         this.startOrReadyButton.interactable = false;
     }
     else
     {
         Text text = this.startOrReadyButton.GetComponentInChildren <Text>();
         text.text = "Ready";
         this.startOrReadyButton.onClick.AddListener(onReadyButtonClicked);
     }
 }
Esempio n. 13
0
    public void rpcCompare()
    {
        var playersByScoreOrder = Play.Players.Where(p =>
        {
            int status = (int)p.CustomProperties[Constants.PROP_STATUS];
            return(status == Constants.PLAYER_STATUS_PLAY);
        }).OrderByDescending(p =>
        {
            // 查找
            Player player = scene.GetPlayer(p);
            return(player.getScore());
        });

        LeanCloud.Player winPlayer = playersByScoreOrder.FirstOrDefault();
        Play.RPC("rpcResult", PlayRPCTargets.All, winPlayer.ActorID);
    }
Esempio n. 14
0
 public override void OnPlayerLeftRoom(LeanCloud.Player player)
 {
     Debug.Log("someone left room");
     if (Play.IsMasterClient)
     {
         int status = (int)player.CustomProperties[Constants.PROP_STATUS];
         if (status == Constants.PLAYER_STATUS_PLAY)
         {
             // 玩家正在游戏中,重新生成玩家列表
             rpcDiscard(player.ActorID);
         }
         else
         {
             // 移除处理
         }
     }
 }
Esempio n. 15
0
 public override void OnPlayerCustomPropertiesChanged(LeanCloud.Player player, Hashtable updatedProperties)
 {
     foreach (var key in updatedProperties.Keys)
     {
         string keyStr = key as string;
         if (keyStr == Constants.PROP_STATUS)
         {
             onPlayerStatusPropertiesChanged(player, updatedProperties);
         }
         else if (keyStr == Constants.PROP_POKER)
         {
             onPlayerPokerPropertiesChanged(player, updatedProperties);
         }
         else if (keyStr == Constants.PROP_GOLD)
         {
             onPlayerGoldPropertiesChanged(player, updatedProperties);
         }
     }
 }
Esempio n. 16
0
 public void draw(LeanCloud.Player player, Poker[] pokers)
 {
     this.gameObject.SetActive(true);
     this.lcPlayer  = player;
     this.pokers    = pokers;
     this.pokerType = PokerType.CalcPokerType(this.pokers);
     for (int i = 0; i < pokers.Length; i++)
     {
         Poker   poker   = this.pokers[i];
         PokerVC pokerVC = this.pokerVCs[i];
         if (this.lcPlayer == Play.Player)
         {
             pokerVC.show(poker);
         }
         else
         {
             pokerVC.showBack();
         }
     }
 }
Esempio n. 17
0
    void onPlayerStatusPropertiesChanged(LeanCloud.Player player, Hashtable updatedProperties)
    {
        // 刷新玩家 UI
        int status = (int)updatedProperties[Constants.PROP_STATUS];

        ui.setPlayerStatus(player, status);
        if (Play.Player.IsMasterClient)
        {
            // 计算得到「准备」玩家的数量
            int readyPlayersCount = Play.Players.Where(p =>
            {
                int s = (int)p.CustomProperties[Constants.PROP_STATUS];
                return(s == Constants.PLAYER_STATUS_READY);
            }).Count();
            if (readyPlayersCount > 1 && readyPlayersCount == Play.Players.Count())
            {
                ui.enableStartButton();
            }
        }
    }
Esempio n. 18
0
    public void draw(int playerIndex, LeanCloud.Player lcPlayer, Poker[] pokers)
    {
        Player player = this.players[playerIndex];

        player.draw(lcPlayer, pokers);
    }
Esempio n. 19
0
    public void bind(LeanCloud.Player lclayer, int index)
    {
        Player player = players[index];

        playerDict.Add(lclayer.UserID, player);
    }
Esempio n. 20
0
    public void bind(LeanCloud.Player lcPlayer, int index)
    {
        PlayerUI playerUI = playerUIs[index];

        playerUIDict.Add(lcPlayer.UserID, playerUI);
    }
Esempio n. 21
0
    void onPlayerGoldPropertiesChanged(LeanCloud.Player player, Hashtable updatedProperties)
    {
        int gold = (int)updatedProperties[Constants.PROP_GOLD];

        ui.updateGoldUI(player, gold);
    }