/// <summary> /// 分牌后要下一组牌 /// </summary> /// <param name="client"></param> private void splitNext(ClientPeer client) { SingleExecute.Instance.Execute( () => { if (userCache.IsOnline(client) == false) { return; } int userId = userCache.GetId(client); if (fightCache.IsInRoom(userId) == false) { return; } //一定要注意安全的验证 _21MutiFightRoom room = fightCache.GetRoom(userId); //发下一组牌 room.NextHandCardByUId(userId); //获取分牌后的下一组手牌 List <CardDto> cardList = room.GetUserCardsByUserId(userId); //广播发送一下手牌 SplitBroDto sbdto = new SplitBroDto(); sbdto.userId = userId; sbdto.position = room.getPosition(userId); sbdto.cardList = cardList; //分牌和 下一手用的一个code brocast(room, OpCode._21Multi, _21MultiCode.SPLIT_BRO, sbdto, null); //和开始游戏后进行一样的判断 //21点 直接赢了 if (room.is21ByUserId(userId)) { //记录一下这组牌 room.SaveListByUserId(userId, 1, false); int position = room.getPosition(userId); OverHandDto ohdto = new OverHandDto(userId, position, 1); brocast(room, OpCode._21Multi, _21MultiCode.OVER_HAND_BRO, ohdto, null); //该下一个玩家了 turnPlayer(userId, position, room); } //能够分牌 if (room.isCanSplitByUserId(userId)) { TurnHandDto thdto = new TurnHandDto(true, userId); client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); //brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } else { TurnHandDto thdto = new TurnHandDto(false, userId); client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); //brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } } ); }
/// <summary> /// /// </summary> /// <param name="lastUserId"></param> /// <param name="lastPosition"></param> /// <param name="room"></param> private void turnPlayer(int lastUserId, int lastPosition, _21MutiFightRoom room) { ClientPeer client = userCache.GetClientPeer(lastUserId); //是不是分过牌 并且还有牌 有牌还是给他发牌 if (room.isHaveNextHand(lastUserId)) { client.Send(OpCode._21Multi, _21MultiCode.SPLIT_CAN_NEXT_SRES, null); } //没有了的话 就下一个玩家开始操作 else { int nextUid = room.GetNextUId(lastUserId); room.SetPlayingUId(nextUid); //没有下一个玩家了 if (nextUid == -1) { //room.SetPlayingUId(-1); //todo 庄家的操作 gameOver(room); } else { //和刚开始差不多 if (room.is21ByUserId(nextUid))//21点 直接赢了 { //记录一下这组牌 room.SaveListByUserId(nextUid, 1, false); int position = room.getPosition(nextUid); OverHandDto ohdto = new OverHandDto(nextUid, position, 1); brocast(room, OpCode._21Multi, _21MultiCode.OVER_HAND_BRO, ohdto, null); //该下一个玩家了 turnPlayer(nextUid, position, room); } else if (room.isCanSplitByUserId(nextUid))//能够分牌 { TurnHandDto thdto = new TurnHandDto(true, nextUid); //client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } else { TurnHandDto thdto = new TurnHandDto(false, nextUid); //client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } } } }
private void StartFight(int roomId) { //房间设置为开始 fightCache.SetRoomPlayByRoomId(roomId); _21MutiFightRoom room = fightCache.GetRoomByRoomId(roomId); //初始发牌 InitCardDto initCardDto = room.InitPlayerCards(); brocast(room, OpCode._21Multi, _21MultiCode.INIT_CARD_BRO, initCardDto, null); //发送开始HIT或STAND的响应 int firstUserId = room.GetFirstUId(); room.SetPlayingUId(firstUserId); if (room.is21ByUserId(firstUserId))//21点 直接赢了 { //记录一下这组牌 room.SaveListByUserId(firstUserId, 1, false); int position = room.getPosition(firstUserId); OverHandDto ohdto = new OverHandDto(firstUserId, position, 1); brocast(room, OpCode._21Multi, _21MultiCode.OVER_HAND_BRO, ohdto, null); //该下一个玩家了 turnPlayer(firstUserId, position, room); } else { if (room.isCanSplitByUserId(firstUserId))//能够分牌 { TurnHandDto thdto = new TurnHandDto(true, firstUserId); //client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } else { TurnHandDto thdto = new TurnHandDto(false, firstUserId); //client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } } }
/// <summary> /// 离开 /// </summary> /// <param name="client"></param> private void leave(ClientPeer client) { SingleExecute.Instance.Execute( delegate() { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); //用户没有匹配 不能退出 非法操作 if (fightCache.IsInRoom(userId) == false) { //client.Send(OpCode.MATCH, MatchCode.LEAVE_SRES, -1); return; } //在战斗的时候离开 if (fightCache.IsInPlaying(userId)) { _21MutiFightRoom room = fightCache.GetRoom(userId); //加入到离开链表里 room.LeaveUIdList.Add(userId); //广播一下离开的用户 room.Brocast(OpCode._21Multi, _21MultiCode.LEAVE_BRO, userId); //如果在处理的时候离开了 换下一个 if (userId == room.playingUserId) { int nextUid = room.GetNextUId(userId); room.SetPlayingUId(nextUid); //没有下一个玩家了 if (nextUid == -1) { //room.SetPlayingUId(-1); //todo 庄家的操作 gameOver(room); } else { //和刚开始差不多 if (room.is21ByUserId(nextUid)) //21点 直接赢了 { //记录一下这组牌 room.SaveListByUserId(nextUid, 1, false); int position = room.getPosition(nextUid); OverHandDto ohdto = new OverHandDto(nextUid, position, 1); brocast(room, OpCode._21Multi, _21MultiCode.OVER_HAND_BRO, ohdto, null); //该下一个玩家了 turnPlayer(nextUid, position, room); } if (room.isCanSplitByUserId(nextUid)) //能够分牌 { TurnHandDto thdto = new TurnHandDto(true, nextUid); //client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } else { TurnHandDto thdto = new TurnHandDto(false, nextUid); //client.Send(OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto); brocast(room, OpCode._21Multi, _21MultiCode.TURN_HS_BRO, thdto, null); } } } } //未战斗的时候离开 else { //正常离开 _21MutiFightRoom room = fightCache.Leave(userId); //广播给房间内所有人 有人离开了 参数:离开的用户id room.Brocast(OpCode._21Multi, _21MultiCode.LEAVE_BRO, userId); } Console.WriteLine("有玩家离开房间"); }); }