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.
BeeWorld beeWorld = new BeeWorld(); beeWorld.weatherInput = ((MainMenu)getWorld()).weatherInput; Greenfoot.setWorld(beeWorld);
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); } }
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); }
public void act() { if(Greenfoot.mouseClicked(this)) { BeeWorld beeWorld = new BeeWorld(); beeWorld.WeatherInput = ((MainMenu)getWorld()).WeatherInput; Greenfoot.setWorld(beeWorld); } }
beeWorld.runSimulation();
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(); } }