CSC 120 Programming Assignment 6

Note: You should not work on this assignment during lecture or lab class-time unless:
  1. You have completed all of the in-class assigned work for the day, and
  2. You have permission from the instructor.

Overview:

Write a Java Application program that plays a game that moves game pieces around a game board.  This program will use an array of objects, each of which represents a player or game piece.  Each game piece keeps track of the spot on the game board where it is located, and has methods to move and draw itself.  You should have one object from a Background class that represents the game board.

Instructions:

  1. Create an application called PA6. It should contain two classes named MUFrame and MUPanel.  Start with the three files in the MUFrame with GUI designer .zip file available on the Student Resources page of the course web site.

  2. At a minimum, your application must be capable of playing a game between a fixed number of players.  Game pieces will move in one direction from the starting point to the finish point or goal.

  3. The user interface should include a button that the user will click repeatedly to cause the game to proceed.  Whenever the user clicks the button, all of the pieces in the game will take one turn in the game -- the number of spaces a piece advances must be randomly determined.  Clicking the button repeatedly will cause the pieces to move toward the finish point until one or more pieces reaches the game's goal on a turn and wins the game.

  4. The program must be able to detect when one of the pieces in the array has reached the goal or won the game.  Alternatively, the program could detect when one of the pieces has lost the game (fell in a pit, was eaten by a tiger, etc.).  In other words, the program must be able to detect when the game is over.

  5. When the game is over, clicking the button should not cause any more movement of the pieces on the screen.  This can be accomplished with a Boolean property that tracks whether the game is over or not.  If the game is over, the pieces should not make any subsequent moves.

  6. The game board:
    You'll need a Background class or Board class.  Instantiate one such object for the game board.  In the paintComponent method of the MUPanel, draw the board first.
  7. The game pieces or players:
    You'll need a GamePiece or Player class.  Data members should include a color, integers to keep track of the piece's current position, a piece name or piece number, and perhaps other stuff if you see the need.  Everyone should try to make their game pieces look different or unusual.  This class will need some kind of method to make the object move on the screen somehow, and also a method for drawing the object.
  8. array of game pieces:
    The MUPanel class must declare and use an array of players/pieces.  Each piece keeps track of the space on the game board (or the over & down of) where it is currently located.  At the start of the game, each piece should be drawn on its starting location.  As the game progresses, each click of the button will cause all the pieces to take one turn in the game.
  9. method in MUPanel called by the actionPerformed of the button in MUFrame:
    Each time the button is clicked, the program must execute a loop that will cause each piece in the array to take a turn (move).  The number of spaces a piece moves should be randomly determined.
  10. paintComponent method in MUPanel:
    Ask the game board to draw itself, then use a loop to ask each of the pieces in the array to draw themselves.
  11. constructor method in MUPanel:
    Instantiate the board object, instantiate the array of game pieces, and instantiate each the game pieces in the array.  Be sure that the pieces are located at their appropriate starting locations.
  12. Don't forget your comment header for MUPanel, and put a comment header in each of the "background" and "player" class files.

Turning in your Program for Grading:

Convert your CSC120\Java\PA6 folder into a .zip file named PA6.zip and submit it to the PA6 dropbox in D2L.

Note: It is expected that each student will complete this assignment INDIVIDUALLY.

Examples:

Ideas for Enhancement of the Basic Requirements:

Use your creativity to enhance the basic game.  Here are some suggestions for enhancing your game (you are not limited to this list - try things out!): There are many more fun things you could include in this project.  Enjoy!

Grading Rubric:

CSC 120, PA6, your name, date & Description comments in MUPanel.java. 2
The Description comment must include a discussion of the goal of the program; how is the game won (or lost)?  When is the game over? 2
Project contains a "background" class and one "background" object that is drawn on screen and represents the game board. 5
Project contains a "player" or "game piece" class and an array of objects from that class that are drawn on screen and move when the game is played. 10
All game pieces in the array move somehow when a button is clicked. 6
Game pieces move randomly, so when button is clicked, each piece may move a different number of "spaces" on the game board. 6
Program detects when the game has been won or lost. 6
Game stops when someone has won or lost – subsequent clicks on the button cause no more movement of the pieces. 6
Your code is easy to read, and indented consistently. 2
Total 45