Due: 2016-09-29T23:59:59
Civilization is a turn-based strategy game centered around founding and building a civilization. More commonly referred to as Sid Meier’s Civilization, the game has been around since 1991 and has since developed somewhat of a cult following. This semester we are going to be implementing our own version of this game for your homework assignments and by the end of the semester you will have a working game you can show off to your friends! If you are not familiar with Civilization, there is a free version that you can play in order to get familiar with the game.
This assignment will get you ramped up on Classes and Data Abstraction. This project will:
For the last assignment we had you implement a (what should have been) very straightforward and basic version of Civilization. Like many of you noted on Piazza that implementation was so basic it just barely followed the actual game design! Well keep in mind we are working on an iterative process of creating this big project, and the next step is to get some more features of the game set up. You will be creating classes to represent Civilizations, Resources, Victories, and Different types of Terrain.
Civilization.java
file from homework 1 with the CivilizationGame.java
one found in this folder. Unfortunately the first assignment wasn’t quite complicated enough and we need to make sure everyone is caught up.CivilizationGame.java
should compile and run no problem! If you receive errors about missing methods, you should add that functionality to your class.You will be writing 2 resource classes: Treasury.java
and Game.java
,
Two additional resource classes, CoalMine.java
and Fish.java
, have already been written for you. Take a look at their descriptions to get ideas of how to complete the other resources.
Treasury.java
:This is one of the most important classes in the game. Almost any action that your civilization takes will require using their Treasury.
int
to represent the amount of gold coins the Civilization has. Each civilization starts out with 200 coins.getCoins
- This method should return the number of coins contained in your Treasury Objectspend
- This method takes in an int
cost and checks to see if there are enough coins to pay the cost proposed. If there are enough coins, decrement the coins instance variable, and return true. If there are not, return false.earn
- This method takes in an int
amount of coins earned and updates the instance variable appropriately. This method should not return anything.Game.java
Wild game objects will provide food for your citizens!
int
healthIncrease.getHealth
.Fish.java
Fish will provide food for your citizens! This class is also already provided for you. You do not need to change anything about the provided file. We provide it’s description below.
CoalMine.java
CoalMine
has two pieces of instance data:
int coal
that represents the amount of coal present.int
BURN_COST. Burn cost should be the same for all instances of coal and the value should never change. It should be initialized to a value of 10.
burn
- This method will check to see if there is enough coal to burn by comparing the amount of coal the mine has to the BURN_COST. If there is enough, the amount of coal will be decremented by BURN_COST and the method will return true. Otherwise, return false.increaseCoal
- This method should take in an amount of coal that was mined. It should then add the passed in parameter to the current coal value.In Civilization there are many different ways to achieve “victory” or win the game. We will focus on just 2:
Technology.java
You will be writing a technology class that represents how advanced the civilization is. There will be some boolean values that will be used to determine if the player has won the game. Throughout the game, players will perform actions that allow them to improve their technology. Once their technology has reached a certain state, they will have won the game.
understanding
which should be initialized as zero and a boolean foundMeaningOfLife
which should be initialized to false.philosophize
that will increase understanding by 25 and one method improveWriting
that will increase understanding by 10.experienceLevel
and one boolean value builtWonderOfTheWorld
. builtWonderOfTheWorld
will be initialized as false, and experienceLevel
should be initialized as zero.increaseExperience
that will increase the experienceLevel
by the value passed in. If the experienceLevel
surpasses 200, builtWonderofTheWorld
should become true.hasTechnologyWin
. If foundMeaningOfLife
and builtWonderOfTheWorld
become true then victory has been achieved!Strategy.java
The strategy class has to do with war strategy.
strategyLevel
integer, a BATTLE_INCREASE
integer, a SIEGE_INCREASE
integer, and a boolean conqueredTheWorld
.
BATTLE_INCREASE
should be initialized to 10 and should hold the same value throughout all instantiations of Strategy.SIEGE_INCREASE
should be initialized to 40 and should hold the same value throughout all instantiations of Strategy.battle
and siege
. Each should increment the strategyLevel
by the corresponding constant. If strategyLevel
ever becomes greater than 180, conqueredTheWorld
should be set to true
.If conqueredTheWorld
gets set to true, then victory has been achieved!
Your Civilization will have 3 Terrains: Desert.java
, Hills.java
, River.java
. Terrains provide you with food and treasure.
River.java
River
object is created it must be given a name.Fish
. The River will never have more than 5 fish, and it will initialize with 5 fish with random integer healthIncrease values between 0 inclusive and 5 exclusive.getFish
method that will return a Fish
from your array if there are any Fish
available. Once one Fish
object is returned from the array, you should never be able to access it again. If no Fish
are available, getFish
should return null.replenishFish
method. This method will randomly generate 5 Fish to fill your backing array. However, this method will only replenish the fish in the river if there are no more fish left! Return whether or not fish were replenished.
CivilizationGame.java
so you do not need to call it yourself.Hills.java
Hills.java
has been provided for you. We provide its description below, but you do not need to make any changes to this class.
The Hills terrain allows your citizens to gain 3 resources: Game, Gold, and Coal.
Desert.java
The primary function of a Desert is to find treasure of course!
Some of Desert.java
has been implemented for you. You will not need to add anything to the lost
method.
findTreasure
that will randomly generate and return an integer value between 0 exclusive and 500 inclusive that represents the amount of coins that were found.lost
method inside of findTreasure
.Population.java
This class represents the population of a certain civilization as a whole.
increaseHappiness
that takes in the integer amount to increase the happiness by.decreaseHappiness
that takes in the integer amount to decrease the happiness by. Note that happiness should never go below 0.canWork
which takes in the number of workers needed and checks to see if there are enough civilians to satisfy the required number of workers. If there are enough civilians, then the amount of civilians gets decreases by the input amount.canBattle
is provided for you and determines if you have enough warriors for a randomly generated battle.hunt
takes in a Hills instance as a parameter and returns the result of the huntfish
takes in a River instance as a parameter and returns the result of the fishing tripcanCook
takes in as parameters Game
and the Civilization’s CoalMine
. If possible, burn coal 4 times, increase the number of warriors by 40, increase the number of civillians by 60 and return true. Otherwise return false.canCook
takes in as parameters Fish
and the Civilization’s CoalMine
. If possible, burn coal 4 times, increase the number of warriors by 10, increase the number of civillians by 15, and return true. Otherwise return false.Below describes the classes involved in settling new cities.
Building.java
This class is also already provided for you. You do not need to change anything about the provided file. We provide it’s description below.
A Building object is the most basic element of a civilization. A building should have an integer cost and an integer workersRequired. A Building should have a constructor that takes in cost and workersRequired parameters and assigns them to each corresponding piece of instance data.
Settlement.java
A Settlement object is composed of Building objects. Your Settlement object MUST have an array of Building objects, as well as a String name. Settlement
will have the following methods:
addBuilding
takes in a Building as a parameter and adds it to the backing array. There is no limit to the number of buildings that can be in a settlement. I should be able to add as many buildings to a settlement as I want.public boolean build(int allottedMoney, Population population, int cost, int workersRequired)
that builds a new Building object and stores it in your backing array. A new Building should only be built if the cost is smaller than the allottedMoney, and the Population has enough civillians to complete the job.expandSettlement
which doubles the size of your backing array while retaining all of the buildings that have been builtYou will be writing 3 civilization classes:
Egypt.java
, RomanEmpire.java
, and QinDynasty.java
Population
, a Treasury
, a CoalMine
, and a River
.Technology
and Strategy
settle
settle
take sin a prospective settlement, adds it to an array of settlements and returns whether or not the settlement was established.Settlement
s and should have a way of returning how many settlements have already been settled through a method called getNumSettlements
.Egypt.java
Egypt
has a Desert
buildPyramid
that takes in a Settlement and builds a pyramid building in that settlement.
practiceHieroglyphics
QinDynasty.java
QinDynasty
has HillsbuildWall
that takes in a Settlement and builds a wall in that settlement
buildHouse
that takes in a Settlement and builds a house in that settlement
establishLegalism
RomanEmpire.java
RomanEmpire
has Hills
buildAqueduct
that takes in a Settlement and builds an aqueduct in that settlement
buildBathHouse
that takes in a Settlement and builds a bath house in that settlement
buildVilla
that takes in a Settlement and builds a villa in that settlement
studyPhilosophy
Any time you get some code written and running you should push your changes up to the remote repository:
git status
to see what changes are staged or unstagedgit add *
to add all changes you have made to be staged for commitgit commit -m "My message"
to commit your changes to your local repository.git pull origin master
to make sure you are up-to-date with the remote version of the repository.git push origin master
to push your changes up to the remote repository.Arrays.java
or ArrayList.java
Peruse the CS1331 style guide here. This also has the instructions for how to run checkstyle on your code. Here’s a more step-by-step rundown:
checkstyle-6.2.2.jar
and select “save as” or “save link as” or whatever it is your browser suggests..java
classes you want to check.cd
into the directory containing your .java
files and the checkstyle jar file.java -jar checkstyle-6.2.2.jar MyJavaFile.java
replacing MyJavaFile.java
with the name of your java file.What gets printed out is the list of all style errors your code has. Do your best to fix all of them and start coding in the correct style. Each individual checkstyle error results in -1 points on your assignment.
Maximum number of points you can lose on Checkstyle this assignment: 20
In order to submit your assignment you need to ensure that your working code is pushed to your remote repository by the due date! Follow the instructions outlined above to push your code to your remote repository!
You should have the following in your repository:
CivilizationGame.java
CoalMine.java
Treasury.java
Game.java
Fish.java
Technology.java
Strategy.java
River.java
Hills.java
Desert.java
Population.java
Building.java
Settlement.java
Egypt.java
QinDynasty.java
RomanEmpire.java
Please be sure that any code you push compiles and runs through the command line! Pull from your repository and make sure everything is working how you want it!