CSE 113 - Fall 2010 - Banner
  • CSE 113 - Fall 2010
CSE 113 - Fall 2010 - Navigation
CSE 113 - Fall 2010 - Lab 4

Lab 4
Last modified: October 13 2010 09:23:01 AM

CSE 113 - Fall 2010 - Announcements

Virus Patrol

For this assignment, you will work with the concepts covered by Chapter 4 of the text, but you will not work with the Little Crab scenario any longer.

If you don't remember how to do any of the steps (like, copying, zipping, etc), please refer back to Lab 1.

First, you will need to copy over the scenario for this assignment. If you are working from home, you can download the scenario here. If you are in lab, the scenario is located in /eng/class/notes/cse113/Lab4.

Take note of the following classes in the scenario:

  • Body - The world in which this scenario takes place.
  • Virus - A virus (enemy) in the scenario.
  • VirusPatrol - Our hero in this scenario.

 

You are to complete the following functionality for the scenario.

Edges

Fill in the body of the checkForEdges method so that the VirusPatrol turns some number of degrees when it is at the edge of the world. You can use code similar to what the crab did in the previous labs. The number of degrees to turn when the actor hits the edge is up to you. You can specify a permanent value or you can write the code so that at each edge, the actor turns a random number of degrees.

Compile and Run

You have just completed a piece of functionality of your project. STOP coding. Compile all the files in the scenario and fix any compiler errors that are reported. After all the erors are fixed, place a VirusPatrol object in the world and click Run. Watch to ensure that the actor moves and turns some amount of the time. After you have compiled and tested this functionality and are satisfied that it is working the way you would like, feel free to move on to the next step.

Random Turns

Fill in the body of the randomTurn method so that the VirusPatrol will turn some number of degrees some percentage of the time. You can pick the percentage to be whatever you'd like, but make it somewhat small so that the VirusPatrol is not turning all the time. For degrees, you can specify the exact number or have the actor turn a random number of degrees.

Compile and Run Again

Every time you complete a piece of functionality, you need to compile and run your scenario. There is no other way to ensure that the functionality is what you intended it to be. Simply writing code in an actor does not guarantee that it performs the way you intended, so making sure to stop and compile and run often will help to ensure your code is working properly.

Run Away from Viruses

Fill in the checkForVirus method so that if the VirusPatrol can see a Virus, it turns away from it. You can specify how many degrees to turn (it can be random if you'd like).

Compile and Run Again

This time you should make sure to put some viruses in the scenario to check to see that the actor turns away from them.

Fill in the Constructor for Body

Having to put in Viruses and the VirusPatrol every time we run the scenario is a lot of work. Use the constructor of the Body class to do the work for us. Modify the constructor in the Body class to create 10 viruses and 1 virus patrol and put each of them in the world at random locations.

Compile and Run Again

You will see the viruses and virus patrol. Reset the scenario to make sure that the viruses are being positioned randomly. Run the scenario to ensure that the virus patrol still works as it did before.

Counting the viruses

Add an instance variable to the VirusPatrol class to count the number of viruses the virus patrol has run into. Create a constructor for the VirusPatrol class and initialize the instance variable to zero inside the constructor. Modify your code in checkForViruses so that when the virus patrol can see a virus, the count is increased by 1.

Compile and Run Again

This time, you will not see a change in the behavior of the virus patrol. But, if you position your virus patrol just right in the world, you can stop the scenario after it hits a few viruses and check to see if the value of your instance variable has changed. Right click on the virus patrol actor and select Inspect from the menu. You will get a dialog that appears and inside it you will see the value of the instance variable for the virus patrol. If you saw your actor collide with a virus, that value should be greater than zero.

Changing Images

You will once again modify thwe checkForViruses code so that after a virus has been hit and the counter updated and the patrol turned, the patrol checks the value of the instance variable. If the value is greater than or equal to 10, then the image of the virus patrol should change to skull.png.

Compile an Run One Last Time

to see the final functionality of this lab.


Submitting the Assignment

Once you have completed your work, you will submit the zipped up version of the Lab 4 scenario.

For directions on submitting, please see here.

Please recall that you must achieve a grade of at least 50% on each of the labs to be allowed to take the second practical exam. This means, that your labs are technically all due by the last day of class (December 10th). However, if you want to stay current with the course, I would recommend having this assignment completed within a week, but definitely before the first practical, which will be during the weeks of October 18th and October 25th.


Grading Information

Please make sure to look at your grading information on Web-CAT. See the grading information page for more details about how to interpret Web-CAT grade reports.

The following tests were run on your assignment submission. Each test was given equal weight, so 12.5 points each part.

  1. The VirusPatrol turns when it reaches the edges of the world.
  2. The VirusPatrol makes random turns while it is acting.
  3. The VirusPatrol turns when it sees a virus.
  4. When the Body is created, 10 viruses are placed randomly in the world.
  5. When the Body is created, 1 VirusPatrol is placed randomly in the world.
  6. There is an instance variable in the VirusPatrol class to keep track of the number of viruses that have been encountered.
  7. When the VirusPatrol encounters a Virus, the instance variable is properly updated.
  8. When the VirusPatrol encounters 10 Viruses, the image of the VirusPatrol changes to "skull.png".

Lab authored by Adrienne Decker

CSE 113 - Fall 2010 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184