Hello,
This is my first time using Greenfoot.
I would like to populate cars objects (blue,red,green) at 4 different locations only - VerticallyUp, VerticallyDown, HorizontallyUp, HorizontallyDown.
All I can think of is creating 4 functions for each location inside the World class, then randomly populate these objects(randomly too)
But I think this solution is not efficient maintaining wise. Because I'm basically copying the same function 4 times, then changing the locations manually and chanting the movement using turn(). In VerticalUp it will be turn(90) VerticalDown(-90) and so on
Do you guys have any better idea?
Snippet:
public void createVerticallyDown(int k)
{
switch(k)
{
case 1:
Vehicle blue = new Blue();
blue.getImage().scale(50,50); //optional
blue.turn(-90);
addObject(blue, 450, 590);
break;
case 2:
Vehicle red = new Red();
red.getImage().scale(50,50); //optional
red.turn(-90);
addObject(red, 450, 590);
break;
}
}
}
