import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; /** * Implements all the other classes to play the game * mastermind. * * @author Andrew Szatkowski * @version 1.0 */ public class Driver { /** * the main method that carries the game out */ public static void main (String [] args) throws IOException { // instance of a buffered reader BufferedReader in = new BufferedReader (new InputStreamReader (System.in)); // constant values final int MAXPEGS = 8; final int MAXCOLORS = 6; final int MAXTURNS = 10; /** * instantiates a new user and gets the game settings */ User newUser = new User(); newUser.setName(in); newUser.setPegs(1, MAXPEGS, in); newUser.setColors(1, MAXCOLORS, in); // game begins boolean again = true; while (again) { // creates a new random answer Answer myAnswer = new Answer(newUser.getPegs(), newUser.getColors()); myAnswer.createAnswer(); // instantiates mastermind class Mastermind myMastermind = new Mastermind(MAXTURNS); myMastermind.clearScreen(); // instantiates row class Row myRow = new Row(newUser.getPegs()); myRow.recordAnswer(myAnswer.getAnswer()); // loops until game is won or lost boolean done = false; int turns = 0; while(!done && turns < MAXTURNS) { newUser.setGuess(in); myMastermind.clearScreen(); myMastermind.setGuessHistory(turns, newUser.getGuess()); newUser.parseGuess(); myRow.recordGuess(newUser.getParsedGuess()); myRow.scoreGuess(); myMastermind.setBlackHistory(turns, myRow.getBlack()); myMastermind.setWhiteHistory(turns, myRow.getWhite()); myMastermind.printHistory(turns + 1); done = myRow.done(); turns += 1; } // determines the outcome of the game if (done) { System.out.println("You win!"); newUser.posResult(); } else { System.out.println("You lose!"); newUser.negResult(); } newUser.printRecord(); again = myMastermind.playAgain(in); myMastermind.clearScreen(); myMastermind.resetHistory(); } } }