Mastermind - GUI

Create a second interchangeable GUI view for the Mastermind model created in chapter 1.

The project

In the spirit of: make it run, make it right, make it fast, make it small; we will use eight iterations:
  1. Draw the bare board
  2. Draw the color palette at the bottom
  3. Select a color and put it in the first row
  4. Add the JButton at the bottom and put colors in each row
  5. Add GUI exposure processing
  6. Integrate MastermindModel and add black-white responses
  7. Allow a new game to be started when the game is won
  8. Allow the answer to be toggled above the board

Iteration 1

Let's start by simply drawing the outline for the board. The program should be intelligent enough to redraw the board when the window is resized. It should also support a variable number of rows.

Instructions and issues:

Iteration 2

2) draw color palette

Iteration 3

3) select color and column, insert color

Iteration 4

4) add JButton and row processing "Submit guess"

Iteration 5

5) add exposure processing, overlay lines on colors

Iteration 6

6) add model, input, bw, responses

Iteration 7

7) add go again?

Iteration 8

8) add answer

Iteration 1 - implementation

Listing 7.1

Iteration 2 - implementation

Added colors[] Dh = … ROWS+3 Added last for loop in paint() Increased height from 400 to 430 Listing 7.2

Iteration 3 - implementation

MouseListener, mousePressed Listing 7.3

Iteration 4 - implementation

JButton, addListener, add(SOUTH) Window height 430 to 450 ActionPerformed() currentRow=1 MousePressed – fillRect( dh*currentRow Listing 7.4

Iteration 5 - implementation

Guesses and init in ctor currentRow=0 drawBoard [setColor black], fillBoard mousePressed does not draw, it sets guesses and repaint Listing 7.5

Iteration 6 - implementation

Model, responses and init, input, bw mm.guess, responses, repaint second loop to fillBoard Listing 7.6

Iteration 7 - implementation

actionPerformed if-check bw else - reset call reset at top of ctor Listing 7.7

Iteration 8 - implementation

DisplayAnswer flag MousePressed – added if clause FillBoard – new top loop Listing 7.8