Ejemplo n.º 1
0
        /// <summary>
        /// 抢地主处理
        /// </summary>
        private void GrabLandLord(ClientPeer client, bool result)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (user.IsOnLine(client) == false)
                {
                    return;
                }

                int userId     = user.GetIdByClient(client);
                FightRoom room = fight.GetRoomByUid(userId);
                if (result == true)
                {
                    //抢
                    room.SetLandlord(userId);
                    GrabDto grab = new GrabDto(userId, room.TableCardList, room.GetPlayerCard(userId));
                    //广播  谁是地主  三张底牌
                    Brocast(room, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BRO, grab);
                    //发送一个出牌的命令
                    Brocast(room, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, userId);
                }
                else
                {
                    //不抢
                    int nextUid = room.GetNextUid(userId);
                    Brocast(room, OpCode.FIGHT, FightCode.TURN_GRAB__BRO, nextUid);
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 出牌的处理
        /// </summary>
        private void Deal(ClientPeer client, DealDto dto)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                //玩家在线
                if (user.IsOnLine(client) == false)
                {
                    return;
                }

                int userId = user.GetIdByClient(client);

                if (userId != dto.userId)      //DTO的ID可以用来做验证。
                {
                    return;
                }
                FightRoom room = fight.GetRoom(userId);
                //玩家出牌
                //掉线  在线
                if (room.LeaveUidList.Contains(userId))
                {
                    //自动出牌
                    Turn(room);
                }
                //玩家在线
                bool canDeal = room.DealCard(dto.length, dto.type, dto.weight, userId, dto.selectCardList);
                if (canDeal == false)
                {
                    //压不住
                    client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1);
                    return;
                }
                else
                {
                    //发送给出牌者
                    client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, 0);
                    List <CardDto> remainCardList = room.GetPlayerCard(userId);
                    dto.remainCardList            = remainCardList;
                    //广播
                    Brocast(room, OpCode.FIGHT, FightCode.DEAL_BRO, dto);
                    //检测下 剩余牌  为0 就赢了
                    if (remainCardList.Count == 0)
                    {
                        //游戏结束
                        GameOver(userId, room);
                    }
                    else
                    {
                        //转换玩家
                        Turn(room);
                    }
                }
            }
                );
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 开始战斗
 /// </summary>
 /// <param name="uIdList"></param>
 public void StartFight(List <int> uIdList)
 {
     SingleExecute.Instance.Execute
     (
         delegate()
     {
         //创建战斗房间
         FightRoom room = fight.CreatRoom(uIdList);
         //创建牌  并排序
         room.InitPlayerCards();
         room.Sort();
         //发送给每个客户端 自身有什么牌
         foreach (int uId in uIdList)
         {
             ClientPeer client       = user.GetClientById(uId);
             List <CardDto> cardList = room.GetPlayerCard(uId);
             client.Send(OpCode.FIGHT, FightCode.GET_CARD_SRES, cardList);
         }
         //发送开始抢地主响应
         int firstUserId = room.GetFirstUid();
         Brocast(room, OpCode.FIGHT, FightCode.TURN_GRAB__BRO, firstUserId, null);
     }
     );
 }