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:
1 2 3 4 5 6 7 8 9 10 | 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 ); } |
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 46 47 48 | 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(); } } |