Ejemplo n.º 1
0
        public void EnterRoom(UserInfoDto userDto) //fixme 顺序问题
        {
            MatchRoomUserInfoDto roomUser = new MatchRoomUserInfoDto()
            {
                ready = false, userInfo = userDto, placeIndex = roomUserList.Count
            };

            roomUserList.Add(roomUser);
            // 直接加入会打乱相对顺序,排序以保证相对顺序与服务器一致。
            roomUserList.Sort((a, b) => a.placeIndex.CompareTo(b.placeIndex));
            ResetPosition();
        }
Ejemplo n.º 2
0
        public MatchRoomDto CreateMatchRoomDto()
        {
            List <MatchRoomUserInfoDto> userInfoDtoList = new List <MatchRoomUserInfoDto>();

            for (int i = 0; i < userOrderList.Count; i++)
            {
                int                  userId      = userOrderList[i];
                RoomUserInfo         info        = userDict[userId];
                UserInfoDto          userInfoDto = DatabaseManager.CreateUserInfoDto(info.client.userId);
                MatchRoomUserInfoDto userDto     = new MatchRoomUserInfoDto(userInfoDto, info.ready, i);
                userInfoDtoList.Add(userDto);
            }
            return(new MatchRoomDto(userInfoDtoList));
        }
Ejemplo n.º 3
0
    /// <summary>
    /// 根据models里面的数据改变UI
    /// improve 冗余的操作多,即使只是改变准备状态都会使所有玩家UI重置一次,而不是精确的改变准备UI。
    /// 但是这样做的优点是可以少写很多方法。
    /// 需求很像Vue的ViewModel,即改变model会以最小的代价改变view
    /// </summary>
    private void RefreshPlayerUI()
    {
        var userList = Models.gameModel.roomModel.roomUserList;

        for (int i = 0; i < userList.Count; i++)
        {
            MatchRoomUserInfoDto user = userList[i];
            ResetPlayerUiByIndex(i, user, true);
        }
        for (int i = userList.Count; i < 3; i++) // 对于房间未满的情况,隐藏剩下位置的用户信息
        {
            ResetPlayerUiByIndex(i, null, false);
        }
    }
Ejemplo n.º 4
0
    private void ResetPlayerUiByIndex(int index, MatchRoomUserInfoDto user, bool show)
    {
        switch (index)
        {
        case 0:
            if (show)
            {
                mainPlayerView.ResetPlayerUI(user);
            }
            break;

        case 1:
            if (show)
            {
                player2View.ShowInfo();
                player2View.ResetPlayerUI(user);
            }
            else
            {
                player2View.HideInfo();
                player2View.HideStatusText();     // 退出房间时,准备提示也要隐藏
            }
            break;

        case 2:
            if (show)
            {
                player3View.ShowInfo();
                player3View.ResetPlayerUI(user);
            }
            else
            {
                player3View.HideInfo();
                player3View.HideStatusText();
            }
            break;
        }
    }