The Grand Heist is a 2-player strategy game I built for my Programming Languages and Techniques I (CIS 1200) course. One player plays as the Rob the Robber, and the other as Pol the Police. Rob’s goal is to collect all the items (key, gem, and coin) and then escape through the door, while Pol’s mission is to catch Rob before he escapes.
Game Implementation
The game is implemented in Java with a graphical interface built using JFrames. The board itself is represented as a 2D array, which tracks the positions of all objects during gameplay. Movable pieces, such as the Robber and Police, inherit from the SPieces base class, while the Spaces enum specifies what occupies each grid square. A TreeMap from Spaces to boolean is used to record which items the Robber has collected, such as the key, gem, or coin. To save progress, File I/O stores the last game state so it can be reopened later. Finally, the project includes JUnit tests to ensure the game’s mechanics and features work as intended.
Saving the Game
First life represents if the game has ended (f for false, t for true).
Second line represents if it is Rob's turn.
Third line represents the bag, in a pair of letters the first one is the item that will be in the bag, the second is t or f to represent if it is collected or not, 0 represents the end of the bag.
In the 12 by 10 grid e, r, p, d, c, k, g represent empty space, robber, police, door, coin, key, and gem respectively.
This is what the save file shows after the game is saved. Notice that the position of Rob, Pol, gem, and door are the same as shown in came.
Class Structure
Board.java - Keeps track of how the board looks and who's turn it is. Make sure the file is in the correct format when wanting to create a board.
Field.java - The game’s stage. This class draws everything on the screen and also listens to player inputs.
HowToPlay.java - Displays the rules in a separate window so players can quickly learn how to play. Includes a “Back” button to return to the main menu.
Level0.java - Launches the actual game window for a selected level. It sets up the frame, status bar, and adds a Pause and Save button.
LevelList.java - A menu for choosing which level to play (Level 1, 2, or 3).
MainMenu.java - The first screen you see. From here, players can start a new game, continue a saved game, or view the How to Play section.
Ground.java - A simple class that paints the game’s background image.
Spaces.java - An enum that lists the possible contents of each square on the board: ROB, POL, EMPTY, GEM, KEY, COIN, DOOR. This makes the board easier to manage.
SPieces.java - A base class for all characters and items that appear on the screen. It stores their position, image, and knows how to draw them. Both Robber and Police inherit from this.
Police.java - Defines Pol (the police officer). It extends from SPieces and adds the necessary functions for Pol.
Robber.java - Defines Rob (the robber). It extends from SPieces and adds the necessary functions for Rob.
Gameplay Video