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

2013/4/1

Minimize code

1
2
JetLennit JetLennit

2013/4/1

#
1. Laggy 2.It seemed like a lot of code for a simple task
danpost danpost

2013/4/1

#
Run the scenario for a little bit, then pause it and right-click on the world and select 'Inherited from World'>'getNumberOfObjects()'; post back with the returned value.
bourne bourne

2013/4/1

#
Do what danpost said. Also it really isn't too much code for having 4 options for that one task. You can possibly shorten it a bit, but not a lot. The code here does the same thing as yours ( I omitted some variables that I didn't see use for )
public void spawnTank()  
{   
    if (Greenfoot.getRandomNumber(600) == 0)
    {
        northAndSouth = Greenfoot.getRandomNumber(640);
        // eastAndWest = (Greenfoot.getRandomNumber(540));
        switch (Greenfoot.getRandomNumber(4))
        {
            case 0:     addObject(new tank(), 5, northAndSouth + 5); break;
            case 1:     addObject(new tank(), northAndSouth + 5, 645); break;
            case 2:     addObject(new tank(), 645, northAndSouth + 5); break;
            case 3:     addObject(new tank(), northAndSouth + 5, 5);
        }
    }  
}
Game/maniac Game/maniac

2013/4/1

#
What is break for
bourne bourne

2013/4/1

#
Ends the control structure "switch", otherwise it will continue to next line within it.
JetLennit JetLennit

2013/4/1

#
waited 1 minute and got 6 (including the turret)
JetLennit JetLennit

2013/4/1

#
and its a lot faster now
You need to login to post a reply.
1
2