Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java chess board problem. At the end of the \"Drawing Images\" video, the beginn

ID: 3799559 • Letter: J

Question

java chess board problem.

At the end of the "Drawing Images" video, the beginnings of a chess board was drawn. In the video enough was completed to show a row of "Black Pawns". This program used the Piece.java and ChessPiece.java classes that you can find at the end of the "Drawing Images" notes.

Throw all of the images you see above into the top level of your project. Save them with names like: whiteQueen.gif

You can use some of the Checkers code, but it can get quite ugly pretty quickly because we have a more complicated situation than the 2 images in checkers.

See if you can use the following file productively to do the dirty work:
Result created on the video

Piece.java

Recreate this program and finish it so that all of the Chess Pieces are drawn. You can find the Chess Piece images at the end of the "Drawing Images" notes. Note that all of the chess piece drawing can be done by constructing appropriate "Piece" classes and calling the drawInPosition method.

Your program should look something like:

In the video, you will see a Chess Program constructor that looks something like:

Although this worked when I ran this on the video, it appears that it is a good idea to move the readInImages to be before the setVisible call. Otherwise it appears that we actually start painting the screen before we have completely read in all of the images. So have your constructor be something like:

Another HINT:

If you feel that putting together the KING rows is painful, you might find it helpful to make use of the following helper array:

The kingRow is exactly in the order that the pieces should be placed in their row. Using a for-loop, your kingRow will help you know where each piece goes.

Explanation / Answer

import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; enum ColorType {black, white}; enum PieceType {Pawn, Rook, Knight, Bishop, Queen, King}; class ChessPiece { private static PieceType[] pieceType= PieceType.values(); private static ColorType[] colorType = ColorType.values(); public static ChessPiece[][]chessPieces = new ChessPiece[colorType.length][pieceType.length]; public static void readInImages() { for (int i=0; i