コード例 #1
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            backgroundTexture   = content.Load <Texture2D>("Gameplay/game_screen");
            tileModel           = content.Load <Model>("Gameplay//tile");
            highlightTileModel  = content.Load <Model>("Gameplay//tile_highlight");
            whitePieceModel     = content.Load <Model>("Gameplay//p2_piece");
            blackPieceModel     = content.Load <Model>("Gameplay//p1_piece");
            whitePieceTileModel = content.Load <Model>("Gameplay//p2_piece_tile");
            blackPieceTileModel = content.Load <Model>("Gameplay//p1_piece_tile");

            // reset the camera
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

            SimpleArcCamera.Reset((float)viewport.Width / (float)viewport.Height);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
コード例 #2
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (IsActive)
            {
                SimpleArcCamera.Update(gameTime);
                if (fallingPieceFrame > 0)
                {
                    fallingPieceFrame--;
                    if (fallingPieceFrame <= 0)
                    {
                        AudioManager.PlayCue("Drop");
                    }
                }
                if (fallingPieceFrame <= 0)
                {
                    player1.Update(board);
                    if (board.PieceCount > lastPieceCount)
                    {
                        lastPieceCount    = board.PieceCount;
                        fallingPieceFrame = fallingPieceFrames;
                    }
                }
                if (fallingPieceFrame <= 0)
                {
                    player2.Update(board);
                    if (board.PieceCount > lastPieceCount)
                    {
                        lastPieceCount    = board.PieceCount;
                        fallingPieceFrame = fallingPieceFrames;
                    }
                }
                if (board.GameOver)
                {
                    GameResult gameResult = GameResult.Tied;
                    if (board.WhitePieceCount > board.BlackPieceCount)
                    {
                        gameResult = GameResult.Player1Won;
                    }
                    else if (board.BlackPieceCount > board.WhitePieceCount)
                    {
                        gameResult = GameResult.Player2Won;
                    }
                    ExitScreen();
                    ScreenManager.AddScreen(new GameOverScreen(gameResult));
                }
            }
        }