Пример #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            KeyboardState newState = Keyboard.GetState();

            input.UpdateWithNewState(newState, gameTime);

            if (input.WasKeyPressed(Keys.Escape, false))
            {
                if (state == gameState.IN_PROGRESS)
                {
                    state = gameState.PAUSED;
                    menu = new Menu(this, pausedItems);
                }
            }

            switch (state)
            {
                case gameState.PAUSED:
                    returnVal = menu.Update(gameTime);
                    if (returnVal == 1)
                    {
                        state = gameState.IN_PROGRESS;
                        menu = null;
                    }
                    else if (returnVal == 2)
                    {
                        this.Exit();
                    }
                    break;
                case gameState.MAIN_MENU:
                    returnVal = menu.Update(gameTime);
                    if (returnVal == 1)
                    {
                        state = gameState.IN_PROGRESS;
                        menu = null;
                    }
                    else if (returnVal == 2)
                    {
                        this.Exit();
                    }
                    break;
            }

            base.Update(gameTime);
        }
Пример #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<SpriteFont>("SpriteFont1");

            //menu = new Menu(this);
            //normally I'd initialize file I/O, and read these from a file
            pausedItems = new List<string>();
            pausedItems.Add("PAUSED");
            pausedItems.Add("Continue Game");
            pausedItems.Add("Exit Game");

            mainMenuItems = new List<string>();
            mainMenuItems.Add("A Game of Blocks and Lines");
            mainMenuItems.Add("New Game");
            mainMenuItems.Add("Exit");

            menu = new Menu(this, mainMenuItems);
        }