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.
Boolean
property that tracks whether the game is
over or not. If the game is over, the pieces should not make any subsequent moves.
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.
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.
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.
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.
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.
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.
Convert your
CSC120\Java\PA6 folder into a .zip file named PA6.zip
and submit it to the PA6 dropbox
in D2L.
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!
- Choose game pieces that are rather complicated to draw (a car, a horse, etc.). Or perhaps each piece in the game will have a different shape, like the different pieces in a game of Monopoly.
- Change the game board so that pieces don't always move in one direction throughout the game. For example, the game board might zig-zag across the screen from left to right, then right to left, etc. (think of the games Chutes and Ladders or The Game of Life), or might go around the screen as in a Monopoly game board.
- Keep track of the number of turns have been taken in the game, and display that on the screen.
- Place an identifying number or label on each game piece when it is drawn on screen that isn't just a number from 1 to n. As an example, if you are a NASCAR fan, you could write a game that moves cars around a game board, and have the first car represent Kyle Busch #18, the second car be Dale Earnhart, Jr. #88, etc..
- Draw a game standings list in the Graphical Output window showing which player is in first place, second place, etc. at the current time. Update the standings each time the button is clicked.
- Set up different victory conditions -- rather than winning by reaching a particular spot on the board, a player might win by accumulating points. Landing on differently-colored board positions might earn different numbers of points, for example.
- Develop a game where a piece may have to move backwards a certain number of positions or return to the start position if it lands on a "penalty" position on the game board. When the game board is drawn, the "penalty" positions should be drawn differently from "normal" squares.
- Assess a penalty of some number of positions that a player will have to move backwards if the player lands on a game board position that is already occupied by another player's piece.
- Add "bonus" positions to the game board -- this means that if a piece lands on a "bonus" position, the piece may move some extra number of positions toward the final position for the game. Another idea would be to give a bonus number of moves to a player that rolls "doubles" in a two-dice game.
- Maybe you could have different game boards/backgrounds for different "levels" of the game -- when a player has reached the winning space on the board, the game "levels-up" to the next game board/background.
- You could use animation to cause the pieces to move without the need to click a "Take Next Turn" button. Once the "Start Game" button is clicked, the game moves along by itself until there is a winner. If you do this, be sure to use an appropriate delay so that the game doesn't run too fast or slow.
- Implement some actual game that you have played and like.
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 |