Hello all. I'm taking a class and one of the requests was to display the count of white cells, red cells, and bacteria, and viruses. For the life of me, I cannot get it to display the count. attached is the code of the Bloodstream and White Cell. Once I have this figured out, I know that I can get the other counts. Any help would be much appreciated!

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * The bloodstream is the setting for our White Blood Cell scenario. It's a place * where blood cells, bacteria and viruses float around. * * @author Michael Kölling * @version 1.0 */ public class Bloodstream extends World { private int countWC; private int countWC2; private int score; private int time; /** * Constructor: Set up the staring objects. */ public Bloodstream() { super ( 780 , 360 , 1 ); setPaintOrder(Border. class ); prepare(); score = 0 ; time = 2000 ; //countWC = 0; showScore(); showWCount(); showTime(); } /** * Create new floating objects at irregular intervals. */ public void act() { if (Greenfoot.getRandomNumber( 100 ) < 3 ) { addObject( new Bacteria(), 779 , Greenfoot.getRandomNumber( 360 )); } if (Greenfoot.getRandomNumber( 100 ) < 1 ) { addObject( new Lining(), 779 , 0 ); } if (Greenfoot.getRandomNumber( 100 ) < 1 ) { addObject( new Lining(), 779 , 359 ); } if (Greenfoot.getRandomNumber( 100 ) < 1 ) { addObject( new Virus(), 779 , Greenfoot.getRandomNumber( 360 )); } if (Greenfoot.getRandomNumber( 100 ) < 6 ) { addObject( new RedCell(), 779 , Greenfoot.getRandomNumber( 360 )); } countTime(); wCount(); } /** * Count number of White Cells in Bloodstream. */ public int wCount() { int countWC; countWC = getObjects(WhiteCell. class ).size(); return countWC; } // end countWhiteCellsInBloodstream /** * Add Count */ public void addCountWC( int countWC) { countWC2 = countWC; showWCount(); } /** * Display number of White Cells in Bloodstream. */ private void showWCount() { showText( "White Cell Count: " + countWC2, 663 , 45 ); } /** * Add some points to our current score. (May be negative.) * If the score falls below 0, game's up. */ public void addScore( int points) { score = score + points; showScore(); if (score < 0 ) { Greenfoot.playSound( "game-over.wav" ); Greenfoot.stop(); } } /** * Show our current score on screen. */ private void showScore() { showText( "Score: " + score, 80 , 25 ); } /** * Count down the game time and display it. Stop the game * with a winning message when time is up. */ private void countTime() { time--; showTime(); if (time == 0 ) { showEndMessage(); Greenfoot.stop(); } } /** * Show the remaining game time on screen. */ private void showTime() { showText( "Time: " + time, 700 , 25 ); } /** * Show the end-of-game message on screen. */ private void showEndMessage() { showText( "Time is up - you win!" , 390 , 150 ); showText( "Your final score: " + score + " points" , 390 , 170 ); } /** * Prepare the world for the start of the program. In this case: Create * a white blood cell and the lining at the edge of the blood stream. */ private void prepare() { WhiteCell whitecell = new WhiteCell(); addObject(whitecell, 128 , 179 ); Lining lining = new Lining(); addObject(lining, 126 , 1 ); Lining lining2 = new Lining(); addObject(lining2, 342 , 5 ); Lining lining3 = new Lining(); addObject(lining3, 589 , 2 ); Lining lining4 = new Lining(); addObject(lining4, 695 , 5 ); Lining lining5 = new Lining(); addObject(lining5, 114 , 359 ); Lining lining6 = new Lining(); Lining lining7 = new Lining(); addObject(lining7, 295 , 353 ); Lining lining8 = new Lining(); Lining lining9 = new Lining(); Lining lining10 = new Lining(); addObject(lining10, 480 , 358 ); Lining lining11 = new Lining(); addObject(lining11, 596 , 359 ); Lining lining12 = new Lining(); addObject(lining12, 740 , 354 ); Border border = new Border(); addObject(border, 0 , 180 ); Border border2 = new Border(); addObject(border2, 770 , 180 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * This is a white blood cell. This kind of cell has the job to catch bacteria and * remove them from the blood. * * @author Michael Kölling * @version 1.0 */ public class WhiteCell extends Actor { /** * */ public void WhiteCell() { } /** * Act: move up and down when cursor keys are pressed. */ public void act() { checkKeyPress(); checkCollision(); } /** * Check whether a keyboard key has been pressed and react if it has. */ private void checkKeyPress() { if (Greenfoot.isKeyDown( "up" )) { setLocation(getX(), getY()- 8 ); } if (Greenfoot.isKeyDown( "down" )) { setLocation(getX(), getY()+ 8 ); } if (Greenfoot.isKeyDown( "right" )) { setLocation(getX()+ 4 , getY()); } if (Greenfoot.isKeyDown( "left" )) { setLocation(getX()- 4 , getY()); } } /** * Check whether we are touching a bacterium or virus. Remove bacteria. * Game over if we hit a virus. */ private void checkCollision() { if (isTouching(Bacteria. class )) { Greenfoot.playSound( "slurp.wav" ); removeTouching(Bacteria. class ); Bloodstream bloodstream = (Bloodstream)getWorld(); bloodstream.addScore( 20 ); } if (isTouching(Virus. class )) { removeTouching(Virus. class ); Bloodstream bloodstream = (Bloodstream)getWorld(); bloodstream.addScore(- 100 ); } } } |