Mastermind is a code-breaking game where the objective is to guess a secret 4 color code within a limited number of attempts (~10). After each guess, the player receives feedback on how many colors are correct and in the correct position (like wordle!). The game can be played in two modes: the player sets the code for the program to guess, or the program sets the code for the player to break. The goal is to guess the code in as few attempts as possible!
- Gameplay with GUI: Play the game through a user-friendly graphical interface built using JavaFX.
- Algorithm Solvers: The program can guess the code set by the player through 3 algorithms/levels.
- Donald Knuth's Algorithm (Hard mode): A highly optimized algorithm that solves the code in ~5 or fewer guesses.
- Medium Algorithm (Medium mode): A balanced guessing algorithm with reasonable performance.
- Basic Algorithm (Easy mode): A straightforward guessing approach suitable for beginners.
- Human Solver: Players can guess the code based on provided hints from the computer.
- File Handling: Supports saving and loading game data from external files.
- Code Guessing Levels: Provides multiple levels for guessing the code.
- Easy: 1-3 colors
- Medium: 3-4 colors
- Hard: 4 colors
- User Response Validation: Ensures that all hints provided by the system are valid and correctly aligned with the player's guess.
- Return to a Previous Game: Allows players to save and load unfinished games, picking up where they left off.
- Popup Window: Displays a prompt if there is an unfinished game, offering the player the option to either return to it or start a new game.
- Home Button: Quickly returns the player to the main menu or home screen for easy navigation.
- New Game: Enables players to start a new game with a different mode or level, providing variety in gameplay.
For detailed API documentation, you can view the Javadocs for this project.
Before you begin, ensure you have the following installed:
- Java Development Kit (JDK) 11 or later
- Eclipse IDE
- JavaFX SDK
- Download the JavaFX SDK
- Visit Gluon and download the JavaFX SDK.
- Extract the JavaFX SDK
- Extract the downloaded ZIP file to a location on your computer.
- Configure JavaFX in Eclipse
- In Eclipse, go to
Window > Preferences > Java > Build Path > User Libraries. - Click New, name the library
JavaFX. - Select the
JavaFXlibrary and click Add External JARs. - Navigate to the
libfolder in your extracted JavaFX SDK and select all the JAR files. - Click Apply and Close.
- In Eclipse, go to
- Clone this repository or download the source code
- Import the Project into Eclipse
- In Eclipse, go to
File > Import > General > Existing Projects into Workspace. - Select the root directory of the downloaded project and click Finish.
- In Eclipse, go to
Set JavaFX Library in Eclipse
- Right-click on the project in Eclipse's Package Explorer.
- Select
Properties > Java Build Path. - In the
Librariestab, click Add Library and select User Library. - Check the
JavaFXlibrary you created earlier and click Finish. - In the
Order and Exporttab, ensure theJavaFXlibrary is checked. - Click Apply and Close.
- Run the Main Class
- Right-click on the main class file (
mastermind.java). - Select
Run As > Run Configurations.
- Right-click on the main class file (
- Set VM Arguments
- In the
Argumentstab, add the following to VM arguments:Replace--module-path /path/to/javafx-sdk-17/lib --add-modules javafx.controls,javafx.fxml/path/to/javafx-sdk-17with the actual path to your JavaFX SDK.
- In the
- Run the Application
- Click Apply and then Run.