I want to get more familiar in generalizing my code more through methods, so I would be able to save more space and reduce the number of lines used.
Here is an example of the prepare() method the world generates when saving the world:
I feel as if that's too much coding and very repetitive. There must be a better way to code all this. Can someone give me an explanation of what I could do to "reduce" the amount of code, and give a brief example of what it would look like?
I feel as if learning this skill will be able to save me more time, meaning more efficient and smarter coding.
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
int heightPokemonA = getHeight()/5;
int heightPokemonB = getHeight()/3;
Pikachu pikachu = new Pikachu();
addObject(pikachu,getWidth()/8,heightPokemonA);
Squirtle squirtle = new Squirtle();
addObject(squirtle,getWidth()/2,heightPokemonB);
Bulbasaur bulbasaur = new Bulbasaur();
addObject(bulbasaur,getWidth()/ 2 + 350,heightPokemonA);
StartGameButton startGameButton = new StartGameButton();
addObject(startGameButton,getWidth()/2,700);
Label label = new Label("Press on any Pokemon to Interact!");
addObject(label,getWidth()/2 + 300,getHeight()/2 + 50);
Charmander charmander = new Charmander();
addObject(charmander,getWidth()/ 2 + 350,getHeight()/2);
Turtwig turtwig = new Turtwig();
addObject(turtwig,getWidth()/8,getHeight()/2);
Label label2 = new Label("Press Start Game to Play a Round of Guess that Pokemon!");
addObject(label2,getWidth()/2 + 150,635);;
}

