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 | import lang.stride.*; import java.util.*; import greenfoot.*; /** * */ public class MyWorld extends World { Counter counter = new Counter(); /** * Constructor for objects of class MyWorld. */ public MyWorld() { super ( 900 , 600 , 1 ); prepare(); } public Counter GetCounter() { return counter; } /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. */ private void prepare() { addObject(counter, 50 , 50 ); Emoti1 emoti1 = new Emoti1(); addObject(emoti1, 130 , 114 ); Emoti2 emoti2 = new Emoti2(); addObject(emoti2, 330 , 115 ); Counter counter = new Counter(); addObject(counter, 38 , 49 ); counter.setLocation( 345 , 47 ); counter.setLocation( 135 , 46 ); removeObject(counter); } } |
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 | import lang.stride.*; import java.util.*; import greenfoot.*; /** * */ public class Counter extends Actor { /** * Act - do whatever the Counter wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment. */ int score = 0 ; public void act() { setImage( new GreenfootImage( "Score :" + score, 20 , Color.WHITE, Color.BLACK)); } public void addScore() { score++; } } |