public static void Main() { ConsoleWindow.CustomizeConsole(); IDrawManager drawManager = new ConsoleDrawManager(); IBorder border = new Border( new Point(middleConsoleWidth - 25, middleConsoleHeight - 15), new Point(middleConsoleWidth + 25, middleConsoleHeight + 15)); IFoodFactory foodFactory = new FoodFactory(new Random(), border); IScene pauseScene = new PauseScene(drawManager); IScene infoScene = new InfoScene(drawManager); IScene gameOverScene = new GameOverScene ( drawManager, new PlayAgainButton(new Point(middleConsoleWidth, 30)), new MenuButton(new Point(middleConsoleWidth, 35)) ); IButton playButton = new PlayButton ( new Point(middleConsoleWidth, 30), new Point(border.TopLeftCorner.CoordinateX + 2, border.TopLeftCorner.CoordinateY + 2), drawManager, foodFactory, border, pauseScene, gameOverScene); IScene startMenu = new StartMenuScene(drawManager, playButton, new InfoButton(new Point(middleConsoleWidth, 35), infoScene), new ExitButton(new Point(middleConsoleWidth, 40))); Engine engine = new Engine(startMenu); engine.Run(); }
public Program() { gameWindow = new GameWindow() { WindowState = WindowState.Maximized, Title = "Medieval Commander", }; scenes = new Dictionary <string, IScene>(); serviceProvider = new ServiceProvider(gameWindow, scene => { if (scene == null) { gameWindow.Exit(); return; } IScene nextScene; if (scenes.ContainsKey(scene)) { nextScene = scenes[scene]; } else { nextScene = new GameScene(serviceProvider, scene); } nextScene.OnChange(); // Reset OpenGL Viewport for next scene GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); GL.LoadIdentity(); if (gameWindow.Height > gameWindow.Width) { GL.Scale(1f, (float)gameWindow.Width / gameWindow.Height, 1f); } else { GL.Scale((float)gameWindow.Height / gameWindow.Width, 1f, 1f); } nextScene.Resize(gameWindow); currentScene = nextScene; }); StartMenuScene startMenuScene = new StartMenuScene(serviceProvider); GameOverScene gameOverScene = new GameOverScene(serviceProvider); LevelSelection levelSelection = new LevelSelection(serviceProvider); scenes.Add("MainMenu", startMenuScene); scenes.Add("GameOver", gameOverScene); scenes.Add("LevelSelection", levelSelection); currentScene = startMenuScene; gameWindow.UpdateFrame += (s, e) => currentScene.Update(); gameWindow.Resize += (s, e) => { GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); GL.LoadIdentity(); if (gameWindow.Height > gameWindow.Width) { GL.Scale(1f, (float)gameWindow.Width / gameWindow.Height, 1f); } else { GL.Scale((float)gameWindow.Height / gameWindow.Width, 1f, 1f); } currentScene.Resize(gameWindow); }; gameWindow.UpdateFrame += (s, e) => serviceProvider.Update(); Stream cursorImage = serviceProvider.GetService <IFileResourceService>().Open("cursor_shiny.png"); using (var image = new MagickImage(cursorImage)) { gameWindow.Cursor = new MouseCursor(0, 0, 32, 32, image.GetPixelsUnsafe().ToArray()); } gameWindow.Run(); }