I need to create a map which has randomly placed trees and food. For the map i am looking to create a 2d array and then add the trees and food to the array with use of classes, is this possible?
class Tree {
char tsymbol;
}
class Food {
char fsymbol;
}
The classes only have to have a symbol stored in them for now, which will be the icon which represents the objects on the map.
public void printWorld (){
int a;
int b;
char[][] map = new char[15][12];
for (a=1; a<=15; ++a)
{
for (b=1; b<=12; ++b)
{
foodsymbol.fsymbol = 1;
final String[] items = { };
map[a][b] =
//final String[] items = {"F", "O", ". ", ". ", ". ", ". ", ". ", ". "};
//Random random = new Random();
//int index = random.nextInt(items.length);
//System.out.printf(items[index] + "\t");
System.out.print(map[1][1]);
}
System.out.printf("\n\n");
}
}
So far i have this, ignore the comments as that was my previous work. This part is where i am trying to add the objects to the array randomly, however i am having problems accessing the variables or classes in this method.
Thanks in advance for any help:)
Aucun commentaire:
Enregistrer un commentaire