/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (CheckersMain game = new CheckersMain()) { game.Run(); } }
/// <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; } } }