A console-based Mastermind game written in Java. This project is an improved version of Mastermind 1.0 and demonstrates clean structure, methods, arrays, loops, input validation, and exception handling.
-
Difficulty levels:
- Easy (4 positions, 6 colors)
- Medium (5 positions, 8 colors)
- Hard (6 positions, 10 colors)
-
Player chooses the maximum number of attempts (between 5 and 15)
-
Randomly generated secret code
-
Feedback system:
- Black pin = correct color, correct position
- White pin = correct color, wrong position
-
Input validation with try/catch
-
Structured code using methods and class fields
mastermind/
โโโ Mastermind.java
โโโ MastermindFuncties.java
-
Mastermind.javaStarts the application and calls the game logic. -
MastermindFuncties.javaContains all game functionality such as:- Game flow
- Difficulty selection
- Code generation
- Game loop
- Input validation
- Open the project in an IDE (for example IntelliJ IDEA, Eclipse, or VS Code).
- Make sure both files are inside the
mastermindpackage. - Run
Mastermind.java.
- Start the game.
- Choose a difficulty level (1, 2, or 3).
- Choose the maximum number of attempts.
- Watch out! Because colors can be reused, meaning the code could be green green blue red or green blue blue blue.
- Enter your guesses as colors separated by spaces, for example:
red blue green yellow
-
After each guess you will receive feedback:
- Black pin = correct color in the correct position
- White pin = correct color in the wrong position
-
Guess the full code before your attempts run out to win the game.
This project demonstrates the use of:
- Classes and methods
- Arrays
- for, while and do-while loops
- if/else and switch-case
- try/catch exception handling
- Scanner for user input
- Random for generating the secret code
- Clean program structure and separation of responsibilities