Hi!
Explain, please:
After first click number= previous value (after start i'ts 0)
After second click number = correct
Thanks!
public class MyWorld extends World { int number; public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(10, 10, 50); prepare(); } private void prepare() { for (int i=0; i<7;i++){ Bomb bomb = new Bomb(); bomb.getImage().setTransparency(100); addObject(bomb,Greenfoot.getRandomNumber(11),Greenfoot.getRandomNumber(11)); } } public void act(){ if(Greenfoot.mouseClicked(null)){ MouseInfo mi = Greenfoot.getMouseInfo(); int mix = mi.getX(); int miy = mi.getY(); Empty em = new Empty(); addObject(em,mix,miy); // showText(""+Empty.number, mix, miy); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.*; public class Empty extends Actor { static int number; List<Bomb> bList = new ArrayList<>(); public void act() { bList = getNeighbours(1, true, Bomb.class); number = bList.size(); } }