question archive JAVA)Problem Specification: Develop a program in Java using GUI components that will draw a checkerboard and place the checker pieces on it at their starting position as shown in Figure 1

JAVA)Problem Specification: Develop a program in Java using GUI components that will draw a checkerboard and place the checker pieces on it at their starting position as shown in Figure 1

Subject:Computer SciencePrice:3.87 Bought7

JAVA)Problem Specification: Develop a program in Java using GUI components that will draw a checkerboard and place the checker pieces on it at their starting position as shown in Figure 1. The board is made up of 64 alternating green and white squares which appear in 8 rows of 8. There are 32 green squares and 32 white squares. Each player places his pieces on the 12 green squares in the first three rows closest to the player. Each of these three rows should have a total of 4 checkers. Remember that checkers may only move in diagonal directions on the green squares. Since the board has 8 rows, 6 of the rows will be taken up by the players' checkers and the remaining two rows will be left open in the middle of the board. The pieces are specified by an 8-by-8 char array called boardStatus. The status of any given square is either r (red), b (balck), or e (empty) as shown in the figure below

The above design of the GUI involves three classes, CheckerPiece, CheckerBoard and CheckerGame. The specifications for these three classes are discussed below.

1. CheckerPiece Class:

This class represents a square in the checkerboard that extends the JComponent class.

It draws a square if it is empty (e) or a square with a black(b) and red(r) checkers if it is red or black respectively.

It overrides the paintComponent(Graphics g) method to draw.

You can use fillRect(), fillOval(), drawRect() methods to draw squares and checkers.

In this class, you will need to have the following instance variables and methods: o Instance variables: ? char status:

It stores the status of a square in the checkerboard. The valid values are 'r', 'b' and 'e'. ? int row, int column:

The row and column indices of the square in the checkerboard. For example, row is 0 and column is 0 for the top-left square in Figure 1. Also, row is 7 and column is 7 for the bottom-right square.

? You can declare as many instance variables and constants as you think necessary. For example, you can define constant variables for the height and width of the squares and checkers, also you can do the same and define constants for the x and y coordinates for the squares and checkers.

In Figure 1, the length of the side of the squares is 60 pixels and the length of the side of the checkers is 40 pixels. o

Methods: ?

public CheckerPiece(int row, int column, char status) The constructor that sets the row, column and status of a checker piece. It throws an IllegalArgumentException if the value of the row, column or status is invalid. For example, row and column need to be between 0 and 7, and the status can either be 'e', 'b' or 'r'. Also, throw an IllegalArgumentException if there is an attempt to put a red or black checker on an invalid square i.e. checkers cannot be placed on white squares. ?

public void paintComponent(Graphics g) You need to Override the paintComponent function from JComponent class to draw checkerboard squares with or without the checker piece based on the value of the status.

You can add as many helper methods or inner classes as you think necessary if you would like to make it functional .

2. CheckerBoard Class:

This class represents a checkerboard that contains 64 CheckerPiece objects (squares with/without checkers).

It extends the JPanel class and adds 64 CheckerPiece objects to the panel.

You can use the GridLayout, 8 x 8, to organize the CheckerPiece objects on the panel.

In this class, you will need to have the following instance variables and methods: o Instance variables: ? char [][] boardStatus: A two-dimensional character array, 8 x 8, that stores the status value for each of the squares. ?

You can declare as many instance variables and constants as you think necessary.

I have defined two constants, ROW and COLUMN for the boardStatus array.

Methods: ?

public CheckerBoard(char [][] boardStatus) The constructor that sets the boardStatus array using the received parameter.

It also uses this array to instantiate 64 CheckerPiece objects based on the row, column and status values.

It adds all these objects to the panel. As mentioned above, you can use the GridLayout, 8 x 8, to organize the CheckerPiece objects on the panel. ?

public void setBoardStatus(char [][] boardStatus) A mutator method that sets the boardStatus array using the received parameter.

You can call repaint() method after setting the array to redraw the checker pieces based on the new value. ?

public void setCheckerPiece(int row, int column, char status) A mutator method that sets the status value for the square specified by row and column. You can call repaint() method after setting the status to redraw the checker pieces based on the new value.

You can add as many helper methods or inner classes as you think necessary if you would like to make it functional

. 3. CheckerGame Class: This driver class represents the checker game window. The checker game window has a checkerboard along with the status bar and menu bar. The status bar is a JPanel object with two JLabels that show the number of red and black checkers remaining during the game and the name of the programmer, YOUR NAME, who developed this game. That being said, the CheckerGame class extends JFrame to create window and adds a CheckerBoard object (a subclass of JPanel) and a status panel. It also adds a menu bar to the window as shown in Figure 2.

In this class, you will need to have the following instance variables and methods:

Instance variables: ? char [][] boardStatus: A two-dimensional character array, 8 x 8, that will represent the status of the required checkerBoard. stores the status value for each of the squares. See figure 2 (left)

You can declare as many instance variables and constants as you think necessary. I didn't use any for the non-functional GUI.

Methods: ? public CheckerGame() The constructor that sets the layout to organize and add the CheckerBoard object (a JPanel), the status bar (a JPanel object) and the menu bar (a JMenu Object). You need to pass a two-dimensional char array with boardStatus, same as Figure 1 and 2 (left) when you create CheckerBoard object. You can use the BorderLayout to set the layout of the JFrame to organize the components. Also, set the title, size or dimension, default close operation, etc. for the JFrame window as shown in Figure 1 and Figure 2 . I have used 505 x 585 pixels dimension for the game window displayed in Figure 1 and 2. Add menus and menu items to the menu bar as shown in Figure 2, you are not required to add actionlistener for these menu items

? public static void main(String[] args) Create object of the CheckerGame class and make the window visible. You can add as many helper classes and methods as you deem necessary. The classes and methods specified above are good enough for the non-functional GUI of a checkerboard game.

Notes: Your Program should Throw an IllegalArgumentException in the following situations: o The CheckerPiece class has the responsibility to throw the exception:

if the status of the square is anything other than the three characters 'r', 'b', and 'e'.

if there is an attempt to put a red or black checker on an invalid square of the checkerboard (checkers are only allowed to be placed on the green squares).

make the following:

1. Make the game work following the game rules described in the link above and summarized in the following majors rules: ? It should be a two-player game where the player with black checkers will play first and then the player with Red. These turns will continue until the game is over. ? A player can not move one space diagonally to an empty square or jump over the opponent's checker piece. ? You need to update the board with every valid move the players make. ? To move a checker piece, the player has to click on that piece and then click the empty square where she/he wants to move that piece. Don't move if a player makes an invalid move.

2. Make the menu items work from the menu bar functional according to the following ? New: It starts a new game. Resets the checkerboard to initial configuration. ? Exit: Exit the game or program. ? Checker Game Rules: Display a JOptionPane message box that has the link to the game rules. ? About Checker Game App: Display a JOptionPane message box that has your name, email and the university name.

3. Update the status, you need to update the status label with the current count of black and red checkers as the game goes on. Also, declare the winner (result) once the game is over.

 

Option 1

Low Cost Option
Download this past answer in few clicks

3.87 USD

PURCHASE SOLUTION

Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

rated 5 stars

Purchased 7 times

Completion Status 100%

Related Questions