/// <summary> /// 排序 /// </summary> public MaJiangCollection SortByColorThenNameDesc() { MaJiangCollection majiangs = new MaJiangCollection(); var temp = this.OrderByDescending(c => c.CardColor).ThenByDescending(c => c.Name).ToList <Card>(); majiangs.AddRange(temp); return(majiangs); }
/// <summary> /// 获得可以胡的牌 /// </summary> /// <returns></returns> public virtual MaJiangCollection GetHuCards(MaJiangCollection maJiangs) { List <Card> HuCards = new MaJiangCollection(); MaJiangCollection doubleCards; doubleCards = maJiangs.FindTheSameCards(2); List <MaJiangCollection> matchedCards = new List <MaJiangCollection>(); if (doubleCards.Count > 0) { for (int i = 0; i < doubleCards.Count; i++) { MaJiangCollection tempMajiangs = new MaJiangCollection(); tempMajiangs.AddRange(maJiangs); tempMajiangs = tempMajiangs.RemoveCountOf(doubleCards[i], 2); List <MaJiangCollection> matchedCardsNeed = tempMajiangs.GetMatchedCardsCollection(); if (matchedCardsNeed.Count == 1) { matchedCards.Add(matchedCardsNeed[0]); } List <MaJiangCollection> matchedCardsNeedDesc = tempMajiangs.GetMatchedCardsDescCollection(); if (matchedCardsNeedDesc.Count == 1) { matchedCards.Add(matchedCardsNeedDesc[0]); } } } for (int i = 0; i < maJiangs.Count; i++) { MaJiangCollection tempMajiangs = new MaJiangCollection(); tempMajiangs.AddRange(maJiangs); MaJiangCollection tempOneCard = new MaJiangCollection { maJiangs[i] }; tempMajiangs = tempMajiangs.RemoveCountOf(maJiangs[i], 1); List <MaJiangCollection> matchedCardsNeed = tempMajiangs.GetMatchedCardsCollection(); if (matchedCardsNeed.Count == 0) { matchedCards.Add(tempOneCard); } List <MaJiangCollection> matchedCardsNeedDesc = tempMajiangs.GetMatchedCardsDescCollection(); if (matchedCardsNeedDesc.Count == 0) { matchedCards.Add(tempOneCard); } } if (matchedCards.Count > 0) { for (int i = 0; i < matchedCards.Count; i++) { HuCards.AddRange(matchedCards[i].GetMatchedCards()); } } MaJiangCollection husdistnct = new MaJiangCollection(); if (HuCards.Count == 0) { return(husdistnct); } int k = 0; do { husdistnct.Add(HuCards[k]); k++; } while (!husdistnct.Exists(c => c.IsTheSameWith(HuCards[k])) && k < HuCards.Count ); return(husdistnct); }