![]() ![]() * Constructor: Set up the starting objects. * where blood cells, bacteria and viruses float around. * The bloodstream is the setting for our White Blood Cell scenario. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot Value of the four counters even though there is no change in any That is not an efficient solution, because it will re-display the Of showing the four counters in the act() method of a class, then There is a change in any of the counters. GREENFOOT SHOWTEXT UPDATEThat, you should update the display of the four counters only when ![]() Value of the four counters, and they should all be zero. When your program starts, you should display the GREENFOOT SHOWTEXT CODEWhen the timer times out, you also need to show theįinal score, and the code for this requirement is already inħ. Scenario WBC-4, thus no need for any code change.Ħ. Zero, and the code for this requirement is already implemented in The addScore method, the game stops when the score is less than in class Bloodstream, inside the implementation of O The sequence of the text follows the sequence shownĥ. Variables in the lower left corner of the screen using four lines show the name and the values of the above four Obtain an instance (handler) of the class Bloodstream.Ĥ. Order to call the public getter and setter, you need to first Public setter to set this increased value back to the variable. Value of the variable, increase this value by one, and then use the Hint: first, you can use the public getter to obtain the current ![]() GREENFOOT SHOWTEXT HOW TOHow to increase any of the above variables by one? Without touching the white blood cell, increase variable O when a virus reaches the left edge of the screen O when the white blood cell touches a virus, increase Without touching the white blood cell, increase O when a bacteria reaches the left edge of the screen O when the white blood cell touches a bacteria, here are the rules to increase these four instance provide a public getter and setter for each variableģ. in class Bloodstream, add the definition of fourĢ. Remove bacteria.īloodstream bloodstream = (Bloodstream)getWorld() īloodstream.Part 1 needs to be completed with Greenfoot.īased on the existing Greenfoot scenario WBC-4, you need to makeġ. * Check whether we are touching a bacterium or virus. * Check whether a keyboard key has been pressed and react if it has. * Act: move up and down when cursor keys are pressed. Thats a copy of the main class, and here is the subclass the counters are used in? import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) * a white blood cell and the lining at the edge of the blood stream. * Prepare the world for the start of the program. ShowText("Your final score: " + score + " points", 390, 170) ShowText("Time is up - you win!", 390, 150) * Show the end-of-game message on screen. * Show the remaining game time on screen. * with a winning message when time is up. * Count down the game time and display it. ShowText("Virus Missed: " + getNumberOfVirusMissed(), 80, 300) ShowText("Bacteria Eaten: " + getNumberOfBacteriaTouched(), 80, 325) This.numberOfVirusMissed= numberOfVirusMissed Public void setNumberOfVirusMissed(int numberOfVirusMissed) This.numberOfVirusTouched= numberOfVirusTouched Public void setNumberOfVirusTouched(int numberOfVirusTouched) This.numberOfBacteriaMissed= numberOfBacteriaMissed ![]() Public void setNumberOfBacteriaMissed(int numberOfBacteriaMissed) This.numberOfBacteriaTouched = numberOfBacteriaTouched Public void setNumberOfBacteriaTouched(int numberOfBacteriaTouched) * Create new floating objects at irregular intervals.ĪddObject(new Bacteria(), 779, Greenfoot.getRandomNumber(360)) ĪddObject(new Virus(), 779, Greenfoot.getRandomNumber(360)) ĪddObject(new RedCell(), 779, Greenfoot.getRandomNumber(360)) This.numberOfVirusMissed = numberOfVirusMissed This.numberOfBacteriaMissed = numberOfBacteriaMissed * Constructor: Set up the staring objects. I was able to get the scoring system to work, but when I run the game, it will only increment the values of setters by one and won't count passed that. In my assingment, I'm supposed to modify a greenfoot project to display the values of viruses and bacteria touched and missed in the game by creating private data types and using setters and getters to demonstrate understanding of data encapsulation, as well as modify the scoring system. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |