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

2012/9/13

Changing the lvls

1
2
3
danpost danpost

2012/9/14

#
What are the goals for each level? Level 1 is 50. Level 2 = 70. Level 3 = ? etc?
Stephon231 Stephon231

2012/9/14

#
a know a way to fix the problem but i need a code that references the world to the counter in the wombat
Stephon231 Stephon231

2012/9/14

#
lvl 1 is 50, lvl 2 is 80, lvl 3 is 100
danpost danpost

2012/9/14

#
Are there any other changes between the levels? For examples, (1) are there more grid-squares? (2) are there more enemies of any kind? (3) does the Wombat gain or lose any characteristics or abilities? Is the game supposed to stop after the third level?
stephon231 wrote...
i need a code that references the world to the counter in the wombat
I believe you will have the same problem(s). It would just be a bit more complicated in the world class.
Stephon231 Stephon231

2012/9/14

#
i thought that if i had the method that changed the world in each world that when it switched world that the old value would not work, and if i put that reference to the counter in each world that it would use the value set for the corrent world
Stephon231 Stephon231

2012/9/14

#
this is y i need a code that gives the world a reffence to the value of the counter
danpost danpost

2012/9/14

#
If there are no other changes other than the number of leaves to be eaten, then you only need one world (there is no sense in duplicating worlds just to change one int variable). A whole new sub-world is not warranted for such a change. Replace the code I gave you before with the following
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// class fields
static int level = 0; // to track the level
static int[] goal = { 50, 80, 100 }; // to specify goal at each level
// in the act after 'eatLeaves'
if (leavesEaten == goal[level])
{
    level = level + 1;
    if (level == goal.length) // are all levels complete
    {
        Greenfoot.stop();
        return;
    }
    else
    {
        Greenfoot.setWorld(new MainWorld());
        return;
    }
}
Stephon231 Stephon231

2012/9/14

#
there is more that changes not just the leaves there are new enemies too
danpost danpost

2012/9/14

#
You can use
1
2
3
4
5
6
7
8
9
10
11
12
if (Wombat.level == 0)
{
    // add whatever
}
else if (Wombat.level == 1)
{
    // add whatever
}
else if (Wombat.level == 2)
{
    // add whatever
}
in the world constructor or a method it calls to add what is needed for each level.
Stephon231 Stephon231

2012/9/14

#
i have a way i just need a way to get a refference to the amount of the counter
Stephon231 Stephon231

2012/9/14

#
i have an idea is there a way to transfer the wombat to the next level without resetting the leavesEaten counter
danpost danpost

2012/9/14

#
int counterValue = ((Counter) getObjects(Counter.class).get(0)).getValue(); This will work as long as there is a counter in the world. Check to make sure getObjects(Counter.class) is not empty before using this statement if there is any chance a counter is not in the world.
Stephon231 Stephon231

2012/9/14

#
is there a way to transfer the wombat to the world without the LeavesEaten counter being reset
danpost danpost

2012/9/14

#
To transfer the Wombat object to the next world, your constructor will need to accept a Wombat type object within a parameter.
1
2
3
4
5
6
public World2(Wombat wombat)
{
    super(12, 12, 50); // or whatever size
    addObject(wombat, x, y); // replace x and y with values
    // add all the other objects
}
danpost danpost

2012/9/14

#
Actually, you can just make the leavesEaten field a 'static' field. That will preserve it between world changes and make it accessable with 'Wombat.leavesEaten' in any world or actor sub-class. Then, you can use (in the Wombat class after 'leavesEaten = leavesEaten + 1;'
1
2
3
if (leavesEaten == 50) Greenfoot.setWorld(new World2());
else if (leavesEaten == 130) Greenfoot.setWorld(new World3());
else if (leavesEaten == 230) Greenfoot.stop();
and not have to pass anything to any world. Also, it would not matter if you created a new Wombat object in each level, since any wombat object will increment the same 'leavesEaten' counter when a leaf is eaten.
There are more replies on the next page.
1
2
3