danpost wrote...
xixEmilyxix wrote...
am i meant to add the ''addedToWorld'' method anywhere?setPaintOrder(AddDay.class);
setPaintOrder(AddDay.class);
public void newDay() { //start new day //remove all objects List objects = getObjects(null); removeObjects(objects); runSimulation(); //add bee every 5 days if(dayValue = 5 || dayValue = 10 || dayValue = 15 || dayValue = 20 || dayValue = 25 || dayValue = 30 || dayValue = 35 || dayValue = 40 || dayValue = 45 || dayValue = 50) { //add new bee addObject(new Forager(), 550, 250); } }
if (dayValue%5 == 0) addObject(new Forager(), 550, 250);
if (dayValue%5 == 0) addObject(new Forager(), 550, 250);
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(); } public void newDay() { //start new day //remove all objects List objects = getObjects(null); removeObjects(objects); //add the help and add day button back //add the add day button AddDay AddDay = new AddDay (); addObject (AddDay, getWidth (), getHeight()); AddDay.setLocation(820,500); //add the help button HelpButton HelpButton = new HelpButton (); addObject (HelpButton, getWidth (), getHeight ()); HelpButton.setLocation(100,190); //random chance to see if bee dies //add bee every 5 days if (dayValue%5 == 0) addObject(new Forager(), 550, 250); updateHoney(); }
public class AddDay extends Actor { public AddDay() { //Set image of button setImage(new GreenfootImage("addDaybutton.png")); } public void act() { //check if the button is being pressed addDay(); } public void addDay() { if(Greenfoot.mouseClicked(this)) { BeeWorld beeWorld = (BeeWorld) getWorld(); beeWorld.updateDay(); } } protected void addedToWorld(World world) { ((BeeWorld)world).updateDay(); } }
import greenfoot.*; public class BeeWorld extends World { AddDay addDay = new AddDay(); HelpButton helpButton = new HelpButton(); int dayValue; public BeeWorld() { super(900, 600, 1); newDay(); } private void newDay() { dayValue++; showText("Day: "+dayValue, 810, 50); removeObjects(getObjects(null)); addObject(addDay(), 820, 500); addObject(helpButton, 100, 190); if (dayValue%5 == 0) { addObject(new Forager(), 550, 250); updateHoney(); } } public void act() { if (Greenfoot.mouseClicked(addDay)) newDay(); if (Greenfoot.mouseClicked(helpButton)) help(); } private void help() { ... } }
import greenfoot.*; public class AddDay extends Actor { public AddDay() { setImage(new GreenfootImage("addDaybutton.png")); } }
public class SimpleActor extends greenfoot.Actor {}
import greenfoot.*; public class BeeWorld extends World { Actor btnAddDay, btnHelp; int dayValue; public BeeWorld() { super(900, 600, 1); btnAddDay = new SimpleActor(); btnAddDay.setImage(new GreenfootImage("addDaybutton.png")); btnHelp = new SimpleActor(); btnHelp.setImage(new GreenfootImage("helpbutton.png")); newDay(); } private void newDay() { removeObject(getObjects(null)); dayValue++; showText("Day: "+dayValue, 810, 50); addObject(btnAddDay, 820, 500); addObject(btnHelp, 100, 190); if (dayValue%5 == 0) { addObject(new Forager(), 550, 250); updateHoney(); } } public void act() { if (Greenfoot.mouseClicked(btnAddDay)) newDay(); if (Greenfoot.mouseClicked(btnHelp)) help(); } private void help() { ... } public void updateHoney() { ... } }
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)) { startSimulation(); } } private void startSimulation() { Greenfoot.setWorld(new BeeWorld(((MainMenu)getWorld()).weatherInput.weatherValue)); } }
public class BeeWorld extends World { //declare variables int beeValue; Flower PinkFlower; Flower PurpleFlower; Flower YellowFlower; StartButton StartButton; int weatherValue; Hive Hive; Bee Forager; Bee Worker; Bee Queen; public static Flower flower; int dayValue; int honeyValue; int nectarValue; Actor btnAddDay, btnHelp, btnEndSimulation; /** * Constructor for objects of class BeeWorld. * */ public BeeWorld(int weatherVal) { //set background to main screen when button is pressed super(864, 540, 1); setBackground(new GreenfootImage("Background.png")); //add buttons btnAddDay = new Buttons(); btnAddDay.setImage(new GreenfootImage("addDaybutton.png")); btnHelp = new Buttons(); btnHelp.setImage(new GreenfootImage("helpButton.png")); btnEndSimulation = new Buttons(); btnEndSimulation.setImage(new GreenfootImage("EndSimulationbutton.png")); addObject(btnEndSimulation, 50, 500); //run new day newDay(); //add the counter for the bee value showText("Bees: ", 810, 20); //declare weatherValue weatherValue = weatherVal; //show honey and nectar values nectarValue = 0; honeyValue = 0; showText("Nectar: " + nectarValue, 810, 80); showText("Honey: " + honeyValue, 810, 110); } 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 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 back showText("Day: "+dayValue, 810, 50); addObject(btnAddDay, 820, 500); addObject(btnHelp, 100, 190); addObject(btnEndSimulation, 50, 500); //run simulation again runSimulation(); //random chance to see if bee dies //add bee every 5 days if (dayValue%5 == 0) { addObject(new Forager(), 550, 250); } }
Greenfoot.setWorld(new BeeWorld(weatherInput.weatherValue));
Greenfoot.setWorld(new BeeWorld(this.weatherInput.weatherValue));