public override void ShowChoiseView(ISFSObject cardData) { base.ShowChoiseView(cardData); InitPokerList(); //初始化左侧的牌 RepositionCards(); //将左侧的牌排列成三行 gameObject.SetActive(true); int[] array = cardData.GetIntArray("cards"); Help1 help = new Help1(); List <int> pokerList = array.ToList(); Resort(pokerList); List <Help1.PlayerDuns> pd = help.getPlayerDuns(pokerList); while (pd.Count > 0 && pd[0].Duns[0] == null) { pd.Remove(pd[0]); } int itemCount = pd.Count > 3 ? 3 : pd.Count; //初始化数据 for (int i = 0; i < itemCount; i++) { ChoiseItem item = _choiseItems[i]; item.gameObject.SetActive(true); if ((int)pd[i].Special - (int)CardType.none >= 0) //特殊牌型,不用显示每行牌型 { item.SpecialObj.SetActive(true); item.NormalObj.SetActive(false); item.Special = (int)pd[i].Special; item.SpecialSprite.spriteName = pd[i].Special.ToString(); item.SpecialSprite.MakePixelPerfect(); item.SetChoiseItem(pd[i].Duns); } else //普通牌型,要显示每组牌的牌型 { item.SpecialObj.SetActive(false); item.NormalObj.SetActive(true); item.SetChoiseItem(pd[i].Duns); } } OnClickPlane(_choiseItems[0]); }
public void OnClickOkBtn() { ISFSObject obj = new SFSObject(); ISFSArray arr = new SFSArray(); string errorMsg = string.Empty; if (_lastChoiseItem != null && _lastChoiseItem.Special > 0) { obj.PutInt("special", _lastChoiseItem.Special); } else { if (!NoDaoShui(_lastList, ref errorMsg)) { YxMessageBox.Show(new YxMessageBoxData() { Msg = errorMsg, Delayed = 3, }); YxDebug.Log("不能倒水"); return; } } int beginIndex = 0; for (int i = 0; i < 3; i++) { int count = i == 0 ? 3 : 5; List <int> tempList = _lastList.GetRange(beginIndex, count); ISFSObject arrItem = new SFSObject(); arrItem.PutInt("type", (int)CheckCardType(tempList, i)); Help1.SortList(tempList); arrItem.PutIntArray("cards", tempList.ToArray()); arr.AddSFSObject(arrItem); beginIndex += count; } obj.PutSFSArray("duninfo", arr); obj.PutInt("type", GameRequestType.FinishChoise); App.GetRServer <SssGameServer>().SendGameRequest(obj); }
public override void ShowChoiseView(ISFSObject cardData) { base.ShowChoiseView(cardData); InitPokerList(); gameObject.SetActive(true); int[] cardArray = cardData.GetIntArray("cards"); _cardValList = cardArray.ToList(); Help1.SortList(_cardValList); Help1 help = new Help1(); List <Help1.PlayerDuns> pd = help.getPlayerDuns(_cardValList); //初始化手牌,待删 for (int i = 0; i < CardsList.Count; i++) { CardsList[i].SetCardId(_cardValList[i]); CardsList[i].SetCardFront(); } RespositionCards();//初始化手牌位置 if (SpecialBtn != null) { if (pd.Count > 0 && pd[0].Special > CardType.none) { _specialDuns = pd[0]; SpecialBtn.gameObject.SetActive(true); } else { _specialDuns = null; SpecialBtn.gameObject.SetActive(false); } } SetChoiseView(_cardValList); }
public void OnClickOkBtn() { ISFSObject obj = new SFSObject(); ISFSArray arr = new SFSArray(); if (_selectInfo != null && _selectInfo.CardType > CardType.none) { obj.PutInt("special", (int)_selectInfo.CardType); } else { string errorMsg = string.Empty; if (CheckIsDaoShui(ref errorMsg)) { YxMessageBox.Show(new YxMessageBoxData() { Msg = errorMsg, Delayed = 3, }); YxDebug.Log("不能倒水"); return; } } for (int i = 0; i < 3; i++) { var lineInfo = Lines[i].LineInfo; ISFSObject arrItem = new SFSObject(); arrItem.PutInt("type", (int)lineInfo.CardType); var tempList = lineInfo.Dun.Cards; Help1.SortList(tempList, false); arrItem.PutIntArray("cards", tempList.ToArray()); arr.AddSFSObject(arrItem); } obj.PutSFSArray("duninfo", arr); //发送到服务器 obj.PutInt("type", GameRequestType.FinishChoise); App.GetRServer <SssGameServer>().SendGameRequest(obj); }
/// <summary> /// 检测牌型 /// </summary> /// <param name="cards">牌</param> /// <param name="line">第几行</param> /// <returns></returns> public CardType CheckCardType(List <int> cards, int line) { //除去可能产生的不必要的信息 cards = cards.GetRange(0, line == 0 ? 3 : 5); //检测牌型 bool isTongHua = line != 0; bool isShunZi = line != 0; int samecount = 1; List <int> sameNumList = new List <int>(); Resort(cards); int color = Help1.GetColor(cards[0]); int value = Help1.GetValue(cards[0]); for (int i = 1; i < cards.Count; i++) { int card = cards[i]; if (card == 0) { continue; } int cardColor = Help1.GetColor(card); int cardValue = Help1.GetValue(card); if (cardColor != color) { isTongHua = false; } if (cardValue - value != 1) { isShunZi = false; } if (cardValue == value) { samecount++; } else { if (samecount > 0) { sameNumList.Add(samecount); samecount = 1; } } value = cardValue; } sameNumList.Add(samecount); if (line == 0) { if (sameNumList.Count == 2) { return(CardType.yidui); } if (sameNumList.Count == 1) { return(CardType.santiao); } return(CardType.sanpai); } if (isTongHua && isShunZi) { return(CardType.tonghuashun); } if (isShunZi) { return(CardType.shunzi); } if (isTongHua) { return(CardType.tonghua); } if (sameNumList.Count > 0) { if (sameNumList.Count == 1) { samecount = sameNumList[0]; if (samecount == 2) { return(CardType.yidui); } else if (samecount == 3) { return(CardType.santiao); } else if (samecount == 4) { return(CardType.tiezhi); } } else if (sameNumList.Count == 2) { samecount = sameNumList[0]; int samecount1 = sameNumList[1]; if ((samecount == 2 && samecount1 == 3) || (samecount == 3 && samecount1 == 2)) { return(CardType.hulu); } else if (samecount == 4 || samecount1 == 4) { return(CardType.tiezhi); } } else if (sameNumList.Count == 3) { if (sameNumList.Any(item => item == 3)) { return(CardType.santiao); } return(CardType.liangdui); } else if (sameNumList.Count == 4) { return(CardType.yidui); } } return(CardType.sanpai); }
/// <summary> /// 根据牌面值对列表进行排序 /// </summary> /// <param name="list">要排序的牌列表</param> /// <param name="mode">1为升序,-1为降序,默认升序</param> void Resort(List <int> list, int mode = 1) { list.Sort((x, y) => mode * Help1.GetValue(x).CompareTo(Help1.GetValue(y))); }
/// <summary> /// 获取按钮状态位,同时初始化字典 /// </summary> /// <param name="pokerList"></param> /// <returns></returns> private int GetBtnState(List <int> pokerList) { if (pokerList.Count < 3) { return(0); } int btnState = 0; CnList cnList = new CnList(pokerList); VnList vnList = new VnList(pokerList); CnList cn5 = cnList.GetMoreThan(5, true, true); //同花色5个以上 VnList vn2 = vnList.GetMoreThan(2, true); //同数值的2个以上 _cardTypeDic.Clear(); //同花顺,128 if (cn5.Count > 0) { foreach (var cnItem in cn5) { if (HaveAndAdd(cnItem.Cards, CardType.tonghuashun, CardType.tonghuashun)) { btnState |= GetStateVal(CardType.tonghuashun); } } } //铁支 VnList vn4 = vnList.GetEqual(4, true); if (vn4.Count > 0) { foreach (var item in vn4) { SssDun dun = new SssDun { CardType = CardType.tiezhi, Cards = item.Cards }; AddToDic(_cardTypeDic, CardType.tiezhi, dun); } btnState |= GetStateVal(CardType.tiezhi); } VnList vn3 = vnList.GetMoreThan(3, true); //葫芦 if (vn3.Count > 0 && vn2.Count > 0) { foreach (var item3 in vn3) { foreach (var item2 in vn2) { if (item3.Val == item2.Val) { continue; } AddListToDic(CardType.hulu, _cardTypeDic, item3.Cards.GetRange(0, 3), item2.Cards.GetRange(0, 2)); btnState |= GetStateVal(CardType.hulu); } } } //同花 if (cn5.Count > 0) { btnState = cn5.Where(item => HaveAndAdd(item.Cards, CardType.tonghua)) .Aggregate(btnState, (current, item) => current | GetStateVal(CardType.tonghua)); } //顺子 { List <SssDun> dunList = new List <SssDun>(); Help1 help = new Help1(); if (help.CheckShunZi(pokerList, dunList, 5, false)) { foreach (var dun in dunList) { AddToDic(_cardTypeDic, CardType.shunzi, dun); } btnState |= GetStateVal(CardType.shunzi); } } //三条 if (vn3.Count > 0) { int count = vn3.Count; for (int i = 0; i < count; i++) { AddListToDic(CardType.santiao, _cardTypeDic, vn3[i].Cards.GetRange(0, 3)); } btnState |= GetStateVal(CardType.santiao); } //两对 if (vn2.Count > 1) { int count = vn2.Count; for (int i = 0; i < count; i++) { int vn2Vi = vn2[i].Val; for (int j = i; j < count; j++) { int vn2Vj = vn2[j].Val; if (vn2Vi == vn2Vj) { continue; } AddListToDic(CardType.liangdui, _cardTypeDic, vn2[i].Cards.GetRange(0, 2), vn2[j].Cards.GetRange(0, 2)); btnState |= GetStateVal(CardType.liangdui); } } } //对子 if (vn2.Count > 0) { int count = vn2.Count; for (int i = 0; i < count; i++) { AddListToDic(CardType.yidui, _cardTypeDic, vn2[i].Cards.GetRange(0, 2)); } btnState |= GetStateVal(CardType.yidui); } return(btnState); }
/// <summary> /// 根据牌面值对列表进行排序 /// </summary> /// <param name="list">要排序的牌列表</param> /// <param name="up">是否是升序排列</param> void Resort(List <int> list, bool up = true) { Help1.SortList(list, up); }