public void Start() { hasClosed = false; gameLoop = new DispatcherTimerGameLoop(1000 / 100); gameLoop.Update += Update; gameWindow = new GameWindow(settings); gameWindow.Closed += (sender, args) => Stop(); SocketFactory socketGame = new SocketFactory(settings); socketGame.Cancel += Stop; socketManager = socketGame.CreateSocketManager(); GraphicManager graphicManager = new GraphicManager(gameWindow.Canvas); InputFactory inputFactory = new InputFactory(gameWindow.Canvas, socketManager); if (hasClosed) return; world = new World(settings, inputFactory, graphicManager); CompositionTarget.Rendering += (sender, args) => world.Draw(); world.Start(); gameWindow.Show(); gameLoop.Start(); }
public SocketManager CreateSocketManager() { if (maxClients <= 0) return null; socketManager = new SocketManager(maxClients, settings.Port); socketManager.Start(); WindowThread<ProgressWindow> windowThread = new WindowThread<ProgressWindow>(); windowThread.Update(p => p.Closed += (sender, args) => Cancel()); windowThread.Start(); while (socketManager.CountClients < maxClients) { windowThread.Update(p => p.StatusText.Text = string.Format("Waiting for {0} players..", maxClients - socketManager.CountClients)); if (windowThread.IsClosed()) { socketManager.Stop(); Cancel(); break; } if (socketManager.HasIncoming) { SocketHandler player = socketManager.ConnectPlayer(); windowThread.Update(p => p.StatusText.Text = "Waiting for name.."); string playerName = player.WaitForName(); windowThread.Update(p => p.List.Children.Add(new TextBlock { Text = playerName })); } Thread.Sleep(10); } windowThread.Stop(); return socketManager; }
public InputFactory(UIElement window, SocketManager socketManager) { this.window = window; this.socketManager = socketManager; }