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:
You are to complete the following functionality for the scenario.
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.
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.
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.
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.
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).
This time you should make sure to put some viruses in the scenario to check to see that the actor turns away from them.
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.
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.
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.
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.
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.
to see the final functionality of this lab.
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.
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.
Lab authored by Adrienne Decker