Esempio n. 1
0
        public DifficultyMenu(MinerGame game, MenuScene previous)
            : base(game, previous)
        {
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 - 300, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), EASY, (menu) =>
                    {
                        // Following line protects new menu from instantly reading previous key as pressed.
                        GameScene newScene = new GameScene(this.Game)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        menu.Game.GameState.Difficulty = DifficultyLevel.Easy;
                        MenuManager.GetInstance().CurrentMenu = newScene;

                    }));
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 - 150, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), MEDIUM, (menu) =>
                    {
                        // Following line protects new menu from instantly reading previous key as pressed.
                        GameScene newScene = new GameScene(this.Game)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        menu.Game.GameState.Difficulty = DifficultyLevel.Medium;
                        MenuManager.GetInstance().CurrentMenu = newScene;
                    }));
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), HARD, (menu) =>
                    {
                        // Following line protects new menu from instantly reading previous key as pressed.
                        GameScene newScene = new GameScene(this.Game)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        menu.Game.GameState.Difficulty = DifficultyLevel.Hard;
                        MenuManager.GetInstance().CurrentMenu = newScene;
                    }));
            MenuItems[currentlySelected].Selected = true;
        }
Esempio n. 2
0
        public PauseMenu(MinerGame game, MenuScene previous)
            : base(game, previous)
        {
            int start = -400;
            int pos = start;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), RESUME, (menu) =>
                    {
                        this.GoBack();
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), SAVE_GAME, (menu) =>
                    {
                        using (FileStream fs = new FileStream("save1.xml", FileMode.Create))
                        {
                            XmlSerializer xml = new XmlSerializer(typeof(GameState));
                            xml.Serialize(fs, this.Game.GameState);
                        }
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), LOAD_GAME, (menu) =>
                    {
                        System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();

                        if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            try
                            {
                                this.Game.Content.Unload();

                                using (Stream stream = openFile.OpenFile())
                                {
                                    XmlSerializer xml = new XmlSerializer(typeof(GameState));
                                    this.Game.GameState = (GameState)xml.Deserialize(stream);
                                    this.Game.GameState.Miner.Suit = new Nanosuit();
                                    stream.Close();
                                }

                                this.Game.GameState.Miner.game = this.Game;

                                foreach (var item in this.Game.GameState.Enemies)
                                {
                                    item.game = this.Game;
                                }

                                foreach (var item in this.Game.GameState.Bullets)
                                {
                                    item.game = this.Game;
                                }

                                this.Game.Content.Load<SpriteFont>("general");
                                this.Game.Content.Load<Texture2D>(Kosmojopek.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Ufolowca.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(WladcaLaserowejDzidy.ASSET_NAME);
                                //this.Content.Load<Texture2D>(PoteznySultan.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Miner.ASSET_NAME);
                                //this.Content.Load<Texture2D>(CosmicMatter.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(DoubleJump.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Field.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Fuel.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Indestructibility.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Key.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(KeyLocalizer.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Laser.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(MoreEnemies.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(SolidRock.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(SpaceGate.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(TitanRock.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Bullet.ASSET_NAME);

                                this.Game.GameState.Miner.LoadContent();

                                foreach (var item in this.Game.GameState.Enemies)
                                {
                                    item.LoadContent();
                                }

                                foreach (var item in this.Game.GameState.Bullets)
                                {
                                    item.LoadContent();
                                }

                                foreach (var item in this.Game.GameState.Map.Fields)
                                {
                                    foreach (var field in item)
                                    {
                                        field.game = this.Game;
                                        field.LoadContent();
                                    }
                                }

                                GameScene newScene = new GameScene(this.Game)
                                {
                                    OldKeyState = this.CurrentKeyState
                                };
                                MenuManager.GetInstance().CurrentMenu = newScene;
                            }
                            catch (Exception exc)
                            {
                                System.Windows.Forms.MessageBox.Show(ERROR_READING_FILE + exc.Message);
                            }
                        }
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), INSTRUCTIONS, (menu) =>
                    {

                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), SETTINGS, (menu) =>
                    {
                        SettingsMenu newMenu = new SettingsMenu(this.Game, this)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), EXIT_MAIN_MENU, (menu) =>
                    {
                        MainMenu newMenu = new MainMenu(this.Game)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            pos += MENU_ITEM_HEIGHT + GAP;
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + pos, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), EXIT_GAME, (menu) =>
                    {
                        menu.Game.ExitGame();
                    }));
            MenuItems[currentlySelected].Selected = true;
        }
Esempio n. 3
0
        public MainMenu(MinerGame game)
            : base(game)
        {
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 - 300, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), START, (menu) =>
                    {
                        // Following line protects new menu from instantly reading previous key as pressed.
                        DifficultyMenu newMenu = new DifficultyMenu(this.Game, this)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 - 150, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), LOAD_GAME, (menu) =>
                    {
                        System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();

                        if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            try
                            {
                                this.Game.Content.Unload();

                                using (Stream stream = openFile.OpenFile())
                                {
                                    XmlSerializer xml = new XmlSerializer(typeof(GameState));
                                    this.Game.GameState = (GameState)xml.Deserialize(stream);
                                    this.Game.GameState.Miner.Suit = new Nanosuit();
                                    stream.Close();
                                }

                                this.Game.GameState.Miner.game = this.Game;

                                foreach (var item in this.Game.GameState.Enemies)
                                {
                                    item.game = this.Game;
                                }

                                foreach (var item in this.Game.GameState.Bullets)
                                {
                                    item.game = this.Game;
                                }

                                this.Game.Content.Load<SpriteFont>("general");
                                this.Game.Content.Load<Texture2D>(Kosmojopek.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Ufolowca.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(WladcaLaserowejDzidy.ASSET_NAME);
                                //this.Content.Load<Texture2D>(PoteznySultan.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Miner.ASSET_NAME);
                                //this.Content.Load<Texture2D>(CosmicMatter.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(DoubleJump.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Field.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Fuel.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Indestructibility.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Key.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(KeyLocalizer.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Laser.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(MoreEnemies.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(SolidRock.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(SpaceGate.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(TitanRock.ASSET_NAME);
                                this.Game.Content.Load<Texture2D>(Bullet.ASSET_NAME);

                                this.Game.GameState.Miner.LoadContent();

                                foreach (var item in this.Game.GameState.Enemies)
                                {
                                    item.LoadContent();
                                }

                                foreach (var item in this.Game.GameState.Bullets)
                                {
                                    item.LoadContent();
                                }

                                foreach (var item in this.Game.GameState.Map.Fields)
                                {
                                    foreach (var field in item)
                                    {
                                        field.game = this.Game;
                                        field.LoadContent();
                                    }
                                }

                                GameScene newScene = new GameScene(this.Game)
                                {
                                    OldKeyState = this.CurrentKeyState
                                };
                                MenuManager.GetInstance().CurrentMenu = newScene;
                            }
                            catch (Exception exc)
                            {
                                System.Windows.Forms.MessageBox.Show(ERROR_READING_FILE + exc.Message);
                            }
                        }

                    }));
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), HIGH_SCORES, (menu) =>
                    {
                        // Following line protects new menu from instantly reading previous key as pressed.
                        HighScoreMenu newMenu = new HighScoreMenu(this.Game, this)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + 150, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), SETTINGS, (menu) =>
                    {
                        SettingsMenu newMenu = new SettingsMenu(this.Game, this)
                        {
                            OldKeyState = this.CurrentKeyState
                        };
                        MenuManager.GetInstance().CurrentMenu = newMenu;
                    }));
            MenuItems.Add(new MenuItem(this, new Rectangle(Game.GraphicsDevice.Viewport.Width / 2 - MENU_ITEM_WIDTH / 2,
                    Game.GraphicsDevice.Viewport.Height / 2 + 300, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT), EXIT, (menu) =>
                    {
                        menu.Game.ExitGame();
                    }));

            MenuItems[currentlySelected].Selected = true;
        }