This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zzimon
Zzimon wrote ...

2014/4/27

Creating a grid in a non-grid world

1
2
3
4
5
6
danpost danpost

2014/4/30

#
To test the Bejeweled_World class, right click on its class and select 'new Bejeweled_World()'. EDIT: WAIT, where is your 'addObject' line after the 'while' block? The last statement inside the double 'for' block should be:
1
addObject(actor, col, row);
Zzimon Zzimon

2014/4/30

#
Uhm, I don't have one^^' and if I put one in how's it supposed to look? I know the basic addObject command but with the
1
2
3
4
5
6
7
8
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(); 
            }
part shouldn't it be something like 'addObject (Actor)' or somethign like that EDIT: just saw your edit, thanks :)
Zzimon Zzimon

2014/4/30

#
They spawned! :D Thank you oh so very much!
Zzimon Zzimon

2014/4/30

#
Ok, as it is now they won't be replaced by new tiles if they move or disappear right? Now I just need a way to make the actors switch places, also they still spawn with 3-5 in a straight line
Zzimon Zzimon

2014/4/30

#
I can't really come up with a way to fix the initial spawn, help please. I just need them to not spawn at a length of 3 or more in a straight line, possibly just a check for 2 surrounding in which case it will switch with another tile
danpost danpost

2014/4/30

#
danpost wrote...
First, we must preclude 'null' for the actor; so, return a false value if the actor given is 'null'. Then, we do one direction, say 'up', and then the other 'left'. We cannot place the actor if there are at least two tiles above it and both are of the same class. If the row is at least the third row and both locations above it hold the same class object, return a false value. Do similar to 'up' for 'left'. If at this point, we have not returned a false value, then the actor can be placed there; so, the last statement in the 'canPlace' method should be 'return true;'.
This is what you should put in the 'canPlace' method.
Zzimon Zzimon

2014/4/30

#
well that's all good but I don't really know the code that will provide the checks, so if you could give me an example or at least the commands that would be great :) So far I'd guess to use the getOneObjectAtOffset command but i simply don't really know how to use this properly
Zzimon Zzimon

2014/4/30

#
Here is my own attempt at this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public Coin()
{
    getImage().scale(40, 40);
}   
public boolean three_coin()
{
    Actor coin = getOneObjectAtOffset( 0, getImage().getHeight()/2, Coin.class);
    if (coin == null)
    {
        return false;
    }
    else
    {
        return true;
        getWorld().removeObject(coin);
    }
}
My logic behind this is that the 'Actor coin = getOneObjectAtOffset( 0, getImage().getHeight()/2, Coin.class);' line should check the box beneath the Coin actor and then the 'getWorld().removeObject(coin);' should remove the one beneath, though for some reason it marks up this line and describes it as an unreachable statement :/
danpost danpost

2014/4/30

#
Methods needed would be: (1) the World class method 'getObjectsAt' (which returns a List object); (2) the List class method 'get' (which returns an Object instance from the list); and, (3) the Object class method 'getClass' (which returns the class of an Object instance).
Zzimon Zzimon

2014/4/30

#
And how should these be implemented?
Zzimon Zzimon

2014/4/30

#
I feel like I've become quite annoying in my endless stupid questions but I really am clueless as to what to do with this one but it's a school project and I'm desperate, if it would in any way help I am more than willing to pay for your help if you manage to help me get this done. Edit: please help ^^'
danpost danpost

2014/4/30

#
danpost wrote...
If the row is at least the third row and both locations above it hold the same class object, return a false value.
'If the row is at least the third row':
1
2
3
if (y > 1) // zero and one are the first two rows
'[if] both locations above it hold the same class object [as "actor"]';
[code]if (getObjectsAt(x, y-1).get(0).getClass() == actor.getClass()) // for the first one above
You should be able to figure out the check for the second one above to complete the vertical check. If these checks are all true, then return a false value. Then if similar checks for the 'left' direction (instead of the 'up' direction) are all true, return a false value That will exhaust all the possible fails for placing the actor at that location, so at the end, return true.
Zzimon Zzimon

2014/4/30

#
ok, thanks, just to be sure line number 1 simply checks if the row is the third or below right? what does the code bracket entail? I don't quite understand this one but the following code:
1
if (getObjectsAt(x, y-1).get(0).getClass() == actor.getClass())
just gets the one above and checks which one that is And then for the check for the other one above it it's supposed to be something like this 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; }
[code]if (getObjectsAt(x, y-1).get(0).getClass() == actor.getClass())
{ return false; }
Zzimon Zzimon

2014/4/30

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

2014/4/30

#
Yes. We do not need to perform any checks if there are not at least two tiles in that direction. Then, if there are, if the two nearest in that direction are of the same class as the actor to be placed, then we cannot place it and must choose a different actor.
danpost wrote...
If these checks are all true, then return a false value.
This does not mean if ANY one is true. The three conditions must be ANDed (using '&&' between them), so that all must be true to force another actor choice.
There are more replies on the next page.
1
2
3
4
5
6