Version: 1.0
Due: 2016-11-10T23: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 working with Comparable and Comparator. This project will:
So far we have explored many aspects of OOP through Java Inheritance and Polymorphism. We have also fully explored such concepts as exceptions and data abstraction. Now we will spend time finishing up our understanding of collections through iterators and collections algorithms. Note that this assignment has two distinct parts.
Last week you implemented a Set. There is one thing that was missing from that implementation of a set, though. Most Collections are Iterable
which allows objects to be the target of a “for-each” loop. You will implement the Iterable
interface in your MySet
implementation. Note that a working MySet
implementation has been provided to you with the previous homework’s requirements.
For the iterator() method, you will be defining a private class which implements the Iterator interface. Private classes are classes defined within another class, and have access to private instance variables in their surrounding class. Because your custom Iterator will need to know the state of your backing array, we must make the Iterator a private class instead of a separate class. You will need to fill out the three methods the Iterator interface requires: hasNext(), next(), and remove(). Finally, your iterator() method should return a new instance of your private Iterator class.
Feel free to refer to the java API as well as notes from class to learn more about what is needed to implement Iterable
.
The provided code won’t work as it relies on your MySet
to be Iterable
in order to work. If you want to work on Part B when you have not completed Part A, just comment out the code that uses the MySet
iterator.
We have spent this semester so far building an implementation of the game Civilization from the ground up. We have implemented many interesting features through the use of java and OOP concepts. However, we have no real way to keep track of our progress or compare ourselves to other players in an attempt to see how we compare. But now that we know how to compare objects effectively we can implement this functionality!
See Standings
. When this option is selected, the user has the ability to see how they compare to other civilizations in the game. Your job is to implement the functionality of listing out the different types of standings.You will specifically need to edit the standings
method in Model.java
in the model
package. Some of it is stubbed out for you. You just need to add the code that provides the appropriate functionality described above.
You must make use of the methods, interfaces, etc. discussed in class in order to receive credit for this assignment.
Below is some example output of what your code should produce once you have completed the assignment. Your code should order the Civilizations correctly as shown in the examples as well as provide the appropriate amounts of resources, techpoints, etc. that they were ranked by. Note that your code will not produce these exact numbers as they are produced randomly when the game starts.
The following is not necessary for you to do but might be interesting.
You might notice if you look in Model.java
that the other Civilizations created are just initialized to beginning values and not ever changed. It might be interesting to actually change the code to dynamically change how these Civilizations procede as your user plays the game. This implementation would be a very basic AI, so if you are interested in AI you can try to implement competing players with the provided code.
This is not extra credit. This just might be interesting for you to explore since the code is set up well to implement a very basic AI.
$ 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
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!