How would I access the value of my score variable from another class?


1 2 3 4 | public static int getScore() { return score; } |
1 | public static int score = (the number you want) |
1 2 3 4 | if (score = 10 ) { addObject( new Square(), 0 , 0 ); } |
1 2 3 4 | if (score = 10 ) { addObject( new Square(), 0 , 0 ); } |
1 2 3 4 | if (score == 10 ) { addObject( new Square2(), 0 , 0 ); } |
1 | int score = <the value score currently is> |
1 | int score = <the value score currently is> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import greenfoot.*; import java.awt.*; public class Score extends Actor { public int score; public void act() { setImage( new GreenfootImage( "Score: " + score, 16 , Color.BLACK, Color.WHITE)); } public void addScore() { score++; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import greenfoot.*; import java.awt.Color; public class Score extends Actor { public int score; public Score() { updateImage(); // initial image } public void updateImage() { setImage( new GreenfootImage("Score: +score, 16 , Color.BLACK, Color.WHITE)); } public void addScore() { score++; updateImage(); // reset image } } |