You assigned the WeatherInput object in the MainMenu class. All you have done in the BeeWorld object is declared a field to hold a WeatherInput object, which needs to be assigned the same object.
1 2 3 | BeeWorld beeWorld = new BeeWorld();beeWorld.weatherInput = ((MainMenu)getWorld()).weatherInput;Greenfoot.setWorld(beeWorld); |
1 2 3 4 5 6 7 8 9 10 11 | public void act() { //Set image of button and when pressed change the screen if(Greenfoot.mouseClicked(this)) { BeeWorld beeWorld = new BeeWorld(); beeWorld.WeatherInput = ((MainMenu)getWorld()).WeatherInput; Greenfoot.setWorld(beeWorld); }} |
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 | public void regularTemperature(){ //add flowers to the bee world PinkFlower PinkFlower = new PinkFlower (); YellowFlower YellowFlower = new YellowFlower (); PurpleFlower PurpleFlower = new PurpleFlower (); addObject(new YellowFlower(), 500, 500); addObject(new PurpleFlower(), 100, 300); addObject(new YellowFlower(), 200, 400); addObject(new PinkFlower(), 100, 100); addObject(new YellowFlower(), 700, 400); addObject(new PurpleFlower(), 800, 200); addObject(new PinkFlower(), 600, 100); addObject(new PinkFlower(), 400, 700); //add bees to the bee world Forager Forager = new Forager (); Worker Worker = new Worker (); Queen Queen = new Queen (); addObject(new Queen(), 500, 250); //add the hive to the bee world Hive Hive = new Hive (); addObject(new Hive(), 650, 400);}public void highTemperature(){ //add flowers to the bee world PinkFlower PinkFlower = new PinkFlower (); YellowFlower YellowFlower = new YellowFlower (); PurpleFlower PurpleFlower = new PurpleFlower (); addObject(new YellowFlower(), 500, 500); addObject(new PurpleFlower(), 100, 300); addObject(new YellowFlower(), 200, 400); addObject(new PinkFlower(), 100, 100); addObject(new PinkFlower(), 700, 400); addObject(new PurpleFlower(), 800, 200); //add bees to the bee world Forager Forager = new Forager (); Worker Worker = new Worker (); Queen Queen = new Queen (); addObject(new Queen(), 500, 250); //add the hive to the bee world Hive Hive = new Hive (); addObject(new Hive(), 650, 400); } |
1 2 3 4 5 6 7 8 9 | public void act() { if(Greenfoot.mouseClicked(this)) { BeeWorld beeWorld = new BeeWorld(); beeWorld.WeatherInput = ((MainMenu)getWorld()).WeatherInput; Greenfoot.setWorld(beeWorld); }} |
1 | beeWorld.runSimulation(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public void runSimulation(){ WeatherInput = new WeatherInput(); int weatherValue = WeatherInput.weatherValue; if(weatherValue >= -40 || weatherValue <= 15) { //if the weather value is between -40 and 15 then the low temp simulation will run lowTemperature(); } else if(weatherValue >= 16 || weatherValue <= 27) { //if the weather value is between 16 and 27 then the regular temp simulation will run regularTemperature(); } else if(weatherValue >= 28 || weatherValue <= 40) { //if the weather value is between 28 and 40 then the high temp simulation will run highTemperature(); } } |