Title: Chess Problem
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Chess 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.

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:

public ChessBoard()
  {
  super("Chess ... a great game");
  setSize(800, 600);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  ChessPiece.readInImages();
  }


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:


  public ChessBoard()
  {
  super("Chess ... a great game");
  ChessPiece.readInImages();
  setSize(800, 600);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  }


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:


  // Helper Array
  PieceType[] kingRow = {PieceType.Rook, PieceType.Knight, PieceType.Bishop, PieceType.Queen,
  PieceType.King, PieceType.Bishop, PieceType.Knight, PieceType.Rook};


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.

Last Updated: June 15, 2014 3:31 PM