CS 261 Homework 2 - Ants vs. Some Bees

Due Wed Sep 24 at 11:59pm

The bees are coming! Defend the colony with inherit-ants!

Overview

In this assignment, you will create a tower defense called Ants vs. Some Bees (inspired by the PopCap game Plants vs. Zombies). In this game, you control the Ant Queen, populating your colony with the bravest ants you can muster. Your ants must protect their queen from the evil bees that invade your territory. Irritate the bees enough by throwing leaves at them, and they will be vanquished. Fail to pester the airborne intruders adequately, and your queen will succumb to the bees' wrath.

To implement this game, you will be taking advantage of Object-Oriented Programmning, using inheritance and polymorphism to easily create the program and avoid code duplication. Furthermore, this assignment will give you a chance to practice reading, understanding, and working with a large existing project.

This assignment should be completed individually. You are welcome to ask for help from me, or from your classmates (following the Gilligan's Island rule)!

Objectives

Necessary Files

You will need to download the cs261-hwk2.zip file.

This zip file contains a large number of Java files, which together implement the basic game engine. You will need to import these files into Eclipse.

The Game

You can run the program by running the main method in the AntsVsSomeBees.java class. You should see something like this: (the blue comments are notes about how to play).

This is a fully working copy of the game! You are able to place ants and try and defend your queen against the bees. (In the starter code, ants don't cost any food).

The game is made up of a couple of components:

A game of Ants Vs. Some Bees consists of a series of turns. In each turn, new bees may enter the ant colony (you can deploy new ants at any time). Then all insects (ants, then bees) take individual actions: bees sting ants, and ants throw leaves at bees. The game ends either when a bee reaches the ant queen (you lose), or the entire bee flotilla has been vanquished (you win).

The Code

There are a lot of classes used to implement this game: as with any good object-oriented program, each concept in the game ends up having a class to represent it.

You will need to make a few modifications to some of these provided classes, as detailed below. You should read through the code to get a sense for how it works. I recommend you start at the main method and trace from there.

Note that the provided classes involves a number of advanced concepts: it uses Maps (which we will cover near the end of the assignment), linked-lists (which we will cover after this assignment), and reflection (which we will stay far away from). You are of course welcome to look over and study the code--get a sense for how this prorgram is put together!

Assignment Details

As always, I recommend you read through all of these instructions carefully before you begin! As with the previous assignment, there are numerous (generally small) tasks you will need to complete.

Sections marked with a star (*) are larger and more complex, and you should budget time accordingly.

1. Food and Harvesters

Currently there is no cost for deploying any type of Ant, so there is no challenge to the game. You should add food costs.

Class Food Armor

HarvesterAnt
2 1

ThrowerAnt
4 1

Now you're using up food, but there is no way to produce more! To fix this, finish implementing the HarvesterAnt. As its action (defined in the action() method), the Harvester should produce 1 food for the colony.

Try playing the game again. Once you have placed a HarvesterAnt, you should accumulate food each turn. Vanquishing the bees is once again possible in the default setup!

2. Wall Ants

Next you're going to create your first brand new ant. You will add some protection to your glorious colony by implementing the WallAnt, which is an ant that does nothing each turn but has a very large armor value.

Class Food Armor

WallAnt
4 4

3. Hungry Ants

Implement a new offensive unit called the HungryAnt, which will eat a random Bee from its place, instantly killing the Bee! However, after eating a Bee, it must spend 3 turns digesting before eating again.

Class Food Armor

HungryAnt
4 1

4. Fire Ants

Implement the FireAnt. A FireAnt also doesn't take any actions on its turn. However, it does have one special ability: when a FireAnt's armor reaches zero (or lower), it will reduce the armor of all the Bees in the same Place as the ant by the ant's damage attribute (which defaults to 3).

Class Food Armor

FireAnt
4 1

Once you've implemented the FireAnt, be sure and test your program by playing a game or two! A FireAnt should destroy any co-located Bees when it dies. You can start a game with ten food by specifying the appropriate value in the AntsVsSomeBees driver.

5. Water*

Now that you've added fire, add some Water! To make things more interesting you will add a new type of Place, representing a water-filled tunnel in the colony. Note that this will be one of the more complex portions of the assignment, as you will need to modify some of the core game code.

Once you've added water, you will need to make the insects react to it. Only an insect that is watersafe can be deployed to a Water place.

6. Scuba Ants

Make a new ant that can be deployed to Water spots! Add a ScubaThrowerAnt ant, which is a type of ThrowerAnt that is watersafe, but otherwise is identical to its parent class.

Class Food Armor

ScubaThrowerAnt
5 1

7. Ninja Ants

Add the NinjaAnt, which damages all Bees that pass by it, but is never seen (thus allowing Bees to pass by it).

Class Food Armor

NinjaAnt
6 1

For a challenge, try to win a default game using only HarversterAnt and NinjaAnt!

8. Bodyguard Ants*

Right now, your ants are quite frail. We'd like to provide a way to help them last longer against the onslaught of the bees. Enter the BodyguardAnt.

Class Food Armor

BodyguardAnt
4 2

A BodyguardAnt differs from a normal Ant because it can occupy the same Place as another ant. When a BodyguardAnt is added to the same Place as another ant, it shields the other ant and protects it from damage. Attacks should damage the BodyguardAnt first and only hurt the protected ant after the BodyguardAnt has perished.

There are a number of steps to implement this Ant:

Be sure and text this ant rigorously---there are lots of moving parts here so lots of ways it can break!

9. The Queen Ant*

Last but definitely not least, you will implement the ability for the Ant Queen herself to take to the trenches!

Class Food Armor

QueenAnt
6 1

The QueenAnt is a waterproof throwing ant (like the ScubaAnt, which you should use as a superclass) that inspires nearby ants through her bravery. Whenever the QueenAnt throws a leaf, she also doubles the damage of the ants on either side of her (in the Places that are her location's entrance and exit).

However, with great power comes great responsibility. The Queen is governed by three special rules:

  1. If a bee ever enters the place occupied by the queen, then the bees immediately win the game. The game ends even if the queen is protected by a bodyguard. The bees also win if any bee reaches the end of a tunnel where the queen normally would reside.
    • The AntColony's queenHasBees() method returns whether or not the bees have reached the queen, which it determines by checking if this.queenPlace.getBees().length > 0 (this is the colony). Normally the queenPlace variable is just a normal Place. Implement a subclass of Place called QueenPlace that (effectively) represents two places: where the Queen currently is, and the normal "queenPlace" at the end of the tunnels.
      • Hint: this should basically be a Place with another, second Place as an instance variable that stores the Queen's current location.
      • You will need to override the getBees() method so that it returns all the bees that are in either location.
    • As part of the QueenAnt's action(), replace the the queenPlace object in the colony with a new QueenPlace object that has a reference to the QueenAnt's current place (as it's extra instance variable).
      • You will need to make an accessor (setter) for the queenPlace variable so you can change it!
      • You can assume that the QueenPlace object will only be used for checking if bees have hit the queen, so you will not need to modify (or even use) any other methods!
  2. There can be only one true queen. Any queen beyond the first one is an impostor and should die immediately (its armor reduced to 0) upon taking its first action, without doubling any ant's damage or throwing anything. (Impostor queens should not affect the colony's queenPlace attribute).
    • This means that the QueenAnt uses a variation of the singleton design pattern (which you will talk about more in Software Engineering).
    • In order to implement this, you can keep track of the number of times that an instance of a QueenAnt has been constructed, using a class (static) variable. Every time you create a queen, increase this variable by 1. You should not need to search through the colonyPlaces to find other queens.
  3. The true (first) queen cannot be removed--meaning it can't be moved! Attempts to remove the queen should have no effect.
    • You can do this by modifying the Place class; add an overloaded removeInsect(QueenAnt) method that has no effect. Note that this method will be called whenever you try and and remove the QueenAnt, because the most specific method signature is applied!
      • Style idea: You could even make an interface (like Unremovable) that the QueenAnt or others could implement, and then use type checking to determine if you should try and remove them or not!
    • This does mean that your Queen can't be damaged... but that's okay, because the game will end if a Bee gets there anyway!

You are now done with the project!
If you weren't able to vanquish the bees' insane-mode assault plan before, do your new ants help? Add some water or design your own layout to keep things interesting.

Be sure to also fill out the README.txt file.

Submitting

BEFORE YOU SUBMIT: make sure your code is fully documented and functional! If your code doesn't run, I can't give you credit! Your name should be in the class comment at the top of each class that you modified.

Submit your program to the Hwk2 submission folder on vhedwig, following the instructions detailed in Lab A. Make sure you upload your work to the correct folder!. You should upload your entire src folder with all your classes (both packages!), as well as your antlist.properties file if you made any changes. Be sure to complete the provided README.txt as well with details about your program.

The homework is due at midnight on Wed Sep 24.

Extensions

There are lots of ways you might extend this assignment!

I have supplied images (and GUI handling) for a number of additional types of ants. You may also design your own kind of ant if you wish!

Class Food Armor Description

SlowThrowerAnt
4 1 Applies a "slow" effect for 3 turns. A slowed
bee only takes an action every other turn.

StunThrowerAnt
6 1 Applies a "stun" effect for 1 turn. A stunned
bee takes no action

ShortThrowerAnt
3 1 A ThrowerAnt that only throws leaves at
Bees at most 2 Places away

LongThrowerAnt
3 1 A ThrowerAnt that only throws leaves at
Bees at least 4 Places away

You could also try extending the Bees class to make a wider variety of bees (though I have no images to support this, and it would likely involve extensive modification of the provided game code).

Extensions can be worth up to 3 points of extra credit; but make sure the rest of the functionality exists and works first!

Grading

This assignment will be graded out of 35 points: