public string Input(string c) { string result = ""; Sentence n = new Sentence(c, reg); foreach (string[] action in n.action) { if (action[0].Equals("send")) { n.from.Send(action[1], n.to); result = n.to_str; } else if (action[0].Equals("claim")) { n.from.Claim(action[1], n.to, this); result = n.to_str; } else if (action[0].Equals("pass")) { if (n.from.Pass(n.to, this)) { result = n.to_str; } else { result = "!" + n.from_str; break; } } else if (action[0].Equals("guess")) { bool guess = (action[1] == "1") ? true : false; if (n.from.Guess(guess, this)) { n.from.last.showedcardlist.Add(n.from.onpass); result = reg.getRef(n.from.last); } else { n.from.showedcardlist.Add(n.from.onpass); result = n.from_str; } } else { result = "DIE"; } } if (this.isGameOver(n)) { this.gameGoing = false; return result; } return result; }
public bool isGameOver(Sentence n) { bool gameover = false; if (n.from.handcard.Count == 0 && n.action[0].Equals("send")) { gameover = true; return gameover; } for (int z = 0; z < playerName.Length; z++) { ArrayList showcard = this.reg.Lookup(playerName[z]).showedcardlist; Card[] showlist = (Card[])showcard.ToArray(typeof(Card)); Dictionary<string, int> dic = new Dictionary<string, int>(); string[] animal_type = { "bat", "fly", "cocktail", "toad", "rat", "scorpion", "spider", "bug" }; for (int j = 0; j < animal_type.Length; j++) { dic.Add(animal_type[j], 0); } for (int k = 0; k < showlist.Length; k++) { dic[showlist[k].type]++; } foreach (KeyValuePair<string, int> pair in dic) { if (pair.Value == 4) { gameover = true; return gameover; } } bool haha = true; foreach (KeyValuePair<string, int> pair in dic) { if (pair.Value == 0) { haha = false; } } if (haha) { gameover = true; break; } } return gameover; /* 三種結束遊戲情況: * 1.showedcard有八種動物(done) * 2.showedcard有四張一樣的動物 * 3.輪到自己出牌時手牌 = 0 * */ }