Hey guys,
So i am doing this task for school, which should contain three different objects(Dijk, Water, Gras) on and 8*8 field. Dijk and Gras are called using two different for loops. And for Water i am using a timer and adding the object from there. However i want that when the object, reaches the third Gras Object of the seventh row to print a message saying "Dijk has been broken". I have tried this using the getOneObjectAtoffset(), but it doesnt work. I hope one of you guys can help me out. This is what my code looks like :
import greenfoot.*; // imports Actor, World, Greenfoot, GreenfootImage
import java.util.Random;
public class WombatWorld extends World
{
/**
* Create a new world with 8x8 cells and
* with a cell size of 60x60 pixels
*/
public WombatWorld()
{
super(8, 8, 60);
//setBackground("cell.jpg");
maakWater();
maakDijk();
maakGras();
}
public void populate()
{
}
private long timeStarted = System.currentTimeMillis();
int x=0;
int y=3;
public void act()
{
long currentTime = System.currentTimeMillis() ;
long elapsedTime = currentTime - timeStarted;
if (elapsedTime / 1000 > 0.1)
{
timeStarted = currentTime;
addObject(new Water(),x,y);
x++;
if (x == 8){
y++;
x = 0;
}
if (getOneObjectAtOffset(8, 8, Water.class)!= null){
System.out.print("Dijkdoorbraak");
//Greenfoot.stop();
}
}
}
public void maakWater()
{
for(int y = 0; y < 3; y++)
{
for(int x=0; x < 8; x++)
{
addObject(new Water(),x,y);
}
}
}
public void maakDijk()
{
for(int y = 3; y < 6; y++)
{
for(int x=0; x < 8; x++)
{
addObject(new Dijk(),x,y);
}
}
}
public void maakGras()
{
for(int y = 6; y < 8; y++)
{
for(int x=0; x < 8; x++)
{
addObject(new Gras(),x,y);
}
}
}
}
Hope you can help me out,
Greetings,
Zakaria

