Zzimon wrote...
Again where is this supposed to go, I'm guessing in each of my tile actors (Sword, Torch and Coin) right?
if (y > 1) // zero and one are the first two rows
if (getObjectsAt(x, y-2).get(0).getClass() == actor.getClass())
{ return false; }
if (getObjectsAt(x, y-1).get(0).getClass() == actor.getClass())
{ return false; } {
public Bejeweled_World()
{
super(20, 10, 60);
GreenfootImage bg = new GreenfootImage("Bejeweled_bg.jpg");
bg.scale(getCellSize(), getCellSize());
setBackground(bg);
prepare();
}
private boolean canPlace(Actor actor, int x, int y)
{
if (actor == null) return false;
// other checks returning false if actor cannot be placed
return true;
if (y > 1) // zero and one are the first two rows
if (getObjectsAt(x, y-2).get(0).getClass() == actor.getClass())
{ return false; }
if (getObjectsAt(x, y-1).get(0).getClass() == actor.getClass())
{ return false; }
}
public void prepare()
{
for (int row=0; row<getHeight(); row++) for (int col=0; col<getWidth(); col++)
{
Actor actor = null;
while (!canPlace(actor, col, row))
{
int which = Greenfoot.getRandomNumber(3);
if(which == 0) actor = new Sword();
if(which == 1) actor = new Coin();
if(which == 2) actor = new Torch();
}
addObject(actor, col, row);
}
}
}private boolean canPlace(Actor actor, int x, int y)
{
if (actor == null) return false;
// other checks returning false if actor cannot be placed
return true;
if (y > 1)
if (getObjectsAt(x, y-2, Actor.class).get(0).getClass() == actor.getClass())
{ return false; }
if (getObjectsAt(x, y-1, Actor.class).get(0).getClass() == actor.getClass())
{ return false; }
} if (y>1 && getObjectsAt(x, y-2m Actor.class).get(0).getClass() == actor.getClass() && getObjectsAt(x, y-1, Actor.class).get(0).getClass() == actor.getClass())
{return false;}if (y>1 && getObjectsAt(x, y-2m Actor.class).get(0).getClass() == actor.getClass() && getObjectsAt(x, y-1, Actor.class).get(0).getClass() == actor.getClass())
{return false;}