i have to design a simple game.
I asked some question before in this forum.
Now the game version is the new version with more items in it.
now, i have a 11 items to draw, '$'.
and i have a function in a header file called utils.h, GetRandom() function.
code:
-
inline unsigned GetRandom(unsigned min, unsigned max) {
-
return rand() % (max - min + 1) + min;
-
}
-
i have to draw that 11 items(which is the same character '$' ) randomly to the screen(specified width and height, which is 25wdth, 11 in height) using that function above.
What my examiner said :
Quote:
suppose you have decided to have 11 powerups. Where are you
going to put them? So you'll neeed to use GetRandom at least 22 times to
get random x and y positions. The min and max will depend on the size of
the screen that you'll have.
I have no idea what it means by min & max argument in GetRandom() function will depend on the size of the screen.
So, what should i put in for the min & max argument? 11 and 25 (the height and width) ?
Please could someone show the example ? because i can't figure it out.
What i have tried (which is failed ) :
-
unsigned xPos;
-
unsigned yPos;
-
-
for(unsigned i = 0; i <= max; i++) {
-
xPos = GetRandom(1, 275);
-
yPos = GetRandom(1, 275);
-
screen->Insert(xPos, yPos, '$'); // draw 11 of $ into screen
-
}
-