When i hit the start button for my bee simulation it sets my nectar value to -2 an does not show my day value. Im not sure why this part is happening. Also, my flower class are not displaying the image for my flowers - just a green footprint. And im not sure how to get my values of nectar, honey and days over to my end screen world. These are the codes i have atm:
beeworld:
MainMenu world:
Flower class:
End Screen world
The end screen world is giving errors that say it cannot find symbol variable for the nectarValue and the dayValue
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class BeeWorld here. * * @author (your name) * @version (a version number or a date) */ public class BeeWorld extends World { //declare variables int beeValue; int weatherValue; public static Flower flower; int dayValue; int honeyValue; Actor btnAddDay, btnHelp, btnEndSimulation; private static final String[] FLOWER_COLOR = { "pink", "purple", "yellow" }; /** * Constructor for objects of class BeeWorld. * */ public BeeWorld(int weatherVal) { //set background to main screen when button is pressed super(864, 540, 1); setPaintOrder(Buttons.class); setBackground(new GreenfootImage("Background.png")); //declare weatherValue weatherValue = weatherVal; //set honey value honeyValue = 0; showText("Honey: " + honeyValue, 810, 110); //set day value dayValue = 0; //set nectar value Forager.nectarValue = 0; //run new day newDay(); } public void act() { if (Greenfoot.mouseClicked(btnAddDay)) { newDay(); } if (Greenfoot.mouseClicked(btnHelp)) { help(); } if(Greenfoot.mouseClicked(btnEndSimulation)) { endSimulation(); } } private void endSimulation() { Greenfoot.setWorld(new EndScreen()); } private void help() { //add help menu HelpMenu HelpMenu = new HelpMenu(); addObject (HelpMenu, getWidth(), getHeight()); HelpMenu.setLocation(650,200); //button to be able to remove help menu RemoveMenu RemoveMenu = new RemoveMenu(); addObject (RemoveMenu, getWidth(), getHeight()); RemoveMenu.setLocation(900,200); } public void runSimulation() { 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(); } } private Actor getRandomFlower() { int colorNum = Greenfoot.getRandomNumber(FLOWER_COLOR.length); return new Flower(FLOWER_COLOR[colorNum]); } public void lowTemperature() { //add random coloured flowers to the bee world addObject(getRandomFlower(), 500, 500); addObject(getRandomFlower(), 100, 300); addObject(getRandomFlower(), 200, 400); addObject(getRandomFlower(), 100, 100); addObject(getRandomFlower(), 700, 400); addObject(getRandomFlower(), 800, 200); //add bees to the bee world Worker Worker = new Worker (); Queen Queen = new Queen (); Forager Forager = new Forager (); addObject(new Queen(), 500, 250); addObject(new Forager(), 400, 150); addObject(new Forager(), 450, 200); addObject(new Forager(), 500, 220); addObject(new Forager(), 550, 250); //add the hive to the bee world Hive Hive = new Hive (); addObject(new Hive(), 650, 400); } public void regularTemperature() { //add random coloured flowers to the bee world addObject(getRandomFlower(), 500, 500); addObject(getRandomFlower(), 100, 300); addObject(getRandomFlower(), 200, 400); addObject(getRandomFlower(), 100, 100); addObject(getRandomFlower(), 700, 400); addObject(getRandomFlower(), 800, 200); addObject(getRandomFlower(), 600, 100); addObject(getRandomFlower(), 400, 700); //add bees to the bee world Worker Worker = new Worker (); Queen Queen = new Queen (); Forager Forager = new Forager (); addObject(new Queen(), 500, 250); addObject(new Forager(), 400, 150); addObject(new Forager(), 450, 200); addObject(new Forager(), 500, 220); addObject(new Forager(), 550, 250); addObject(new Forager(), 520, 175); 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 random coloured flowers to the bee world addObject(getRandomFlower(), 500, 500); addObject(getRandomFlower(), 100, 300); addObject(getRandomFlower(), 200, 400); addObject(getRandomFlower(), 100, 100); addObject(getRandomFlower(), 700, 400); addObject(getRandomFlower(), 800, 200); //add bees to the bee world Worker Worker = new Worker (); Queen Queen = new Queen (); Forager Forager = new Forager (); addObject(new Queen(), 500, 250); addObject(new Forager(), 400, 150); addObject(new Forager(), 450, 200); addObject(new Forager(), 500, 220); addObject(new Forager(), 550, 250); addObject(new Forager(), 520, 175); addObject(new Queen(), 500, 250); //add the hive to the bee world Hive Hive = new Hive (); addObject(new Hive(), 650, 400); } public void updateDay() { //update what day it is and run the next day when the day button is clicked dayValue = dayValue +1; showText("Day: " + dayValue, 810, 50); newDay(); } private void newDay() { //start new day //remove all objects List objects = getObjects(null); removeObjects(objects); //increase day value dayValue++; //increase honey value updateHoney(); //add buttons btnAddDay = new Buttons(); btnAddDay.setImage(new GreenfootImage("addDaybutton.png")); btnHelp = new Buttons(); addObject(btnAddDay, 820, 500); btnHelp.setImage(new GreenfootImage("helpButton.png")); addObject(btnHelp, 100, 190); btnEndSimulation = new Buttons(); btnEndSimulation.setImage(new GreenfootImage("EndSimulationbutton.png")); addObject(btnEndSimulation, 50, 500); //run simulation again runSimulation(); //add bee every 5 days if (dayValue%5 == 0) { addObject(new Forager(), 550, 250); } } public void updateHoney() { //take away from nectar value Forager.nectarValue = Forager.nectarValue - 2; //increase honey value honeyValue = honeyValue + 2; //add the counter for the honey value and nectar value showText("Honey: " + honeyValue, 810, 110); showText("Nectar: " + Forager.nectarValue, 810, 80); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class mainMenu here. * * @author (your name) * @version (a version number or a date) */ public class MainMenu extends World { //declare variables ErrorMessageWeather ErrorMessageWeather; WeatherInput weatherInput = new WeatherInput(); Actor btnHelp, btnStartButton; /** * Constructor for objects of class mainMenu. * */ public MainMenu() { // Create the main menu super(864, 540, 1); Greenfoot.start(); setBackground(new GreenfootImage("MainMenu.png")); //add the help button btnHelp = new Buttons(); btnHelp.setImage(new GreenfootImage("helpButton.png")); addObject(btnHelp, 100, 190); //add start button to main menu btnStartButton = new Buttons(); btnStartButton.setImage(new GreenfootImage("StartButton.png")); addObject (btnStartButton, 150, 350); //add weather input box to main menu addObject (weatherInput, getWidth (), getHeight ()); weatherInput.setLocation(400,250); } public void act() { if(Greenfoot.mouseClicked(btnStartButton)) { //start simulation when start button is clicked startSimulation(); } if (Greenfoot.mouseClicked(btnHelp)) { //show help menu when help button is clicked help(); } } private void startSimulation() { Greenfoot.setWorld(new BeeWorld(weatherInput.weatherValue)); } private void help() { //add help menu HelpMenu HelpMenu = new HelpMenu(); addObject (HelpMenu, getWidth(), getHeight()); HelpMenu.setLocation(650,200); //button to be able to remove help menu RemoveMenu RemoveMenu = new RemoveMenu(); addObject (RemoveMenu, getWidth(), getHeight()); RemoveMenu.setLocation(900,200); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * A pile of food. The pile consists initially of 100 crumbs of food. * * @author Michael Kolling * @version 1.1 */ public class Flower extends Actor { //create variable to be able to change colour of flowers public String color; public Flower(String pigment) { //set image of flowers color = pigment; GreenfootImage image = new GreenfootImage(color+"Flower.png"); } public void act() { } public boolean touchingForager() { //check if touching bee then return it return isTouching(Forager.class); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class EndScreen here. * * @author (your name) * @version (a version number or a date) */ public class EndScreen extends World { Actor btnMainMenuButton; /** * Constructor for objects of class EndScreen. * */ public EndScreen() { //create end screen super(864, 540, 1); Greenfoot.start(); setBackground(new GreenfootImage("EndScreen.png")); //add main menu button btnMainMenuButton = new Buttons(); btnMainMenuButton.setImage(new GreenfootImage("MainMenubutton.png")); addObject(btnMainMenuButton, 50, 500); //add statistics showText("Nectar Value: ", + nectarValue, 420, 270); showText("Honey Value: ", + Forager.nectarValue, 420, 290); showText("Days: ", + dayValue, 420, 310); } public void act() { if (Greenfoot.mouseClicked(btnMainMenuButton)) { MainMenu(); } } private void MainMenu() { Greenfoot.setWorld(new MainMenu()); } }