/// <summary> /// Function handles the updating of checkers piece. /// This function is called whenever a successful move is done. /// This function will update the piece's position on the board, and change who's turn it is. /// </summary> /// <param name="gameState">The gamestate to update</param> public void Update(CheckersGameState gameState) { if (destination != Vector2.Zero) { position = destination; destination = Vector2.Zero; if (gameState.turnColor == PieceColor.Black) { gameState.changePlayerTurn(PieceColor.White); } else { gameState.changePlayerTurn(PieceColor.Black); } } }
/// <summary> /// Update function that is called periodically by the game engine /// </summary> /// <param name="main">Main driver for the game</param> /// <param name="gameTime">Gametime recieved by the main</param> public void Update(CheckersMain main, GameTime gameTime) { //Below handles the animated marking of the active game piece if (currentState.activeGamePiece != null) { if (currentState.activeGamePiece.rotation - CheckersPiece.ROTATION_SPEED * MathHelper.TwoPi < 0) { currentState.activeGamePiece.rotation -= CheckersPiece.ROTATION_SPEED * MathHelper.TwoPi + MathHelper.TwoPi; } else { currentState.activeGamePiece.rotation -= CheckersPiece.ROTATION_SPEED * MathHelper.TwoPi; } } //Below sets the first player in the game to black when a game is started if (currentState.turnColor == PieceColor.None && currentState.blackGamePieces.Count > 0) { currentState.changePlayerTurn(PieceColor.Black); } //Below takes care of running alpha-beta when it is the computer's turn, //and doing the best move selected by the algorithm if (currentState.turnColor == currentState.aiColor && currentState.winner == PieceColor.None) { if (aiThread == null) { aiThread = new Thread(doAiMove); aiThread.Start(); } } //If this case is reached, it means that it was the player's turn, and any mouse events should be processed else { int mouseX = Mouse.GetState().X; int mouseY = Mouse.GetState().Y; //Handle mouse events for the game only if it's not minimized if (Mouse.GetState().LeftButton == ButtonState.Pressed && isMousePressed == false && main.IsActive) { isMousePressed = true; handleMouseAction(mouseX, mouseY); } //Handle mouse events for the game only if it's not minimized if (Mouse.GetState().LeftButton == ButtonState.Released && main.IsActive) { isMousePressed = false; } } //If the computer finishes (thread is sleeping) join the two threads and set the thread back to null if (aiThread != null) { if (aiThread.IsAlive == false) { aiThread.Join(); aiThread = null; } } }