Good day,
What I am aiming for in my 'Game' world class is a way of retrieving a string in some kind of variable so that the one map creating method (not world constructor) will be able to receive many different arrays depending on how the map creator is called (in its condition).
Currently, I have each map being created in a separate identical method (if you were to ignore the difference of array name) & this makes creating new maps more tedious than I believe it needs to be...
Any help would be appreciated, preferably one involving a way of storing a string in some kind of variable so that the method condition is easy to solve, but it most likely will involve some kind of use of array. Don't worry about suggesting the array names be changed, I'm planning to do that anyway!
Below is the group of methods/arrays involved in each class (most of it is either map arrays or methods to utilise the map creation methods) :
/**
* This World below is very important towards the placement of each level.
* Each value represents one Wall tile.
* e.g. If you wanted to clip two walls
* together along the x-axis, that would require the wall's x-coords to be
* different to the ones listed here.
* There has to be 18 values in the World below, so long as the values are
* between 0 - 90, it should be accepted.
*/
private int[] xCoordinate=
{
2,7,12,17,22,27,32,37,42,47,52,57,62,67,72,77,82,87
};
/**
* Worlds containing 'WWorld' are world Worlds (hopefully there is more than one)
*/
private int[] createWorld=
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,
1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,9,
0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,9,
0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,99
};
private int[] messaboutWorld=
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,
0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,9,
0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,9,
0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,9,
0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,9,
0,0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,0,9,
0,0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,0,9,
0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,9,
0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,9,
0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,0,9,
0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,0,7,0,9,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,99
};
private int[] blankWorld=
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,
1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,99
};
/**
* Key is:
* 0 = Nothing, 1 = Wall, 2 = Enemy, 3 = Spawner, 7 = controls, 8 = Level goal,
* 9 should not be changed, manages new row
*
* (Level_goal MUST be in a different location to every other world)
*/
private int[] mazeWorld1=
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,
1,0,0,0,0,0,0,0,0,0,0,1,0,1,2,0,0,1,9,
1,0,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,1,9,
1,0,1,0,0,3,0,0,0,1,0,1,0,1,2,0,0,1,9,
1,0,1,0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,9,
1,0,1,0,1,1,1,1,0,1,0,1,0,1,1,0,1,1,9,
1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,9,
1,0,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,1,9,
1,0,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,1,9,
1,0,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,1,9,
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,9,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,99
};
/**
* If the condition is:
* 1 = smiley face world
* 2 = The world with lots of tools
* 3 = A blank world!
*/
public void setWorld(int worldNumber)
{
refreshWorld();
switch(worldNumber)
{
case 1:
createWorld();
break;
case 2:
createMessabout();
break;
case 3:
createBlank();
break;
case 4:
createMaze1();
break;
}
}
public void refreshWorld()
{
removeObjects(getObjects(Enemy.class));
removeObjects(getObjects(Wall.class));
removeObjects(getObjects(Spawner.class));
//removeObjects(getObjects(Level_goal.class));
}
/**
* This method utilises the 'blankWorld' World. The integers used represent the following:
* "1=Wall class", "2=Enemy class", "8 = Spawner class", "9 = begin new row"
*/
private void createBlank()
{
int counter = 0;
int ypos = 0;//xpos stands for X-Position
int limit = 0;
while( blankWorld[counter] != 99)
{
//the follwing are te 3 checks for what a tile might be
if(blankWorld[counter] == 1)
{
addObject(new Wall(), xCoordinate[counter-limit] ,ypos+2);
}
if(blankWorld[counter] == 2)
{
addObject(new Enemy(movedIncrementor(false)), xCoordinate[counter-limit] ,ypos+2);
}
if(blankWorld[counter] == 3)
{
addObject(new Spawner(1), xCoordinate[counter-limit] ,ypos+2);
}
if(blankWorld[counter] == 7)
{
addObject(new Controls(), xCoordinate[counter-limit] ,ypos+2);
}
if(blankWorld[counter] == 8)
{
addObject(new Level_goal(), xCoordinate[counter-limit] ,ypos+2);
}
if(blankWorld[counter] == 9) //New row
{
ypos +=5;
limit = counter+1;
}
counter += 1;
}
}
private void createWorld()
{
int counter = 0;
int ypos = 0;//xpos stands for X-Position
int limit = 0;
/**
* This line of code and many like it can be explained like this:
* The Method starts with a counter of 0 and sets the ypos (or y-axis row number)
* to 0 in order to start from ther beginning.
* The counter is NOT used to end the execution of this method's 'while' section.
*/
while( createWorld[counter] != 99)
{
if(createWorld[counter] == 1)
{
addObject(new Wall(), xCoordinate[counter-limit] ,ypos+2);
}
if(createWorld[counter] == 2)
{
addObject(new Enemy(movedIncrementor(false)), xCoordinate[counter-limit] ,ypos+2);
}
if(createWorld[counter] == 3)
{
addObject(new Spawner(1), xCoordinate[counter-limit] ,ypos+2);
}
if(createWorld[counter] == 7)
{
addObject(new Controls(), xCoordinate[counter-limit] ,ypos+2);
}
if(createWorld[counter] == 9)
{
ypos +=5;
limit = counter+1; //Allows repeated counting of
}
counter += 1;
}
}
private void createMessabout()
{
int counter = 0;
int ypos = 0;//xpos stands for X-Position
int limit = 0;
while( messaboutWorld[counter] != 99)
{
//the follwing are te 3 checks for what a tile might be
if(messaboutWorld[counter] == 1)
{
addObject(new Wall(), xCoordinate[counter-limit] ,ypos+2);
}
if(messaboutWorld[counter] == 2)
{
addObject(new Enemy(movedIncrementor(false)), xCoordinate[counter-limit] ,ypos+2);
}
if(messaboutWorld[counter] == 3)
{
addObject(new Spawner(1), xCoordinate[counter-limit] ,ypos+2);
}
if(messaboutWorld[counter] == 6)
{
addObject(new Controls(), xCoordinate[counter-limit] ,ypos+2);
}
if(messaboutWorld[counter] == 7)
{
addObject(new Spawner(1), xCoordinate[counter-limit] ,ypos+2);
}
if(messaboutWorld[counter] == 9)
{
ypos +=5;
limit = counter+1; //Allows repeated counting of
}
counter += 1;
}
}
private void createMaze1()
{
int counter = 0;
int ypos = 0;//xpos stands for X-Position
int limit = 0;
while( mazeWorld1[counter] != 99)
{
//the follwing are te 3 checks for what a tile might be
if(mazeWorld1[counter] == 1)
{
addObject(new Wall(), xCoordinate[counter-limit] ,ypos+2);
}
if(mazeWorld1[counter] == 2)
{
addObject(new Enemy(movedIncrementor(false)), xCoordinate[counter-limit] ,ypos+2);
}
if(mazeWorld1[counter] == 3)
{
addObject(new Spawner(1), xCoordinate[counter-limit] ,ypos+2);
}
if(mazeWorld1[counter] == 7)
{
addObject(new Controls(), xCoordinate[counter-limit] ,ypos+2);
}
if(mazeWorld1[counter] == 9) //New row
{
ypos +=5;
limit = counter+1;
}
counter += 1;
}
}



