Example #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();

            if(Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                m_bInitGame = true;
                m_bCanBePressed = true;
                m_bResetGame = true;
                return;
            }

            if(!m_bInitGame)
                return;

            if (Keyboard.GetState().IsKeyDown(Keys.F10))
            {
                m_bResetGame = true;
                return;
            }

            if (Mouse.GetState().LeftButton == ButtonState.Released)
            {
                m_updateCounts++;
                m_bCanBePressed = true;
                return;
            }

            if (m_bResetGame)
                return;

            if ((m_playTurn == Play_Turn.White_Turn) && (m_bPlayerWhiteCPU))
            {
                m_cpuPlayer.setTeam(false); // White team.
                Play play = m_cpuPlayer.getCPUPlay(m_gameTable);
                m_gameTable.move(play);
                m_soundKlik.Play();

                if( m_gameTable.CheckMate )
                {
                    m_bInitGame = false;
                    m_stateSplash = SPLASH_STATES.WINNER_WHITE;
                }
                else
                {
                    changeTurn( );
                }

                base.Update(gameTime);

                return;
            }

            if ((m_playTurn == Play_Turn.Black_Turn) && (m_bPlayerBlackCPU))
            {
                m_cpuPlayer.setTeam(true); // Black team.
                Play play = m_cpuPlayer.getCPUPlay(m_gameTable);
                m_gameTable.move(play);
                m_soundKlik.Play();

                if( m_gameTable.CheckMate )
                {
                    m_bInitGame = false;
                    m_stateSplash = SPLASH_STATES.WINNER_BLACK;
                }
                else
                {
                    changeTurn( );
                }

                base.Update(gameTime);

                return;
            }

            if ((m_bCanBePressed) && (Mouse.GetState().LeftButton == ButtonState.Pressed))
            {
                if (m_updateCounts <= 26)
                    return;

                m_updateCounts = 0;
                Rectangle rectMouse;
                rectMouse.X = Mouse.GetState().X;
                rectMouse.Y = Mouse.GetState().Y;
                rectMouse.Width = 1;
                rectMouse.Height = 1;

                if (ClickOnTarget(rectMouse))
                {
                    m_pointSquareSelection.X = -1;
                    m_pointSquareSelection.Y = -1;
                    m_listTargetsMovements = null;
                    m_bPieceSelected = false;

                    if( m_gameTable.CheckMate )
                    {
                        m_bInitGame = false;

                        if (m_playTurn == Play_Turn.Black_Turn)
                            m_stateSplash = SPLASH_STATES.WINNER_BLACK;
                        else
                            m_stateSplash = SPLASH_STATES.WINNER_WHITE;

                    }
                    else
                    {
                        changeTurn( );
                    }

                    base.Update(gameTime);

                    return;
                }

                ClickOnPiece(rectMouse);

            }

            base.Update(gameTime);
        }
Example #2
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()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            m_rectTable.X = 0;
            m_rectTable.Y = 0;
            m_rectTable.Width = 640;
            m_rectTable.Height = 640;

            m_graphics.PreferredBackBufferHeight = 640;
            m_graphics.PreferredBackBufferWidth = 640;
            m_graphics.ApplyChanges();

            m_listTargetsMovements = new List<Point>();

            m_gameTable = new Table();

            m_bPieceSelected = false;
            m_bResetGame = true;
            m_bInitGame = false;

            m_bCanBePressed = false;
            m_updateCounts = 0;

            m_stateSplash = SPLASH_STATES.OPEN;

            m_playTurn = Play_Turn.White_Turn;
            m_bPlayerBlackCPU = true;
            m_bPlayerWhiteCPU = false;
            m_cpuPlayer = new MiniMax();
            m_cpuPlayer.setTeam(m_bPlayerBlackCPU); // CPU is with Black pieces.

            m_DeadBlackSpaces = new Rectangle[TOTAL_BLACK_PIECES];
            m_DeadWhiteSpaces = new Rectangle[TOTAL_WHITE_PIECES];

            InitializeDeadSpaces();

            m_gameTable.calculateWhitePiecesPosition( false );

            m_rectPlayNow.Height = 100;
            m_rectPlayNow.Width = 20;
            m_rectPlayNow.X = (36 / 2) - (m_rectPlayNow.Width/2);
            m_rectPlayNow.Y = (640 / 2) - (m_rectPlayNow.Height/2);

            m_rectButton.Height = 20;
            m_rectButton.Width = m_rectPlayNow.Width;
            m_rectButton.X = (36 / 2) - (m_rectButton.Width / 2);
            m_rectButton.Y = ((m_rectPlayNow.Y + m_rectPlayNow.Height) + 4);

            m_rectSplashScreens.Height = 300;
            m_rectSplashScreens.Width = 400;
            m_rectSplashScreens.X = (m_rectTable.Width / 2) - (m_rectSplashScreens.Width / 2);
            m_rectSplashScreens.Y = (m_rectTable.Height / 2) - (m_rectSplashScreens.Height / 2);
        }