static void Server_Connected(object sender, Server <SnakePlayer> .ConnectionEventArgs e) { SnakeGame TargetGame = null; e.Client.Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); foreach (SnakeGame G in Games) { if (G.Status == GameStatus.WaitingForOpponent) { TargetGame = G; break; } } if (TargetGame == null) { CurrentID++; TargetGame = new SnakeGame(Map); TargetGame.AddPlayer(e.Client); TargetGame.ID = CurrentID; TargetGame.GameOver += new SnakeGame.GameOverDelegate(TargetGame_GameOver); TargetGame.MessageLogged += new SnakeGame.LogMessageDelegate(TargetGame_MessageLogged); Games.Add(TargetGame); TargetGame_MessageLogged(TargetGame, new SnakeGame.LogEventArgs("First player connected")); } else { TargetGame.AddPlayer(e.Client); } }
static void Server_Connected(object sender, Server<SnakePlayer>.ConnectionEventArgs e) { SnakeGame TargetGame = null; e.Client.Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); foreach (SnakeGame G in Games) { if (G.Status == GameStatus.WaitingForOpponent) { TargetGame = G; break; } } if (TargetGame == null) { CurrentID++; TargetGame = new SnakeGame(Map); TargetGame.AddPlayer(e.Client); TargetGame.ID = CurrentID; TargetGame.GameOver += new SnakeGame.GameOverDelegate(TargetGame_GameOver); TargetGame.MessageLogged += new SnakeGame.LogMessageDelegate(TargetGame_MessageLogged); Games.Add(TargetGame); TargetGame_MessageLogged(TargetGame, new SnakeGame.LogEventArgs("First player connected")); } else { TargetGame.AddPlayer(e.Client); } }
static void TargetGame_MessageLogged(object sender, SnakeGame.LogEventArgs e) { SnakeGame G = (SnakeGame)sender; Console.WriteLine("#" + G.ID + ": " + e.Message); }