private void SetupGameEventHandlers(GameEventController gameEventController) { gameEventController.Event += (sender, args) => { switch (args.Event) { case GameEvent.PlayerCrashed: PlayerCrashed(args.Player); break; case GameEvent.PlayerSpawned: PlayerSpawned(); break; case GameEvent.ScoreUpdated: ScoreUpdated(); break; case GameEvent.GameStarted: break; case GameEvent.RoundStarted: RoundStarted(); break; case GameEvent.RoundEnded: RoundEnded(); break; default: throw new ArgumentOutOfRangeException(); } }; }
public GameController(IClientEventReceiver clientEventReceiver, IServerEventSender serverEventSender, GameSettings settings) { var gameEventController = new GameEventController(); SetupGameEventHandlers(gameEventController); SetupClientEventHandlers(clientEventReceiver); _eventSender = serverEventSender; _minPlayers = settings.MinPlayers; _game = new GameEngine(gameEventController, settings); _botController = new BotController(this, clientEventReceiver); _worldBroadcastThread = new Thread(delegate() { while (true) { if (DateTime.UtcNow < _nextWorldUpdate) { continue; } Task.Run(() => BroadcastWorldUpdate()); _nextWorldUpdate = DateTime.UtcNow.AddMilliseconds(BroadcastWorldInterval); } }); _broadcastCounterThread = new Thread(delegate() { while (true) { Thread.Sleep(1000); Console.WriteLine($"{WorldBroadcastsPerSecond} world broadcasts per second"); WorldBroadcastsPerSecond = 0; } }); Start(); }