Project 3: Monopoly
Due: Tuesday, July 21 by 8:00pm
- Updates
- Overview
- Monopoly Rules
- Details
- Classes
- Game Boards
- Sample Output
- Tips
- Working in Pairs
- What to Turn In
Updates
- 7/16: If you're seeing weird formatting in the names of properties that have apostrophes in them, you can downloaded an updated Madison.board file, which should resolve the issue. However, this formatting issue is not related to your implementation.
- 7/14: There was a small bug in MonopolyClasses.jar dealing with auto-play while using the GUI. A new version of the JAR file has been posted. If you already downloaded MonopolyClasses.jar, you'll need to replace it with the new version before you can use auto-play with the GUI.
- 7/14: Reminder: When you create new Java projects, remember to follow the instructions from the Eclipse Tutorial (see step 2). You need to make sure to select the radio button "Use project folder as root for sources and class files."
Overview
This project has several goals:
- Implement a program that uses multiple classes
- Use instantiable classes that we provide
- Learn about provided classes by reading their javadocs
- Implement basic instantiable classes for which we've defined an interface
- Practice overriding the public String toString() method of an instantiable class
In this project, you will build a version of Monopoly with a Madison theme. We have provided several already-implemented classes, and you will implement a few other classes to complete the game. This game has an graphical user interface (GUI), but can also be played in a text-only console mode. We have provided implementations for both of these modes. When you submit your files, please use the text-only console mode.
You may work on this project in pairs. See pairs for more information.
Monopoly Rules
This version of Monopoly is slightly simplified from the board game version. This game is for 2-4 players. Each player starts out the game at the "Go!" space and has $1500 dollars. Players alternate turns; each turn consists of deciding whether to buy any new houses, rolling two dice, moving the number of spaces on the board specified by the sum of the dice, and responding to any actions based based on the new location.
What Happens When You Land on a Space
There are several types of spaces that on which a player may land, and each type will be handled differently.
Property
These are the Madison-themed locations around
the board. Properties are arranged in groups of three (noted by the
different colors on the board).
If a player lands on a property that is not currently owned, and they have enough funds to purchase the property, they may do so.
If a player lands on a property that is currently owned by another player, the current player must pay rent. Rent is calculated as the base rent for the property plus the base rent times the number of houses on the property. E.g., if the rent is $10 and the property has two houses, rent is $10 + $10*2 = $30.
Chance!
There are six different Chance! options in the game. A die will
be rolled and the result will be used to select among the options.
Go to Jail
When a player lands on the "Go to
Jail" space, they must pay a fine of $50 and are transported across
the board to the Jail space. However, because they have paid the
fine, they are not in jail, but are now just visiting. On their
next turn, their move will start at the jail space.
Go!, Jail, and Free Parking
These spaces have no
specific actions associated with them. Note, however, that when a
player passes Go! (either by landing on it or by moving past the
space as they circle the board), they collect $200.
Buying Houses
At the start of each turn, the current player may also elect to purchase houses. Buying houses is advantageous because it increases the rent owed by other players when they land on the space. Players may only purchases houses for spaces for which they own the whole group. For instance, once a player owns Espresso Royale, Indie Coffee, and Barriques, they may purchase a house for one or more of these properties. A property has a maximum of three houses; a player does not need to purchase one house for each property before putting two houses on a property.
Ending the Game
Game play ends when a player's cash balance drops below $0. A player may not purchase a property or house to put themelves into debt; however, paying rent may drop a player's balance below $0. Landing on Go To Jail and paying the associated fine may also drop a player's balance below $0; landing on Chance! and losing money can do the same. The winner of the game is the player with the largest net worth (defined next) who also has a non-negative cash balance.
A player's net worth is defined as their cash balance, plus the cost of each property they own, plus the cost of each house they own.
Details
Start by creating a new Java Project in Eclipse. Download the code that we've provided in this jar file. Add the jar file to your project:
- See the tutorial from Project 0 for a refresher on how to do this, or
- In Eclipse, right click on your Java project, go to Build Path > Configure Build Path, click on the Libraries tab, click on the "Add JARS..." button, and select the MonopolyClasses.jar file from within your current project.
Next, download the Java files you will be updating for this project: monopoly_files.zip. Copy this file to your project directory and unzip it (NOTE: you may need to move the files out of a folder named "monopoly_files" into your project directory). It contains code skeletons for all the classes you will be implementing, Dice.java, a file for the board layout called Madison.board, and images needed for the graphical user interface. You'll see that there are lots of comments already provided (much like Project 2), but don't forget to add your own comments as you implement the methods!
In this project, you will be implementing all the unimplemented methods provided in these files; these are described in the Javadoc and in the next section, Classes. You may not change these method headers in any way. You may also implement your own methods in addition to the provided methods, but they must be declared private. You will also be adding instance variables to some classes. You may not create any new files.
You will need to edit each provided method's body (including main in Monopoly.java) so that it implements the functionality described in the Javadoc and the program. When we grade this project, we will test individual methods to verify that they work as specified. Your program output should match the sample output provided.
Classes
Classes You Must Implement
For each class, be sure to read the Javadoc carefully! Below, we have only provided a brief description of each class. Remember that you need to implement these methods as specified, without making any changes to the method header.
The Monopoly class is the main class. This is where the players are created and the game begins.
You will need to write main. Your main method should do the following (see the Javadoc for each of the mentioned classes for information on how to invoke their constructors and other methods):
- Build an array of Player objects for your game (you may have 2-4 players).
- Construct a new Game instance using your players and the filename for your game board. See Boards (below) for more information.
- Construct a new MonopolyUI object (either GUI or Console).
- Invoke the play method of the Game class using your MonopolyUI.
The Player class represents a player. You will implement lots of methods in this class; you will also likely want to add some instance variables.
The Space class represents a space on the board. You will implement lots of methods in this class; you will also likely want to add some instance variables.
The Property class represents a property on the board. The spaces on the board that are the property type have a Property associated with them. You will implement lots of methods in this class; you will also likely want to add some instance variables.
Classes That We Have Provided
The Game class represents a game setup that is being played. This class handles player turns and determines a final winner.
The Board class implements the game board used to play the game. A board may be initialized with default space names or by passing in the name of a file that contains a board description. You will be using the latter; don't worry about reading a file--we've implemented that part for you! You'll just need to pass in the name of the file.
The MonopolyUI class is an abstract class that represents a user interface for this program. You don't need to worry about what an abstract class means; we'll learn about these later. In this project, you'll be using either the GUI or Console class, defined next.
The GUI class is a graphical user interface for this program. The interface creates a new window with an image of the board, displays messages and prompts to the user, and gets input from the user.
The Console class is a text-based user interface for this program. This interface is very similar to what we've used in other projects and is entirely text-based. If you work in Eclipse, this interface runs in the console. The messages and prompts to the user are the same as the GUI interface, and this interface gets text input from the user and does input validation, etc. as necessary.
The Dice class is the same as for Project 2. As before, you should not modify the contents of this file (except during your own testing, when you may want to change the SEED value--sample outputs specify the SEED value used). We will use the original version of this file during grading.
Game Boards
As you read above, this Board class is designed to accept a file that specifies the board layout. We have provided a game board, Madison.board in monopoly_files.zip, for you to use. You may also create your own if you choose. We will grade your project using the provided board file.
You should store your board files in your project folder; the filename will then be a String containing the name of the file, e.g.,
String filename = "Madison.board";
If you want to create your own board the format is as follows:
- One Space is specified per line
- Your board should have 36 spaces (see BOARD_SIZE in Board.java)
- The Go!, Chance!, Jail, Free Parking, and Go To Jail spaces are indicated with the keywords: GO, CHANCE, JAIL, FREE_PARKING, GOTO_JAIL.
- Your board should have exactly one Go! space and exactly one Jail space.
- Your board may have at most 24 properties. Properties may be named any way you choose; however, be aware that long names may display poorly on the board.
Sample Output
For testing purposes, we have also provided an "auto-play" mode to the game. To run the game in auto-play mode, call the enableAutoPlay method on your Game object before calling play, e.g.,
Game myGame = new Game(...); ... myGame.enableAutoPlay(); myGame.play(...);
You can see sample output from running Monopoly (with the Console user interface) in sample1.txt and sample2.txt. Each sample output specifies the value of SEED in Dice.java. Change this value, run the game in auto-play, and compare your output with the sample.
Tips
- You should download the provided code and make sure you can add everything to your Java project soon! The sooner you get started, the sooner we can help you troublshoot any issues you encounter.
- You will need to finish implementing the Player, Space, and Property classes before you can write and test your main class.
- To test your implementation for each class, you may want to write a test class for each (e.g., TestPlayer) like we've done in class (e.g., we wrote Student and then used it in TestStudent). This will let you verify that you've implemented the methods for each class correctly before you try to run the whole program. The game will not work properly if you do not implement the methods as specified.
- In main, you can use a reference variable of either the GUI or the
Console class when you call the play method of the
Game class. E.g.,
GUI userInterface = new GUI(...);
orConsole userInterface = new Console(...);
depending on whether you would like to play the game with a graphical user interface or the console. - If you use the GUI class, a new window will appear in which you will play the game. Prompts will appear to ask for user input. To exit the game, close the prompt window or use the red "Terminate" button in the Console in Eclipse (as if you were stopping an infinite loop).
- To run your program and compare to the sample output provided, you will need to update the SEED variable in Dice.java. To do this, simply change the initialization value to the one specified in the sample output file.
Working in Pairs
For the project, you may work in pairs. Both partners must be currently enrolled in CS 302-001. If you choose to work with a partner, you must follow the rules below. These rules are the same as for Project 2.
Rules for Pair Programming
- You may only have one partner for this project
- You may have a different partner for future projects
- You may not pair program with multiple partners on the same project
- Once you start working with a partner on a project, you must complete the project with that partner.
- You must list your partner as a collaborator in the header comments of your source files
- Only one partner will submit .java files via the Dropbox for this project. However, both partners must submit a README file that lists the full names of both partners
- You must follow the principles of pair programming summarized below
Principles of Pair Programming
This summary of pair principle principles was summarized by Finn Kuusisto from a paper by Williams and Kessler:
- Pair programming involves two people working together at one computer, continuously collaborating on design, coding, and testing. One person types; the other either provides directions ("Now we need to write a new method that does ..., Now we need a loop to do ...") or constantly reviews what the typer is doing, and provides comments.
- Pair programming has proved successful both in classes and in industry. Programmers usually report having more confidence in their solutions and enjoying programming more when working in pairs.
- It is important to switch roles often (slide the keyboard back and forth). Because pair programming can be quite intense, it is also a good idea to take breaks (to check e-mail, go for a walk, have a snack).
- It is important to provide honest but friendly feedback. To be effective, there needs to be some healthy disagreement and debate, but pairs also need to be respectful of each other, and try to avoid becoming defensive when receiving criticism.
- Inevitably, programmers do some independent thinking/working. For best results, that work should be reviewed by both partners (and perhaps revised) when they start working together again.
- To be successful, pair programmers must realize that the benefits of working together outweigh their usual preference for working alone, they must confidently share their work, accepting instruction and suggestions for improvement in order to improve their own skills and the code they are writing, and they must accept ownership of their partner's work and thus be willing to constructively express criticism and suggest improvements.
What to Turn In
Before you submit your work, check the following:
- Did you implement all of the methods specified in the skeleton files and Javadoc, making sure to not alter the method names, parameters, or return values in any way?
- Does your program match the sample output?
- If you worked on your own computer, did you verify that your program works correctly on a lab computer?
- Did you make sure to invoke the play method of Game with a Console object in the final version to submit?
- Did you follow the style and commenting guidelines?
To submit:
- Upload the following
to the Project 3 Dropbox folder on Learn@UW:
- Monopoly.java
- Player.java
- Property.java
- Space.java
- Do not upload:
- Game.java
- Board.java
- Console.java
- Dice.java
- GUI.java
- MonopolyUI.java
- If you worked with a partner: only one partner should submit .java files. Both partners must submit a README file that contains the full names of both partners.