i am developing a high score system but i am separating it into another class,, world class. the problem is i cant access the variable from another world class help me... how can i access the variable from another world class in another


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 | play aw = new play(); private int score; public gameOver() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 500 , 400 , 1 ); addObject(aw, 300 , 280 ); Greenfoot.start(); showScore(); } public void act() { if (Greenfoot.mouseClicked(aw)) Greenfoot.setWorld( new startup()); } public void adScore( int points) { score = score + points; showScore(); } private void showScore() { showText( "Your Score:" + score, 80 , 25 ); } |
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 | //-------------------------------------------------------------------- boolean isTurning; private int time, timeshower, Stoper; private int score; public static int randomer = Greenfoot.getRandomNumber ( 30 ); /** * Constructor for objects of class MyWorld. * */ public animationStart() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1000 , 500 , 1 ); setPaintOrder(floor. class ); setPaintOrder(Border. class ); start(); score = 0 ; showScore(); time = 0 ; Stoper = 0 ; isTurning = false ; } private void showScore() { showText( "Score: " + score, 80 , 25 ); } public void adScorer( int points) { score = score + points; showScore(); } |
1 2 3 4 5 6 | else if (isTouching(sooe. class )) { removeTouching(sooe. class ); animationStart newsc = (animationStart)getWorld(); newsc.adScorer( 10 ); } |
1 2 3 4 5 6 7 8 | else if (isTouching(sooe. class )) { removeTouching(sooe. class ); animationStart newsc = (animationStart)getWorld(); newsc.adScorer( 10 ); gameOver scor = ( gameOver)getWorld(); scor.adScorer( 10 ); } |
1 | public static int score; |
1 | if (score > gameOver.score) gameOver.score = score; |
1 | gameOver.score = Math.max(score, gameOver.score); |