Ants Versus Zombies
|Assigned||Monday, April 8, 2013|
|Program Due||Monday, April 22, 2013, 11:59pm|
To gain experience in the following areas:
- Exception Handling
To continue to gain experience in the following areas:
- Interfacing with existing APIs
In Ants Versus Zombies, you control an ant colony that is being attacked by a horde of zombies. The game consists of 5 rounds of 2 phases each.
The player begins the game with 100 "food" and no ants in his colony. The first phase is the "Recruit" phase. The player spends his food to recruit ants into his colony. Note that order is important - the first ant recruited will be the first defender, the second ant recruited becomes the second defender, and so forth. The player clicks on the "Done" button when done recruiting; any unspent food is kept for the next round.
The next phase is the "Invasion" phase. First the program generates the invading zombie horde (see below). Next, combat occurs as long as zombies remain. The first ant in the colony attacks the first zombie in the horde and vice versa. Damage is dealt simultaneously. They continue attacking each other while their remaining life values are greater than zero. If the zombie's life reaches 0 (or less), it dies and the player is rewarded with a bit of food; that zombie is replaced with the next zombie in the horde (if any). The ant dies if its life reaches 0 (or less), and it is replaced with the next ant (if any). Note that it is possible for both the ant and zombie to die, in which case both are replaced with the next ant and zombie.
If at any time during an invasion the player has no ants left alive in his colony and there is at least one remaining zombie, he loses.
The colony is victorious if all invading zombies are defeated. All ants left heal all injuries (i.e., their life is reset to full).
The game returns to the Recruit phase, and the process repeats for 4 more rounds. The player wins if the colony survived the fifth horde. His final score is equal to the amount of food remaining.
Here are some screen shots of actual game play:
Here is a downloadable executable file so that you can practice playing the actual game and become comfortable with its rules.
Try the sample game explained in Appendix 3 (a single invasion) to help.
Project Specification Details
This is a closed project, as defined on the Projects page. You may not get assistance from friends, family, nor other students. As always, you may get assistance from the CMSC 202 TAs, tutors in the CS Help Center, and your instructor.
The following source code files are given to you. DO NOT modify them. Use them as is.
The following data files are given to you. DO NOT modify them. Use them as is.
A zip file containing these files is located here: proj4files.zip
You must complete the implementation of a class named
This class implements the interface
GameInterface. (Note that there
may be other classes than those specified in the
you need to code in order to get your
Game class to work properly.)
DO NOT modify the
nextFight method that is already
coded. Leave it as is.
The main driver for this project,
Project4.java, will instantiate your
game and run it.
You are responsible for writing the code that specifies the different varieties of ants that are used in the game; see Appendix 1.
Generating the Zombie Horde
The zombie hordes for each round are stored on disk as separate data files. The program must read and parse a horde file at the beginning of each Invasion. Horde files are named horde_1.data, horde_2.data, and so forth.
Contained within the file is a single line, termed "Zombie String". Each character in the string represents an invading zombie; see Appendix 2. If instead the character is a digit (1 through 9, inclusive), then make additional copies of the previously specified zombie.
For example, the horde file horde_1.data contains the
SZI1. This represents the horde:
- zombie scientist,
- standard zombie,
- infected zombie, and another
- infected zombie. (Note the
1at the end of the string.)
Use the following Java code to open and read the Zombie String within a file:
java.io.FileReader file = new java.io.FileReader(filename);
java.io.BufferedReader buf = new java.io.BufferedReader(file);
String zombieString = buf.readLine();
You may assume that a horde file always has a valid Zombie String.
Requirements and Hints
- (Requirement) Each file for this project must be part
of a package named
- (Hint) Play the game multiple times until you are confident that you understand the rules.
- (Hint) Draw a program class diagram, either formally or informally, to understand the relationship between all program classes and interfaces.
- (Hint) Develop and test your game with just one type of ant before adding the rest.
- (Hint) Both FileReader and BufferedReader throw exceptions. You must handle those exceptions.
- (Hint) For convenience, place the horde data files in
- (Hint) You may use ArrayLists, Vectors, and/or other built-in Java collection class types.
- submit all .java files you create. Submit only your .java files (not .class files or any other files).
- Do not submit the files Project4.java, GameInterface.java, RecruitDialog.java, InvasionDialog.java, or any other complete .java files that were given to you. Also do not submit any horde data files.
- Use submitls to verify that your files are in your submittal directory.
More complete documentation for submit and related commands can be found here.
Remember -- if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause compiler errors and a reduction in your grade.
Avoid unpleasant surprises!
Appendix 1: Types of Ants
In this game, all ants have a cost to recruit into the colony and an initial amount of life. In addition, each ant has a unique way to defend the colony.
Army Ant Food Cost: 35 Life: 30 Deals 10 damage to enemy zombie, plus 5 additional points of damage for every army ant that has been recruited during the entire game (including itself). Bullet Ant Food Cost: 10 Life: 1 Deals 25 damage to enemy zombie. Carpenter Ant Food Cost: 10 Life: 10 Deals 10 damage to enemy zombie. Citronella Ant Food Cost: 25 Life: 20 Deals 10 damage to enemy zombie. When it dies, all remaining zombies and ants take 2 damage. If this kills other citronella ants, they also explode and do damage to everything. Fire Ant Food Cost: 15 Life: 20 Deals 10 damage to enemy zombie, 20 if that zombie is flammable. Leafcutter Ant Food Cost: 20 Life: 10 Deals 10 damage to enemy zombie. If that zombie's life is now 0 (or less), it does not get its attack on leafcutter ant. (Normally, ants and zombies attack simultaneously.) Pharaoh Ant Food Cost: 15 Life: 10 Deals 10 damage to enemy zombie, 30 if that zombie is gigantic. Sugar Ant Food Cost: 20 Life: 20 Deals 10 damage to enemy zombie. Any time a sugar ant defeats a zombie (even if itself dies during the attack), gain an extra 5 food. Thief Ant Food Cost: 15 Life: 25 The thief ant does not attack zombies as normal. It does no damage to the zombie on its own. Instead, it reflects half of the damage it takes from a zombie back at the zombie, rounded down. For example, a giant zombie attacks the thief ant. The thief ant takes 35 damage, but the giant zombie also takes 17 damage. Weaver Ant Food Cost: 20 Life: 10 Deals 15 damage. Unlike other ants, the weaver ant attacks the zombie second in line in the horde (instead of the head of the horde). If there is only one zombie left in the horde, the weaver ant does nothing.
Appendix 2: Types of Zombies
In this game, all zombies have an initial life and a food reward when it is defeated. Each zombie has a unique way of attacking the colony. Also included in each zombie's description is a single-letter abbreviation, used when parsing the Zombie String in the horde file.
Armored Zombie Horde Abbreviation: A Life: 20 Food Reward: 15 Deals 10 damage to enemy ant. The first time an armored zombie takes damage during the invasion, it instead takes none. Afterwards, it takes damage as normal. Giant Zombie Horde Abbreviation: G Life: 40 Food Reward: 20 Deals 35 damage to enemy ant. It is considered gigantic. Infected Zombie Horde Abbreviation: I Life: 20 Food Reward: 15 Deals 25 damage to enemy ant. It is considered flammable. Radioactive Zombie Horde Abbreviation: R Life: 70 Food Reward: 25 Deals 5 damage to enemy ant. It also deals 5 damage to the zombie behind it in the horde (if any). It is considered gigantic and flammable. Standard Zombie Horde Abbreviation: Z Life: 10 Food Reward: 10 Deals 10 damage to enemy ant. Voodoo Zombie Horde Abbreviation: V Life: 15 Food Reward: 15 Deals 10 damage to enemy ant. If this is enough to kill the ant, add a new Standard Zombie to the end of the Horde. (If a voodoo zombie kills a citronella ant, and that citronella ant causes the death of another ant, only add one new Standard Zombie instead of two.) Zombie Ninja Horde Abbreviation: N Life: 10 Food Reward: 5 Deals 15 damage to enemy ant. In addition, the zombie ninja's attack reduces the colony's food store by 5 (if any). (If a leafcutter ant kills a zombie ninja, do not deduct any food because the zombie ninja did not get an attack. Also, the food deduction occurs for every round of combat, thus if the zombie ninja attacks for two rounds, the player loses 10 food.) Zombie Scientist Horde Abbreviation: S Life: 5 Food Reward: 5 Deals 5 damage to enemy ant.
Appendix 3: Sample Game
The player begins with 100 food. He recruits these ants, in the following order:
- carpenter ant
- fire ant
- army ant
- pharaoh ant
The player has 25 food remaining. As per horde_1.data, the invading horde is, in order:
- zombie scientist
- standard zombie
- infected zombie
- infected zombie
- In the first fight:
- The carpenter ant deals 10 damage to the zombie scientist, and zombie scientist deals 5 damage to carpenter ant. The zombie scientist dies, and the player gets 5 points of food. The carpenter ant's life is now 5.
- In the second fight:
- The carpenter ant deals 10 damage to the standard zombie, and standard zombie deals 10 damage to carpenter ant. The carpenter ant dies. The standard zombie also dies, and the player gets 10 points of food.
- In the third fight:
- The fire ant deals 20 damage to the first infected zombie. The infected zombie deals 25 damage to the fire ant. The fire ant dies. The infected zombie also dies, and the player gets 15 points of food.
- In the fourth fight:
- The army ant deals 15 damage to the second infected zombie. The infected zombie deals 25 damage to the army ant. The army ant survives, but only has 5 life remaining. The infected zombie also survives, but only has 5 life remaining. No food is given to the player.
- In the fifth fight:
- The army ant deals 15 damage to the second infected zombie. The infected zombie deals 25 damage to the army ant. The army ant dies. The infected zombie also dies, and the player gets 15 points of food. A pharoah ant with 10 life remains in the colony.
There are no zombies remaining in the horde, so the player survived the invasion. The player has had 45 food added to his food reserve, over the course of the invasion, bringing his total to 70, from which he may spend to recruit additional ants. For the next invasion, the pharaoh ant will be the first defender of the colony.