Example #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            m_mapSize = 48;

            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth  = 1024;

            if (!m_debugView.m_debugOptions.m_withVS)
            {
                graphics.SynchronizeWithVerticalRetrace = false;
                IsFixedTimeStep = false;
            }

            graphics.ApplyChanges();

            //graphics.ToggleFullScreen();

            m_windowHeight = graphics.GraphicsDevice.Viewport.Height;
            m_windowWidth  = graphics.GraphicsDevice.Viewport.Width;

            m_save = new ModelClasses.Save();

            m_menu = new ViewClasses.Menu.Menu(m_gameAssets, m_save);

            m_game         = new ModelClasses.Game(m_gameAssets, m_mapSize, m_mapSize);
            m_game.m_state = ModelClasses.Game.GameState.Main;

            m_gameAssets.LoadHeightMap(graphics.GraphicsDevice, m_game.m_map);

            m_gameView = new ViewClasses.GameView(graphics.GraphicsDevice, m_gameAssets, m_game);

            m_game.SetParticleHandler(m_gameView.m_particleHandler);

            m_gameView.m_mapTransformer.LoadGraphicsContent(graphics.GraphicsDevice);

            m_debugView.InitilizePositions();

            //LOLOL  Mouse wasn't visible for a strategy game at first, LOLOL!!
            IsMouseVisible = true;
            Window.Title   = "Cubes are cute";

            ViewClasses.BoundingBoxBuffer.InitiliazeBuffers(graphics.GraphicsDevice);
        }
Example #2
0
        public void MenuHandling(GraphicsDevice a_graphics, ref ModelClasses.Game a_game, ViewClasses.Menu.Menu a_menu,
                                 ViewClasses.DebugView a_debugView, ViewClasses.GameAssets a_gameAssets, ref ViewClasses.GameView a_gameView)
        {
            //When menu is opened
            if (m_input.KeyClicked(m_input.m_f1))
            {
                if (a_menu.m_menuState == Menu.MenuState.None)
                {
                    a_game.m_state = ModelClasses.Game.GameState.Pause;

                    a_menu.m_menuState = Menu.MenuState.InGameMenu;
                }
                else if (a_menu.m_menuState == Menu.MenuState.Main)
                {
                    //Nothing
                }
                //when it's closed
                else
                {
                    a_game.m_state = ModelClasses.Game.GameState.Game;
                }
            }
            else
            {
                //Checks to se if mouse is in the menu area
                if (m_input.m_mouse.m_mouseState.Y < Menu.m_menu.Bottom && m_input.m_mouse.m_mouseState.X > Menu.m_menu.Left)
                {
                    VisualMenuCheck(a_menu);

                    if (m_input.mouseLeftClick())
                    {
                        if (a_menu.m_menuState == Menu.MenuState.Main)
                        {
                            if (ButtonPress(a_menu.m_mainButtons[0]))
                            {
                                a_menu.m_menuState = Menu.MenuState.PreGame;
                            }
                            else if (ButtonPress(a_menu.m_mainButtons[1]))
                            {
                                a_menu.m_menuState = Menu.MenuState.Load;
                            }
                            else if (ButtonPress(a_menu.m_mainButtons[2]))
                            {
                                a_menu.m_menuState = Menu.MenuState.Options;
                            }
                            else if (ButtonPress(a_menu.m_mainButtons[3]))
                            {
                                MasterController.m_exit = true;
                            }
                        }
                        else if (a_menu.m_menuState == Menu.MenuState.PreGame)
                        {
                            //Starts a session to play against computer
                            if (ButtonPress(a_menu.m_play))
                            {
                                ModelClasses.Game f_game        = new ModelClasses.Game(a_gameAssets, MasterController.m_mapSize, MasterController.m_mapSize);
                                GameBuilder       f_gameBuilder = new GameBuilder();

                                f_gameBuilder.BuildWorldForFour(f_game, a_gameAssets);

                                a_gameAssets.LoadHeightMap(a_graphics, f_game.m_map);

                                a_gameView = new ViewClasses.GameView(a_graphics, a_gameAssets, f_game);

                                f_game.SetParticleHandler(a_gameView.m_particleHandler);

                                a_gameView.m_mapTransformer.LoadGraphicsContent(a_graphics);

                                a_game = f_game;

                                a_menu.m_menuState = Menu.MenuState.None;
                            }
                            //Starts a Session to observe a Computer battle
                            else if (ButtonPress(a_menu.m_observer))
                            {
                                ModelClasses.Game f_game = new ModelClasses.Game(a_gameAssets, MasterController.m_mapSize, MasterController.m_mapSize);

                                f_game.SetParticleHandler(a_gameView.m_particleHandler);

                                a_gameAssets.LoadHeightMap(a_graphics, f_game.m_map);

                                a_gameView = new ViewClasses.GameView(a_graphics, a_gameAssets, f_game);

                                f_game.SetParticleHandler(a_gameView.m_particleHandler);

                                a_gameView.m_mapTransformer.LoadGraphicsContent(a_graphics);

                                a_game = f_game;

                                a_menu.m_menuState = Menu.MenuState.None;
                            }
                            //Return u to main menu
                            else if (ButtonPress(a_menu.m_ret))
                            {
                                a_menu.m_menuState = Menu.MenuState.Main;
                            }
                        }
                        else if (a_menu.m_menuState == Menu.MenuState.InGameMenu)
                        {
                            //Return to game button
                            if (ButtonPress(a_menu.m_return))
                            {
                                a_game.m_state = ModelClasses.Game.GameState.Game;
                            }

                            //Options button
                            else if (ButtonPress(a_menu.m_options))
                            {
                                a_menu.m_menuState = Menu.MenuState.Options;
                            }

                            //Save button
                            else if (ButtonPress(a_menu.m_save))
                            {
                                a_menu.m_menuState = Menu.MenuState.Save;
                            }

                            //Load Button
                            else if (ButtonPress(a_menu.m_load))
                            {
                                a_menu.m_menuState = Menu.MenuState.Load;
                            }

                            //Main Menu Button
                            else if (ButtonPress(a_menu.m_quit))
                            {
                                a_game.m_state     = ModelClasses.Game.GameState.Main;
                                a_menu.m_menuState = Menu.MenuState.Main;
                            }

                            //Quit button
                            else if (ButtonPress(a_menu.m_ret))
                            {
                                MasterController.m_exit = true;
                            }
                        }

                        //Options Screen
                        else if (a_menu.m_menuState == Menu.MenuState.Options)
                        {
                            if (a_game.m_state == ModelClasses.Game.GameState.Main)
                            {
                                //Debug Button
                                if (ButtonPress(a_menu.m_debug))
                                {
                                    a_menu.m_menuState = Menu.MenuState.DebugMenu;
                                }
                                else if (ButtonPress(a_menu.m_ret))
                                {
                                    a_menu.m_menuState = Menu.MenuState.Main;
                                }
                            }
                            else
                            {
                                //Debug Button
                                if (ButtonPress(a_menu.m_debug))
                                {
                                    a_menu.m_menuState = Menu.MenuState.DebugMenu;
                                }
                                else if (ButtonPress(a_menu.m_ret))
                                {
                                    a_menu.m_menuState = Menu.MenuState.InGameMenu;
                                }
                            }
                        }

                        //Debug Screen
                        else if (a_menu.m_menuState == Menu.MenuState.DebugMenu)
                        {
                            if (ButtonPress(a_menu.m_ret))
                            {
                                a_menu.m_menuState = Menu.MenuState.Options;
                            }
                            else
                            {
                                for (int i = 0; i < a_menu.m_checkBoxes.Length; i++)
                                {
                                    if (a_menu.m_checkBoxes[i].m_state == CheckBox.ChkState.Checked)
                                    {
                                        a_debugView.m_debugOptions.m_options[i] = true;

                                        a_debugView.m_debugOptions.Update();
                                    }
                                    else if (a_menu.m_checkBoxes[i].m_state == CheckBox.ChkState.Unchecked)
                                    {
                                        a_debugView.m_debugOptions.m_options[i] = false;

                                        a_debugView.m_debugOptions.Update();
                                    }
                                }
                            }
                        }
                        //Save screen
                        else if (a_menu.m_menuState == Menu.MenuState.Save)
                        {
                            if (ButtonPress(a_menu.m_ret))
                            {
                                a_menu.m_menuState = Menu.MenuState.InGameMenu;
                            }
                            //New save button
                            //It creates a new save slot and saves the game and adds it to the save/load screens
                            else if (ButtonPress(a_menu.m_newSave))
                            {
                                m_save.TryToSave(a_game, "New Save");

                                //in order to update save/load screens to populate new saves
                                a_menu.UpdateSlots(a_gameAssets, m_save);

                                a_game.m_state = ModelClasses.Game.GameState.Game;
                            }
                            else if (ButtonPress(a_menu.m_Sup))
                            {
                                a_menu.ScrollUp();

                                a_menu.UpdateSlots(a_gameAssets, m_save);
                            }
                            else if (ButtonPress(a_menu.m_Sdown))
                            {
                                a_menu.ScrollDown();

                                a_menu.UpdateSlots(a_gameAssets, m_save);
                            }
                            else
                            {
                                //Loops through the saves to see if user have pressed a save and if true it saves the game and break
                                Button f_click = ButtonClicked(a_menu.m_saves);

                                if (f_click != null)
                                {
                                    m_save.TryToSave(a_game, f_click.m_buttonText);

                                    a_menu.UpdateSlots(a_gameAssets, m_save);

                                    a_game.m_state = ModelClasses.Game.GameState.Game;
                                }
                            }
                        }
                        //Load screen
                        else if (a_menu.m_menuState == Menu.MenuState.Load)
                        {
                            if (ButtonPress(a_menu.m_Lup))
                            {
                                a_menu.ScrollUp();

                                a_menu.UpdateSlots(a_gameAssets, m_save);
                            }
                            else if (ButtonPress(a_menu.m_Ldown))
                            {
                                a_menu.ScrollDown();

                                a_menu.UpdateSlots(a_gameAssets, m_save);
                            }
                            else
                            {
                                Button f_click = ButtonClicked(a_menu.m_loaded);

                                if (f_click != null)
                                {
                                    ModelClasses.Game f_game = m_save.TryToLoad(f_click.m_buttonText);

                                    if (f_game != null)
                                    {
                                        f_game.InitializeModels(a_gameView.m_particleHandler, a_gameAssets);

                                        a_gameAssets.LoadHeightMap(a_graphics, f_game.m_map);

                                        a_gameView = new ViewClasses.GameView(a_graphics, a_gameAssets, f_game);

                                        f_game.SetParticleHandler(a_gameView.m_particleHandler);

                                        a_gameView.m_mapTransformer = new ViewClasses.MapTransformer(f_game.m_map);

                                        a_gameView.m_mapTransformer.LoadGraphicsContent(a_graphics);

                                        a_game = f_game;

                                        a_game.m_state = ModelClasses.Game.GameState.Game;
                                    }
                                }
                            }

                            if (a_game.m_state == ModelClasses.Game.GameState.Main)
                            {
                                if (ButtonPress(a_menu.m_ret))
                                {
                                    a_menu.m_menuState = Menu.MenuState.Main;
                                }
                            }
                            else
                            {
                                if (ButtonPress(a_menu.m_ret))
                                {
                                    a_menu.m_menuState = Menu.MenuState.InGameMenu;
                                }
                            }
                        }
                        else if (a_menu.m_menuState == Menu.MenuState.Win)
                        {
                            if (a_game.m_state == ModelClasses.Game.GameState.GameOver)
                            {
                                if (ButtonPress(a_menu.m_ret))
                                {
                                    a_game.m_state = ModelClasses.Game.GameState.Main;

                                    a_menu.m_menuState = Menu.MenuState.Main;
                                }
                            }
                        }
                        else if (a_menu.m_menuState == Menu.MenuState.Lose)
                        {
                            if (a_game.m_state == ModelClasses.Game.GameState.GameOver)
                            {
                                if (ButtonPress(a_menu.m_ret))
                                {
                                    a_game.m_state = ModelClasses.Game.GameState.Main;

                                    a_menu.m_menuState = Menu.MenuState.Main;
                                }
                            }
                        }
                    }
                }
            }
        }