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

2014/6/3

Placing Objects

ethan.poole ethan.poole

2014/6/3

#
When I have a random number generated, how do I get a class to appear in a location related to the number generated?? For instance a bingo grid, I generate a number 5, how do I make my counter subclass place in the correct location on the grid??
riowmp riowmp

2014/6/3

#
Sorry can't help :(. I'm stuck on the same thing.
TheLimit TheLimit

2014/6/3

#
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
danpost danpost

2014/6/5

#
You will have three sets of information: (1) the top-left location coordinates for where counter zero will go (counting in java starts at zero) (2) the number of rows across and columns down that make up the total area where the counters are placed (3) the horizontal gap between each counter location across and vertical gap between each counter down Giving these data fields names: (1) topLeftX and topLeftY (2) rows and cols (3) hGap and vGap. Since, rows times columns is the total number of possible counters, each location can be arrived at by
int rand = Greenfoot.getRandomNumber(rows*cols);
int x = topLeftX+hGap*(rand%cols);
int y = topLeftY+vGap*(rand/cols);
You need to login to post a reply.