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

2014/6/15

Europe Map

1
2
danpost danpost

2014/6/17

#
Sbaliyev wrote...
Every capital must asked 1 time not more how am i suppose to do this?
It would have been nice to know this before we finalized the code. You will need to List the Locatie object and remove them from the list as they are used. You will need to import 'java.util.List' into the Achtergrond class. You will need an instance List object to hold the unchosen capitals and it will need to be loaded with the capitals after they are all created.
// add instance field
private List<Locatie> locaties;
// add as last statement in 'populateWorld' method
locaties = (List<Locatie>) getObjects(Locatie.class);
Then we need to change the 'setLocatie' method to choose from the list of unchosen.
// change 'setLocatie' method to the following
private void setLocatie()
{
    // check for an empty list (all have been chosen)
    if (locaties.isEmpty())
    {
        Greenfoot.stop();
        return;
    }
    // choose and remove from list
    actieveLocatie = locaties.remove(Greenfoot.getRandomNumber(locaties.size));
    vragen.toonVraag(actieveLocatie.getName());
}
You need to login to post a reply.
1
2