Homework 03

Version: 1.6

Due: 2016-10-20T23:59:59

Download zip

Introduction

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 Abstract Classes, Interfaces, Data Abstraction, Inheritance, and Polymorphism. This project will:

Problem Description

Now that you’ve had some practice working on a project with multiple classes, we’re ready to take our game up a notch! For this homework, you’ll be implementing several classes representing the controllable units and structures of the game as well as some of the logic behind their interactions. And best of all, you’re going to using inheritance and your knowledge of polymorphism to do it!

Before we begin…

Compiling and Running

$ javac -cp src/main/java src/main/java/runner/*.java
$ javac -cp src/main/java src/main/java/*/*.java
$ javac -cp src/main/java src/main/java/runner/*.java src/main/java/model/*.java src/main/java/view/*.java src/main/java/controller/*.java
$ java -cp src/main/java runner.CivilizationGame

Checkstyle

Solution Description

Civilization.java

First thing’s first! In your second homework, you may remember a good deal of overlap between all of the different Civilization classes (Egypt, RomanEmpire, and QinDynasty). To clean this up and eliminate alot of repeated code, you’re going to create a class called Civilization to serve as the super class for Egypt, RomanEmpire, and QinDynasty. We’ve provided some modified files for you (they are a bit different from what they were in HW02, as some requirements have changed) for these three subclasses. Your job here is to factor out common code between them and move it into Civilization.java to make it cleaner. Once you have done this, there is some additional functionality to add. For now, in each of the three civilization subclasses, override the explore method to provide unique functionality for each subclass. Egypt’s explore method should find treasure in its desert, and add the amount of gold found to its treasury. The RomanEmpire should mine coal in its hills and add the resources it finds to its own resources. QinDynasty should also explore its hills, but instead go hunting and add the health of the Game it hunted to its food supply (Don’t forget to make sure the Game in the hills does not run out! There is an instance method in Hills to help you with this). There are additional methods that these classes will override, but we will revisit those later on.

MiltaryUnit.java

Take a look at Unit.java. This class represents a player controllable unit in the game. It extends a class called MapObject. Note what methods you have to work with in these classes, how they work, and what they do (it will help to take a look at model/Model.java, view/UI.java, controller/GameController.java, and runner/CivilizationGame to fully understand how the game works). What you are going to do now, is create a new class called MilitaryUnit that inherits from Unit and represents a class that can attack another MapObject on the game board.

Symbolizable.java

MilitaryUnit subclasses

Now, we’re going to create some concrete subclasses for the MiltaryUnit we just made! The ones you will implement will be in MeleeUnit.java, RangedUnit.java, and SiegeUnit.java. HybridUnit.java has been provided for you, and you should not have to modify it.

MeleeUnit.java

Special MeleeUnit subclass: LegionUnit.java

RangedUnit.java

Special RangedUnit subclass: WarChariot.java

SiegeUnit.java

Special SiegeUnit subclass: BlackPowderUnit.java

Building.java and some subclasses

Now that we have all of our trusty defenders implemented, we can safely work on building up some of our civilization’s Buildings! Building.java is provided for you; take a look at that to see what all of our Buildings are going to be able to do, and what it is that they have. Notice that this is an abstract class. This is because you will be extending this class to make some specialized Buildings with additional functionality! The classes you will be implementing will be Farm.java and Landmark.java. FishingShack.java, CoalMine.java, and Settlement.java have been provided for you, but we urge you to take a look at them to stay up to date on changes that have been made to those classes. Both of the subclasses you need to implement will have a one-arg constructor that takes in a Civilization that represents the owner of the Building. Additional values you need to set will be detailed in the sections below for each class. Both classes will also have to provide implementations for the invest method, and provide toStrings. The format of the toString for each class will be the name of the Building, appended to the front of the superclass’s toString. So, Farm would have “Farm. “ appended to the front of the superclass’s toString.

Farm.java

Landmark.java

Special Landmark subclass: Pyramid.java

Special Landmark subclass: GreatWall.java

Special Landmark subclass: Coliseum.java

Worker unit classes

AnglerUnit.java

CoalMinerUnit.java

FarmerUnit.java

MasterBuilderUnit.java

SettlerUnit.java

Model.java

attackSelected

Conclusion

Verifying Your Submission

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!