static void Main(string[] args) { //These methods will be triggered when an incoming messgae of that specified title is received //the type of receipt is explicitly stated NetworkComms.AppendGlobalIncomingPacketHandler <int>("Player", GetPlayerNumber); NetworkComms.AppendGlobalIncomingPacketHandler <int>("NumColumns", GetColumnNumber); NetworkComms.AppendGlobalIncomingPacketHandler <int>("canTakeGuess", GetApprovalforGuess); NetworkComms.AppendGlobalIncomingPacketHandler <int[]>("CheckGuess", GetCheckGuess); //Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); //Request server IP and port number TakeServerInfo(); while (true) { if (_canStartGame) { //starts game _game = new Game(); int mode = _game.Initialization(); NetworkComms.SendObject("Mode", _serverIp, _serverPort, mode); _canStartGame = false; } if (_canTakeCol) { _numColumns = _game.TakeNumColumns(); NetworkComms.SendObject("numColumns", _serverIp, _serverPort, _numColumns); _canTakeCol = false; _canTakeAttempt = true; } if (_canTakeAttempt) { _numAttempts = _game.TakeNumAttempts(); NetworkComms.SendObject("numAttempts", _serverIp, _serverPort, _numAttempts); Console.WriteLine("Wait for Second Player to choose Secret Combination.."); _canTakeAttempt = false; } if (_canPlyer2Move) { _secretCombination = _game.Player2Move(_numColumns); NetworkComms.SendObject("secretCombination", _serverIp, _serverPort, _secretCombination); _canPlyer2Move = false; } while (_cantakeGuess && _numAttempts > 0 && !_hasWon && _canTakeNextGuess) { string[] guess = _game.TakeGuess(_numColumns); NetworkComms.SendObject("guess", _serverIp, _serverPort, guess); _numAttempts--; _canTakeNextGuess = false; } if (_hasWon) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n\tYou Won!!!"); Console.WriteLine("\n\n\n\nPress any key to close"); break; } if (_numAttempts == 0 && _cantakeGuess) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n\tYou Lost!!!"); Console.WriteLine("\n\n\n\nPress any key to close"); break; } //Console.WriteLine("Please Wait..."); } //We have used comms so we make sure to call shutdown Console.Read(); NetworkComms.Shutdown(); }