//对传输过来的流信息进行翻译 public Poker[] TranslatePoker(string presentMsg) { Poker[] realsuit = new Poker[27]; string[] strArray = presentMsg.Split(','); if (presentMsg != null) { for (int i = 0; i < 27; i++) { realsuit[i] = new Poker(int.Parse(strArray[i]));//写法特殊注意!! } } return(realsuit); }
public void Shuffle(Poker[] poker) { Random r = new Random(); for (int i = 53; i >= 0; --i) { Poker temp = null; int j = r.Next(0, i); temp = poker[i]; poker[i] = poker[j]; poker[j] = temp; } }
public Poker LosePoker() { if (possession.Count != 0) { Poker temp = null;//为什么弄个temp因为没办法读出删除一步走 temp = possession.Last(); possession.RemoveLast(); return(temp); } else { return(null); } }
public Table UpdateObsoleteTable(string strSRecMsg) { Table neoTable = new Table(); if (strSRecMsg != "-1" && strSRecMsg != null) { string[] strArray = strSRecMsg.Split(','); for (int i = 0; i < strArray.Length; i++) { Poker p = new Poker(int.Parse(strArray[i])); neoTable.GainPoker(p); } return(neoTable); } else { return(neoTable);//千万不要直接Return null不然满城血雨!! } }
////对传输过来的流信息进行第一次翻译 private Poker[] TranslatePoker(string presentMsg, int invalid) { Poker[] realsuit = new Poker[27]; string[] strArray = presentMsg.Split(','); if (presentMsg != null) { for (int i = 0; i < 27; i++) { realsuit[i] = new Poker(int.Parse(strArray[i]));//写法特殊注意!! } } //把最后那个密码加到桌上 int index1 = presentMsg.LastIndexOf(","); int index2 = presentMsg.LastIndexOf("#"); int length = index2 - index1 - 1; string value = presentMsg.Substring(index1 + 1, length); Poker p = new Poker(int.Parse(value)); table.GainPoker(p); return(realsuit); }
//现在不是自动游戏时代了 //public Poker SearchPoker(Poker clickedPoker) //{//传进来的不能是玩家而应该是扑克了 // foreach (Poker item in possession)//泛型已出,千万别用for,迭代器记死 // { // if (item.ID % 13 == clickedPoker.ID % 13) // { // return item; // } // } // return null; //} public int CartPoker(Table table, Player p, Poker clickedPoker) {//如上改动 Poker lastPoker = p.ActivatePoker(); table.GainPoker(p.LosePoker()); if (lastPoker.ID % 13 == clickedPoker.ID % 13) { int cartLock = 0; LinkedList <Poker> tempo = new LinkedList <Poker>(); foreach (Poker item in possession) //获得牌 { if (item.ID == clickedPoker.ID) //开锁 { cartLock = 1; } if (cartLock == 1) { p.GainPoker(item); } else { tempo.AddLast(item); } } table.possession.Clear(); foreach (Poker item in tempo) { possession.AddLast(item); } tempo.Clear(); return(1);//成功加牌 } else { return(0);//用户瞎点的,不予加牌 } }
public void GainPoker(Poker p) { possession.AddLast(p); }