This site requires JavaScript, please enable it in your browser!
Greenfoot back
CrazyCarl992
CrazyCarl992 wrote ...

2012/11/8

Arrays

CrazyCarl992 CrazyCarl992

2012/11/8

#
I am writing a castle defense game. In the game objects can be places on a 12 x 12 grid. Defensive objects are placed vertically and offensive objects are placed facing horizontally. I need to use a two dimensional array to keep track of where there are objects at any given time. Any ideas?
SPower SPower

2012/11/8

#
So you don't know how to create a 2 dimension array? Well, I suppose you understand a normal array, and this is a 2 dimensional array:
Class[][] name;
// 2 times the '[]'
and to set an object, do this:
name[anindex1][anindex2] = something;
I think you can even do this:
name[someindex] = someonedimensionalarray;
You need to login to post a reply.