A JavaFX implementation of the classic 24 Game where players use basic arithmetic operations to make four card values equal 24.
In this game, players are presented with four randomly selected playing cards and must use addition, subtraction, multiplication, and division to create a mathematical expression that equals 24 using each card exactly once. For example, if given cards with values 3, 8, 8, and 3, a valid solution might be: (8 / (3 - (8 / 3))) = 24.
- JavaFX-based graphical user interface
- Random card generation with standard playing card images
- Ability to verify user solutions
- Built-in solution finder algorithm
- Hint system that progressively reveals solution pattern
- Optional OpenAI API integration for alternative hint generation
- Java 11 or higher
- JavaFX
- exp4j library for expression evaluation
- SimpleOpenAI (optional, for API integration)
-
Clone this repository:
git clone https://github.com/yourusername/24-card-game.git -
Build the project using Maven:
mvn clean install -
If you want to use the OpenAI API integration:
- Set the environment variable
OPENAI_API_KEYwith your API key - Uncomment the relevant code in
GameController.java
- Set the environment variable
- Launch the application
- Four random cards will be displayed
- Enter your mathematical expression in the text field using the numbers corresponding to the card values
- Click "Verify" to check if your solution is correct
- Use "Hint" for help (after several attempts, the pattern of operators will be revealed)
- Click "Refresh" to get a new set of cards
- You must use each card exactly once
- You can use only addition, subtraction, multiplication, and division
- You can use parentheses to change the order of operations
- Each card value must be used as is (e.g., a King is 13, not 10+3)
GameController.java: Main controller handling UI events and game logicrandomCard.java: Generates random cards from the deckCardValue.java: Converts card images to numerical valuesSolution.java: Algorithm to verify and find 24 Game solutionsApi.java: Optional OpenAI API integration for hint generation
- Score tracking system
- Difficulty levels
- Timed mode
- Multiplayer support
- Inspired by the classic 24 Game
