I am trying to make it so that I can change the value of a static integer, diff, I made in MyWorld class in an Actor class when I click my mouse on the Actor.
Here is the code in the act method of my Actor class:
it is printing the "diff = 1" but ((MyWorld)getWorld()).diff = 1; is not working.
in my MyWorld class:
if(Greenfoot.mouseClicked(this)){ ((MyWorld)getWorld()).diff = 1; System.out.println("diff = 1"); getWorld().removeObjects(getWorld().getObjects(Medium.class)); getWorld().removeObjects(getWorld().getObjects(Hard.class)); getWorld().removeObjects(getWorld().getObjects(ChooseYourDifficulty.class)); World world; world = getWorld(); world.removeObject(this); }
private int myLevel; private int[][] map; static int diff; //int x; //int y; private Tadpole myTadpole; private Frog myFrog; public MyWorld() { super(750, 750, 1); setPaintOrder(Titlescreen.class, ChooseYourDifficulty.class, Score.class, Rocket.class, Fly.class, Fly2.class, Car.class, Ambulance.class, Crocodile.class, Crocodile2.class, Rock.class, Frog.class, Log.class, Tadpole.class, Lilypad.class); Titlescreen titlescreen = new Titlescreen(); addObject(titlescreen, getWidth()/2, getHeight()/2); ChooseYourDifficulty chooseYourDifficulty = new ChooseYourDifficulty(); addObject(chooseYourDifficulty, getWidth()/2, getHeight()/2); Easy easy = new Easy(); addObject(easy, 110, 400); Hard hard = new Hard(); addObject(hard, 630, 400); Medium medium = new Medium(); addObject(medium, 380, 400); //mouseClicked(); if(diff == 1){ System.out.println("diff ====1"); myLevel = 0; myTadpole = new Tadpole(); myFrog = new Frog(); map = level1; loadLevel(); prepare(); } if(diff == 2){ myLevel = 1; myTadpole = new Tadpole(); myFrog = new Frog(); map = level2; loadLevel(); prepare(); } if(diff == 3){ myLevel = 2; myTadpole = new Tadpole(); myFrog = new Frog(); map = level3; loadLevel(); prepare(); } }