Docsity

CS 3230 Lab #4: Creating a Stratego Game Board - Prof. Delroy Brinkerhoff, Lab Reports of Computer Science

Toggle sidebar
bg1
CS 3230 Lab #4
GUI’s 1
Assignment
Create the Stratego game board:
The board is divided into three areas: the playing field in the center and two “trays” of tokens on
either side. At this point, the program consists of six classes: Stratego.java, Board.java,
Space.java, Token.java, TokenHandler.java, and Ranks.java. TokenHandler will be provided.
1. Token
a. Implements Transferable (you must import java.awt.datatransfer.*)
b. Add an accessor method to get the player
c. Add the Transferable interface code (provided in token.txt)
d. You may add a second constructor for the lakes if you wish
2. TokenHandler - provided, no modifications needed
3. Ranks - unmodified from lab #3
pf3

Partial preview of the text

Download CS 3230 Lab #4: Creating a Stratego Game Board - Prof. Delroy Brinkerhoff and more Lab Reports Computer Science in PDF only on Docsity!

CS 3230 Lab

GUI’s 1

Assignment

Create the Stratego game board:

The board is divided into three areas: the playing field in the center and two “trays” of tokens on either side. At this point, the program consists of six classes: Stratego.java, Board.java, Space.java, Token.java, TokenHandler.java, and Ranks.java. TokenHandler will be provided.

  1. Token a. Implements Transferable (you must import java.awt.datatransfer.*) b. Add an accessor method to get the player c. Add the Transferable interface code (provided in token.txt) d. You may add a second constructor for the lakes if you wish
  2. TokenHandler - provided, no modifications needed
  3. Ranks - unmodified from lab #
  1. Stratego a. Extends JFrame and implements Ranks b. Includes the following constants and variable: public static final int SETUP = 0; public static final int DEMO = 1; public static final int QUIT = 2; public static final int PLAY = 3; public static final int RED = 1; public static final int BLUE = 2; public static final int WIDTH; public static final int HEIGHT; private static int mode = SETUP; c. The constructor: public Stratego() fills the trays and places the lakes and any other needed initialization d. Defines the accessor method: static public int getMode() { return mode; } e. Has the following static initializer block: static { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

WIDTH = (int)(screenSize.width / 18 - 1); HEIGHT = (int)(screenSize.height / 12); } f. Defines main

  1. Board a. Extends JPanel but replaces the default layout manager b. Constructor: public Board(int rows, int cols) where “rows” and “cols” are the number of rows and columns in the board respectively (this permits the trays to be implemented as instances of Board) c. Defines a method public void putTokenAt(Token token, int i, int j)
  2. Space a. Extends JPanel b. Defines the following transfer handler (as a class variable) to support drag and drop: private static final TransferHandler tokenHandler = new TokenHandler(); c. Defines two instance variables to remember the row and column location of the space; has a Token (i.e., an instance variable of type Token), which is null whenever the space is empty d. Constructor: public Space(int row, int col) i. Performs various initialization tasks (setting the preferred size, background color, event handling, etc.) ii. Sets the transfer handler: setTransferHandler(tokenHandler); e. Should define three token methods (called from TokenHandler) i. public void setToken(Token t): sets the aggregated token but also adds the token to the space’s layout manager and calls repaint() (see Die.java, roll)