Zzimon wrote...
Again where is this supposed to go, I'm guessing in each of my tile actors (Sword, Torch and Coin) right?

1 2 3 4 5 | 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 ; } |
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 | { 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); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 | 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 ; } } |
1 2 | 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 ;} |
1 2 | 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 ;} |