public void JsonCommand(JToken jtoken, List <JToken> jTokenList) { //Register Players if (!_isSet_player1) { _isSet_player1 = true; jTokenList.Add(JToken.Parse(JsonConvert.SerializeObject(_referee.Register(jtoken.ToObject <string>())))); } else if (!_isSet_player2) { _isSet_player2 = true; jTokenList.Add(JToken.Parse(JsonConvert.SerializeObject(_referee.Register(jtoken.ToObject <string>())))); } //Play out the match else { string play = jtoken.ToObject <string>(); try { jTokenList.Add(JToken.Parse(JsonConvert.SerializeObject(_referee.GetBoardHistory()))); if (play == "pass") { _referee.Pass(); } else { _referee.Play(play); } } catch (RefereeException) { List <PlayerWrapper> victors = _referee.GetVictors(); List <string> names = new List <string>(); foreach (PlayerWrapper victor in victors) { names.Add(victor.GetName()); } jTokenList.Add(JToken.Parse(JsonConvert.SerializeObject(names.ToArray()))); throw new RefereeException("Game has ended"); } } }
public void JsonCommand(JToken jtoken) { //Register Players if (!_isSet_player1) { Console.WriteLine(JsonConvert.SerializeObject(_referee.Register(jtoken.ToObject <string>()))); _isSet_player1 = true; } else if (!_isSet_player2) { Console.WriteLine(JsonConvert.SerializeObject(_referee.Register(jtoken.ToObject <string>()))); _isSet_player2 = true; } //Play out the match else { string play = jtoken.ToObject <string>(); try { Console.WriteLine(JsonConvert.SerializeObject(_referee.GetBoardHistory())); if (play == "pass") { _referee.Pass(); } else { _referee.Play(play); } } catch (RefereeException) { Console.WriteLine(JsonConvert.SerializeObject(_referee.GetVictors())); throw new RefereeException("Game has ended"); } } }