/// <summary> /// 创建一副牌 /// </summary> public static List <BaseCard> CreatCardLibrary() { /// <summary> /// 牌库队列 /// </summary> List <BaseCard> cardQueue = new List <BaseCard>(); CardColors colors; CardWeight weight; int id = 0; for (int i = 0; i < 13; i++) //牌的权值数目 { for (int j = 0; j < 2; j++) //牌色 { colors = (CardColors)j; weight = (CardWeight)i; BaseCard card = new BaseCard(colors.ToString() + weight.ToString(), id, colors, weight, CardBelongTo.ZERO, CardDisplay.False); //创建一张 cardQueue.Add(card); //入队 id++; } } //for (int i = 0; i < cardQueue.Count; i++) //{ // Console.WriteLine(cardQueue[i].CardId+ cardQueue[i].CardName); //} return(cardQueue); }
/// <summary> /// 发单摸结果 /// </summary> /// <param name="secondCommand"></param> /// <param name="roomInfo"></param> /// <param name="cardIndex">所摸牌在桌牌中的下标</param> /// <param name="card">所摸牌</param> void ForeachSendDraw(int secondCommand, RoomInfo roomInfo, int cardIndex, BaseCard card) { byte[] data_1 = BitConverter.GetBytes(cardIndex); byte[] data_3; if (card == null) { data_3 = new byte[0]; } else { data_3 = DataDo.Object2Json(card); } byte[] datas = new byte[data_1.Length + data_3.Length]; Buffer.BlockCopy(data_1, 0, datas, 0, 4); Buffer.BlockCopy(data_3, 0, datas, 4, data_3.Length); Conn conn; Console.WriteLine("----roomInfo.member.Count:" + roomInfo.member.Count); for (int i = 0; i < roomInfo.member.Count; i++) { Server.connMap.TryGetValue(roomInfo.member[i].id.ToString(), out conn); byte[] data = Incode.IncodeSecondaryCommand(type, secondCommand, datas); conn.SendBts(data); } }
/// <summary> /// 摸牌 /// </summary> void Draw() { SingleDraw singleDraw = DataDo.Json2Object <SingleDraw>(Decode.DecodeSecondContendBtyes(bytes)); RoomInfo roomInfo = GetRoom(singleDraw.roomNum); //找到自己在成员列表所对应的下标 if (roomInfo == null) { return; } int cardIndex = singleDraw.cardIndex; BaseCard card = roomInfo.cardsLibrary[cardIndex]; //////出错 “牌不一致” card.CardBelongTo = (CardBelongTo)singleDraw.myIndex; //为每个玩家发牌 //服务器房间牌库数据修改 roomInfo.playersCards.Add(card); roomInfo.cardsLibrary.Remove(card); Console.WriteLine("玩家牌数:" + roomInfo.playersCards.Count + " 牌库:" + roomInfo.cardsLibrary.Count); Console.WriteLine("singleDraw: cardIndex:" + singleDraw.cardIndex + " myId:" + singleDraw.myId + " 时间:" + DateTime.Now); //自动摸牌(托管) if (singleDraw.autoTrusteeship) { card.CardDisplay = CardDisplay.True; //每人的计时是_SingleDrawTime + _SelectMyselfCardTime+出牌按钮+再次摸牌时间 Next(roomInfo); Console.WriteLine("Next-------------Draw"); } ForeachSendDraw((int)SecondCommands.DRAW, roomInfo, cardIndex, card); }
/// <summary> /// 抽取指定 颜色 及 张数 的牌 /// </summary> /// <param name="colorCardsCount">指定颜色的牌数</param> /// <param name="roomInfo">房间信息(修改手牌和牌库)</param> /// <param name="id">玩家id</param> /// <param name="cardColors">对应牌色</param> public static void DoDeal(int colorCardsCount, RoomInfo roomInfo, int id, CardColors cardColors) { for (int i = 0; i < colorCardsCount; i++) { BaseCard card = roomInfo.cardsLibrary.Find(it => { if (it.CardColor == cardColors)//找到满足条件的牌 { return(true); } else { return(false); } }); int index = roomInfo.member.FindIndex(it => { if (it.id == id) //找到该玩家在成员列表中的下标(索引) { return(true); } else { return(false); } }); roomInfo.cardsLibrary.Remove(card); card.CardBelongTo = (CardBelongTo)(index + 1);//为每个玩家发牌 0是牌库 roomInfo.playersCards.Add(card); } }
/// <summary> /// 抽取指定 张数 的牌 /// </summary> /// <param name="colorCardsCount">指定颜色的牌数</param> /// <param name="roomInfo">房间信息(修改手牌和牌库)</param> /// <param name="id">玩家id</param> public static void DoDeal(int colorCardsCount, RoomInfo roomInfo, int id) { for (int i = 0; i < colorCardsCount; i++) { #region 测试代码 ///////////////////////////////////////////////////////////// 测试代码 /////////////////////////////// //if (id==1) //{ // BaseCard tempCard=null; // foreach (var item in roomInfo.cardsLibrary) // { // if (item.CardWeight == CardWeight.Line) // { // tempCard = item; // } // } // BaseCard card; // if (tempCard!=null) // { // card = tempCard; // } // else // { // card = roomInfo.cardsLibrary[0]; // } // int index = roomInfo.member.FindIndex(it => // { // if (it.id == 1)//找到该玩家在成员列表中的下标(索引) // { // return true; // } // else return false; // }); // roomInfo.cardsLibrary.Remove(card); // card.CardBelongTo = (CardBelongTo)(index + 1);//为每个玩家发牌 0是牌库 成员的0代表所属的1 // roomInfo.playersCards.Add(card); //} /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // else #endregion { BaseCard card = roomInfo.cardsLibrary[0]; int index = roomInfo.member.FindIndex(it => { if (it.id == id)//找到该玩家在成员列表中的下标(索引) { return(true); } else { return(false); } }); roomInfo.cardsLibrary.Remove(card); card.CardBelongTo = (CardBelongTo)(index + 1);//为每个玩家发牌 0是牌库 成员的0代表所属的1 roomInfo.playersCards.Add(card); } } }