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

2014/5/1

Selecting characters and switching them with others

5
6
7
8
9
10
11
danpost danpost

2014/5/3

#
Zzimon wrote...
yeah the class would be quite easy but the rest of the code still has to be altered to use the last actor
ONLY the prepare method as stated above (in my last post). Do not forget to change the random value.
Zzimon Zzimon

2014/5/3

#
Isn't it pretty much only the Bejeweled_World that really has anything to do with the amount of actors i.e. this:
    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);
        }
    }
so it'll be changed to getRandomNumber(4) instead and then just another if for the number 3
danpost danpost

2014/5/3

#
Zzimon wrote...
Isn't it pretty much only the Bejeweled_World that really has anything to do with the amount of actors i.e. this: < Code Omitted > so it'll be changed to getRandomNumber(4) instead and then just another if for the number 3
That is all!
danpost danpost

2014/5/3

#
danpost wrote...
That is all!
The joy of OOP!
Zzimon Zzimon

2014/5/3

#
now the added Tile actor works just as the others, the tiles are now Sword, Coin, Torch and Key. So now we just need to fix the removal of sets and the 'respawn' following
Zzimon Zzimon

2014/5/3

#
yeah it is quite a lot easier with code like this, it's like 2 lines instead of 100 :)
danpost danpost

2014/5/3

#
Ok. Like I said we need two methods, similar to the getHorizontalMatchingCount and getVerticalMatchingCount; except these will now return List objects containing the matching tiles.
private List<Tile> getHorizontalMatchingTiles(int x, int y)
and similar for 'Vertical'. Instead of declaring a counter field, we will declare a List field; and instead of 'count++;' for matches, we will use something like 'list.add(matchingTile);'. The List field will be declared as follows:
List<Tile> list = new ArrayList();
You will need to add the following import statements:
import java.util.List.*;
import java.util.ArrayList.*;
At the end of the methods, you will return the list. Let us see what you can come up with (remember, it will be very similar to the other two methods).
Zzimon Zzimon

2014/5/3

#
This all has to go in the Bejeweled_World too right? (just to be sure)
Zzimon Zzimon

2014/5/3

#
no 'int' needed? like is it just private List<Tile> and not private int List<Tile> like the MatchCount?
Zzimon Zzimon

2014/5/3

#
ok here I must admit that I don't quite even understand the getVerticalMatchCount properly ^^'. I'm gonna need a CrashCourse in exactly what it all means if I have any hope for a proper List thing, since they were alike. All of my previous suggestions have been solely based on code I've previously used and which were on a whole different level than this ^^'. I learn better with examples when it comes to this.
danpost danpost

2014/5/3

#
Zzimon wrote...
This all has to go in the Bejeweled_World too right? (just to be sure)
Yes.
no 'int' needed? like is it just private List<Tile> and not private int List<Tile> like the MatchCount?
After the modifiers to a method ('private', public' or 'protected' and 'abstract', 'static' and/or 'final'), which may or may not be present, the return type is given. All methods must have a return type (I do not believe that constructors are considered methods and will never have a return type). The return type declares what the method will return to the calling statement (for example: 'getX()' is a method call and the return type of that method is of 'int' type -- meaning it will return an int value back to the calling statement). The return type can be any of the primitive data types or an Object type (String, Actor, World, Class and List are all Object types; in fact anything that is not one of the primitive types is an Object type). The return type always goes just before the method name and is required in a method declaration statement. A 'void' return type means nothing is returned (the method is used to do some processing, instead of being used to 'get' a value or Object). A method can, however, do both.
Zzimon Zzimon

2014/5/3

#
Soo we do need an int since we are fetching information which we need back and this isn't just processing.. right?
danpost danpost

2014/5/3

#
Zzimon wrote...
Soo we do need an int since we are fetching information which we need back and this isn't just processing.. right?
No. At this point, we already know that some set has been created. Now, the information we need is which tiles are included in any and all of those sets that were created. We know that at least three tiles are involved; that means we cannot just return a Tile, or an Actor; as that would only be one of them. We must return a List object which will be a list of Tile objects. I gave you the extra information you needed for using the list in the methods which I asked you to attempt to create. What I did not give you is what you would need as far as calling those methods and using those lists to remove and replace the location of those tiles within the list. But, we are not at that point yet.
danpost danpost

2014/5/3

#
Zzimon wrote...
this isn't just processing.. right?
Actually, this is not processing at all, it is only getting information (the list of actors in a matched set).
Zzimon Zzimon

2014/5/3

#
Could you please just write it up? Then I can see if I can make a connection between it and the getVerticalMatchCount because I'm 100% blank right now, sorry.
There are more replies on the next page.
5
6
7
8
9
10
11