ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 11 May 2017 My Price 10.00

Ants Vs. SomeBees

 Goal

In this project, you will create a tower defense (Links to an external site.) game called Ants Vs. SomeBees. As the ant queen, you populate your colony with the bravest ants you can muster. Your ants must protect the colony 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. This game is inspired by PopCap Games' Plants Vs. Zombies (Links to an external site.) ®.

(If you've never played Plants vs. Zombies, you can play it for free right in your web browser (Links to an external site.).)

This project requires you to implement a larger number of classes. It is very important to think about how these classes might relate to each other, and how you can use inheritance to make the code easier to write and easier to understand, while eliminating duplicate code. Consider how you will use inheritance very carefully--designing the classes yourself is an important aspect of this assignment.

Starting Materials

Download the scenario for this assignment, which contains the classes and images you need to start: program4.zip. Do not forget to unpack the zip file before you use it!

The starting scenario provides two classes for you to use in your solution:

Colony is a skeleton you will complete yourself. It forms the "world" for this game. The source code provided only contains a constructor, and a stub for a method called onTouchDown(). Read the comments in the source file for details on these methods. See below for required features you have to add to this class yourself.

HomeBase is a predefined class that serves as the base class for your Colony. This class sets up the game world geometry: the screen is a 10x6 grid, where each grid cell is 80 pixels square. It also provides a number of methods that you can use in implementing your Colony's features:

setActorChoices(class1, class2, ...) Your Colony class should call this method in its constructor to indicate which actor classes (ant types) you have created. It will cause the world to show a simple row of ant selectors (clickable images) across the top edge of the game screen that you can click on to indicate which kind of ant you wish to place while playing the game.
newActorOfSelectedType() Call this method in your code to create a new ant of the selected type, in order to place it somewhere on the screen. This method will return null if no ant type has been selected by the player yet. Note that this method will return a reference of type Actor. In order to use the reference to invoke Ant methods you will need to typecast it: 
Ant selectedAnt = ((Ant) newActorOfSelectedType())  
win() Your code should call this method when the ants win to pop up a winning message and stop the game.
lose() Your code should call this method when the bees win to pop up a losing message and stop the game.
act() This method is automatically called on each turn of the simulation. The HomeBase class uses it to update the food display on-screen,and determine whether the game is over. If you override this method in your Colony class, be sure to call super.act(); so that the food display gets updated properly.

Classes You Create

You are responsible for creating five different types of ants, plus the bees that harrass them. In addition, you'll also create a small number of additional classes that represent objects (not insects) in the game. These are discussed separately below.

Types of Ants

Ants are "created" when the player clicks on one of the available ant types across the top of the screen, and then clicks on an open spot in the playable area of the game to indicate where the new ant should be placed. Creating ants requires food from the colony, and should be handled in your colony object (discussed below).

You are required to provide five specific kinds of ants that differ in how they behave. All ants have an integer "health" value that indicates how strong they are. Health is decreased when an ant is stung by a bee, and an ant leaves the field (is removed from the world) when its health reaches zero.

Every ant should provide a method called getHealth() that returns the ant's current health, as well as a method called injure(n) that reduces the ant's health by the provided amount. When an ant's health reaches zero, it should remove itself from the colony. Further, every ant class should provide a default constructor. Finally, every ant should provide a getFoodCost() method that indicates how many food units are necessary to add this ant to the colony.

Harvester Ant

 

A HarvesterAnt simply collects food, adding it to the colony's food supply. Every 40 turns, a harvester produces one unit of food to add to the colony. Adding a harvester ant costs 2 food units. A harvester ant begins with a health of 1.

Thrower Ant

 

A ThrowerAnt is an offensive unit that throws a continuous stream of leaves straight ahead. Leaves annoy flying bees, causing them to fly away. Every 120 turns, a thrower throws one leaf. Adding a thrower ant costs 4 food units. A thrower ant begins with a health of 1.

Fire Ant

 

A FireAnt is an offensive unit that explodes when its health reaches zero. When it explodes, it reduces the health of any bee in any neighboring cell by 3 health units. Adding a fire ant costs 4 food units. A fire ant begins with a health of 1.

Wall Ant

 

A WallAnt is a defensive unit that blocks bees. Adding a wall ant costs 4 food units. A wall ant begins with a health of 4.

Hungry Ant

 

A HungryAnt is an offensive unit with a huge appetite that can eat a bee. Any bee that reaches the hungry ant will be eaten--but the catch is that it will take the hungry ant 240 turns to "digest" the bee it just ate. While digesting, the hungry ant is vulnerable to any other bee that comes across it. Adding a hungry ant costs 5 food units. A hungry ant begins with a health of 1.

Bees

 

A Bee flies in a straight line due west, heading for the ant queen's chamber (on the left edge of the screen). Your Bee class, (named Bee), should turn to face due west as part of its default constructor.

Like ants, your bee class must provide a method called getHealth() that returns the bee's current health, as well as an injure(n) method that reduces the bee's health by the specified amount. When the bee's health reaches zero, it should remove itself from the colony. Bees start with a health value of 3.

Since our grid has large cells (80 pixels wide), bee movement would be very jumpy if bee's moved forward by one grid cell each turn--not to mention, they'd be super fast! Instead, the move() method provided by the Actor class can take floating point numbers, allowing actors to move by fractional portions of a grid cell. Bees move to the left by 0.0125 units (1/80th of a grid cell) on each turn, as long as they are not blocked by an ant.

As soon as a bee touches an ant, it becomes blocked. The bee will be stuck on top of the ant until it can vanquish the ant. Once the bee reaches an ant, it will wait for 40 turns and then sting (injure) the ant, reducing its health by one. The bee will continue stinging the ant every 40 turns until one of the two is vanquished by the other.

As soon as any bee touches the queen's chamber on the left side of the screen (see below), the bees win the game, (i.e., the ants lose).

Other Actor Classes Representing Objects

Leaf: A leaf is thrown by a thrower ant at incoming bees. A leaf simply travels due east at a rate of 0.025 grid units per turn (twice as fast as a bee flies). As soon as a leaf hits a bee, it should injure the bee, reducing its health by 1. The leaf should also be removed from the world. Further, if the leaf reaches the right edge of the screen (x coordinate of 9) without hitting a bee, it should also be removed from the world.

QueensChamber: Create a class that represents the bee's goal: the queen's chamber. An image is already provided for you to use. The queen's chamber should be placed at (0, 3). If any bee reaches the queen's chamber, the bees win.

Hive: Create a class that represents the bee hive. An image is already provided for you to use. The hive should be placed at (9, 3) on the right edge of the screen. The hive should provide a method called getBees() that returns the number of bees in the hive, as well as a corresponding setter method that allows the number of bees in the hive to be set. Initially, the hive's constructor should start it with 30 bees to be released. The hive should do nothing for the first 400 turns. After that, the hive should release one bee at a time, randomly placing the bee in one of the five spots from (9, 1) - (9, 5). The hive should then wait a random delay between 80-400 turns before launching the next bee.

Colony: The colony represents the whole world. The queen's chamber and the hive should be created and placed appropriately in the colony's constructor. The colony starts off with 10 food units, and only gains food when it is provided by harvester ants. Your colony must provide a getFood() method that returns the number of food units currently in the colony, as well as a addFood(n) method that can be used by harvesters to add food to the colony, and a consumeFood(n) method that is used to reduce the amount of food in the colony when creating new ants. The ants win the game when the hive has no more bees, and there are no more bees anywhere in the colony.  The colony creates a series of controls along row 0 at the top of the screen, based on the classes you pass into setActorChoices().Each of these control spots is itself just an actor, (one you don't have to write inherited from HomeBase), that remembers a specific ant class, and then calls setSelectedActor() on the colony whenever it is touched.

Testing

To test onTouchDown() use the setSelectedActor() method on your Colony. You could use it in a test like this:

public void testCreatingHarvester()
{
   // Simulate "clicking" the harvester ant control at the top of screen
   colony.setSelectedActor(HarvesterAnt.class);

   // Now test onTouchDown() on the colony somewhere
   colony.onTouchDown(2, 2);

   // The remainder of your test goes here
   ...
}

To simulate the passing of time in your tests note that the test class has a method called run(world, N) that takes a world (i.e., your colony) and will simulate N turns. However, it appears that this method may not work reliably in Greenfoot4Sofia, but it does work reliably on Web-CAT.

Submitting Your Solution

All program assignments are submitted to Web-CAT. Use the Controls->Submit... menu command to submit your work.

Answers

(11)
Status NEW Posted 11 May 2017 07:05 AM My Price 10.00

-----------

Not Rated(0)