# Yorkville High School Computer Science

ASSIGNMENTS: No Current Assignments

## AP Computer Science :: Projects :: Civilization V

Rubric
Lesson
Due: Feb 27

### Problem

In the videogame Civilization V, each settlement has a grid of tiles in which it can work to provide the civilization the resources it needs to survive. While the game has a number of different resources available we will focus on food, gold, and production for the scope of this project.

In the game, each settlement can assign citizens to work, at most, 36 tiles in a grid of hexagons that looks like the following.

Each of the grid locations contains a certain amount of gold, food, and production. The tiles can be improved to provide more resources. The tiles in that grid aren't always workable, however. A settlement may not have grown enough to incorporate all of the tiles or the tiles could be a part of another settlement's workable tiles. Below is what a settlement looks like when all 36 tiles are being worked.

The center tile (in row 4 column 4) is the settlement itself, and this tile is always worked. The icons for the different resources are as follows:

Food
Production
Gold

Assume the larger icons equal 5 units of the relevant resource. The pink icons represent culture and blue icons represent science, which we won't be using for this project. Below is another example showing a settlement that has only grown to a population of 12.

The green faces indicate tiles where a citizen is working. The black circles are tiles that are available to be worked. The arrows indicate tiles that are being worked by another settlement. Tiles outlined in pink cannot yet be worked since they aren't yet a part of the settlement, but are tiles the game suggests should be purchased. Since the above settlement has a population of 12, it can only work 12 tiles plus the settlement tile.

For this project you should create four classes to start. You should first create a Resource class that stores the amount of the resource and has an accessor that returns the amount of that resource. A constructor should initialize the amount of the resource. You should create subclasses of Resource for Gold, Food, and Production. The subclasses will not have their own methods, but will need a constructor to initialize the amount of the resource available.

Next, create a Tile class. The tile class should store the amount of Gold, Food, and Production available on the Tile. Each should be stored as a Resource variable. The Tile class should also store a boolean variable that is true if the Tile is workable, and false if it is not workable. A constructor should be used to initialize these variables. Finally, the Tile class should have an accessor for all three Resource variables as well as the boolean variable.

Finally, create a Settlement class that stores the population of the settlement, a 2D array of Tiles, and a 2D array of booleans that represent whether or not each tile is being worked. The way the grid is set up the rows and columns are not the same length. The top row has 4 tiles, but the middle row has 7. We could make a 2D array with a different number of rows and columns, but it is easier to just make a the same number of columns for each row and just set Tiles to null if they will never be available. The city Tile should be stored separately since it will always be worked. See the Delhi example to see how many Tiles are in each row. Finally, the Settlement class should have three methods that return the amount of Gold, Food, or Production the settlement is currently generating.

Once you are done, test your project using these unit tests. You may want to look at the unit tests first so you can name your classes and methods the same. The tests are based on the following settlements:

Philadelphia - Producing 27 food, 29 production, and 13 gold with a population of 12

Berlin - Producing 36 food, 32 production, and 25 gold with a population of 14

Delhi - Producing 69 food, 65 production, and 55 gold with a population of 45

Finally, create your own unit test. You can search Google Images for "civilization v citizen management" to find examples. Provide a link to the image in the comments of your unit test method. For tiles that are not workable because they are outside the city's radius you can make up the amount of food, production, and gold they provide.