public void SaveCurrentCardsType(string cardTypeCode, List <int> keysOutside) { twp = new TypeWithPoints(); CardsType ct = (CardsType)Enum.Parse(typeof(CardsType), cardTypeCode); twp.cardsType = ct; switch (ct) { case CardsType.Single: twp.p = keysOutside[0]; break; case CardsType.Doub: twp.p = keysOutside[0]; break; case CardsType.Four: twp.p = keysOutside[0]; break; default: twp.ps = keysOutside; break; } }
public void Pass() { HideAll(); PlayCardsReq req = new PlayCardsReq(); var reqTypeWithPoints = new TypeWithPoints(); reqTypeWithPoints.cardsType = CardsType.Pass; req.typeWithPoints = reqTypeWithPoints; req.handPoints = new List <int>(PlayManager.GetInstance().AllPointsInHand()); SendPlayCards(req); }
public void Pass() { TypeWithPoints typeWithPoints = new TypeWithPoints(); typeWithPoints.cardsType = CardsType.Pass; if (!CardHelper.GetInstance().CanPlay(typeWithPoints)) { ShowMessage(ErrorCode.PLAY_INVALID_CARDS_TYPE); } else { GameObject.FindGameObjectWithTag("MainCamera").GetComponent <GameController>().SendMessage("Pass"); } }
public void PlayCards() { List <int> allReady2GoPoints = PlayManager.GetInstance().AllReady2GoPoints(); Debug.Log("out before play:" + CardHelper.GetInstance().Join(PlayManager.GetInstance().AllPointsOutside())); if (allReady2GoPoints.Count == 0) { Debug.Log("no card selected."); ShowMessage(ErrorCode.PLAY_NO_CARD_SELECTED); } else { Debug.Log("ready2GoPoints:" + CardHelper.GetInstance().Join(allReady2GoPoints)); TypeWithPoints typeWithPoints = CardHelper.GetInstance().JudgeType(allReady2GoPoints); Debug.Log(string.Format("type:{0},p:{1},ps{2}", typeWithPoints.cardsType, typeWithPoints.p, Join(typeWithPoints.ps))); if (typeWithPoints.cardsType.Equals(CardsType.Invalid)) { ShowMessage(ErrorCode.PLAY_INVALID_CARDS_TYPE); } else if (!CardHelper.GetInstance().CanPlay(typeWithPoints)) { ShowMessage(ErrorCode.PLAY_NOT_BIG_ENOUGH); } else { List <int> goPoints = new List <int>(allReady2GoPoints); List <int> handPoints = new List <int>(PlayManager.GetInstance().AllPointsInHand()); PlayCardsReq req = new PlayCardsReq(); req.typeWithPoints = typeWithPoints; req.handPoints = handPoints; req.points = goPoints; GameObject.FindGameObjectWithTag("MainCamera").GetComponent <GameController>().SendMessage("SendPlayCards", req); } } }
public TypeWithPoints JudgeType(List <int> list) { Debug.Log("JudgeType, points:" + Join(list)); //plain list List <int> points = new List <int>(list.Count); for (int i = 0; i < list.Count; i++) { points.Add(list[i] % 100); } Debug.Log("Plain points:" + Join(points)); points.Sort(); Debug.Log("Points after sort:" + Join(points)); TypeWithPoints tp = new TypeWithPoints(); if (isSingle(points)) { tp.cardsType = CardsType.Single; tp.p = points[0]; return(tp); } if (isDouble(points)) { tp.cardsType = CardsType.Doub; tp.p = points[0]; return(tp); } if (points.Count == 2 && points[0] == 16 && points[1] == 17) { tp.cardsType = CardsType.DoubJoker; return(tp); } if (points.Count == 4 && points[0] == points[3]) { tp.cardsType = CardsType.DoubJoker; tp.p = points[0]; return(tp); } if (isSeq(points)) { tp.cardsType = CardsType.Seq; tp.ps = points; return(tp); } List <int> doubSeq = judgeDoubSeq(points); if (doubSeq != null) { tp.cardsType = CardsType.DoubSeq; tp.ps = doubSeq; return(tp); } List <int> threeSeq = judgeThreeSeq(points); if (threeSeq != null) { tp.cardsType = CardsType.ThreeSeq; tp.ps = threeSeq; return(tp); } List <int> threeWithOneSeq = judgeThreeWithOneSeq(points); if (threeWithOneSeq != null) { tp.cardsType = CardsType.ThreeWithOneSeq; tp.ps = threeWithOneSeq; return(tp); } List <int> threeWithTwoSeq = judgeThreeWithTwoSeq(points); if (threeWithTwoSeq != null) { tp.cardsType = CardsType.ThreeWithTwoSeq; tp.ps = threeWithTwoSeq; return(tp); } List <int> fourWith2SingleSeq = judgeFourWith2SingleSeq(points); if (fourWith2SingleSeq != null) { tp.cardsType = CardsType.FourWith2SingleSeq; tp.ps = fourWith2SingleSeq; return(tp); } List <int> fourWith2DoubSeq = judgeFourWith2DoubSeq(points); if (fourWith2DoubSeq != null) { tp.cardsType = CardsType.FourWith2DoubSeq; tp.ps = fourWith2DoubSeq; return(tp); } return(tpInvalid); }
public bool CanPlay(TypeWithPoints typeWithPoints) { CardsType originalType = twp.cardsType; CardsType readyType = typeWithPoints.cardsType; if (originalType == CardsType.Invalid || originalType == CardsType.Pass || readyType == CardsType.Invalid || readyType == CardsType.Exist) { Debug.LogError("invalid card type happend!"); return(false); } if (originalType != CardsType.Exist && readyType == CardsType.Pass) { return(true); } switch (originalType) { case CardsType.Exist: return(!(readyType == CardsType.Invalid || readyType == CardsType.Exist || readyType == CardsType.Pass)); case CardsType.Single: if (readyType == CardsType.DoubJoker || readyType == CardsType.Four) { return(true); } if (readyType == CardsType.Single) { return(typeWithPoints.p > twp.p); } return(false); case CardsType.Doub: if (readyType == CardsType.DoubJoker || readyType == CardsType.Four) { return(true); } if (readyType == CardsType.Doub) { return(typeWithPoints.p > twp.p); } return(false); case CardsType.Four: if (readyType == CardsType.DoubJoker) { return(true); } if (readyType == CardsType.Four) { return(typeWithPoints.p > twp.p); } return(false); case CardsType.DoubJoker: return(false); default: if (readyType == CardsType.DoubJoker || readyType == CardsType.Four) { return(true); } if (readyType == originalType) { List <int> oldList = typeWithPoints.ps; List <int> newList = twp.ps; return(oldList.Count == newList.Count && oldList[newList.Count - 1] < newList[newList.Count - 1]); } return(false); } }