I have a private method that is called from the constructor to instantiate a bunch of objects.
I can do it two ways.
private Monster[,] createMonsters()
{
Monster[,] myMonsterArray = new Monster[8, 6];
for (int i = 0; i < 8; i++)
{
myMonsterArray[0, i] = new Monster(SpriteFactory.getMonster1Sprite());
myMonsterArray[1, i] = new Monster(SpriteFactory.getMonster2Sprite());
myMonsterArray[2, i] = new Monster(SpriteFactory.getMonster3Sprite());
myMonsterArray[3, i] = new Monster(SpriteFactory.getMonster1Sprite());
myMonsterArray[4, i] = new Monster(SpriteFactory.getMonster2Sprite());
myMonsterArray[5, i] = new Monster(SpriteFactory.getMonster3Sprite());
}
return myMonsterArray;
}
called with
monsterArray = createMonsters();
or
private void createMonsters()
{
monsterArray = new Monster[8, 6];
for (int i = 0; i < 8; i++)
{
monsterArray[0, i] = new Monster(SpriteFactory.getMonster1Sprite());
monsterArray[1, i] = new Monster(SpriteFactory.getMonster2Sprite());
monsterArray[2, i] = new Monster(SpriteFactory.getMonster3Sprite());
monsterArray[3, i] = new Monster(SpriteFactory.getMonster1Sprite());
monsterArray[4, i] = new Monster(SpriteFactory.getMonster2Sprite());
monsterArray[5, i] = new Monster(SpriteFactory.getMonster3Sprite());
}
}
called with
createMonsters();
Is either better or worse?