I'm making a candy crush kinda game. I need to draw different colors of gems on the board randomly.
class Gem
{
public:
int x; int y;
Gem(){x = 0 ; y = 0;}
void make(int x , int y, int color)
{
DrawRoundRect(x, y, 50 , 50 , colors[color], 10);
}
};
Gem gem;
for(int i = 195 ; i <= 795 ; i = i+100)
{
for(int j = 70 ; j <= 5000 ; j = j+100)
{
int col = Randomise(0,4);
gem.make(i,j,col);
}
}
All the gems drawn are of the same color. Also, this function gives a different random number on every redraw. Due to which the color of all the gems keeps changing with the movement of the mouse (The mouse and keyboard accelerate redraw of the screen). I have to move the gems downwards and yet want the color of that specific gem to remain the same throughout the game. How can I resolve it?
The definition of Randomise( )
is:
int Randomise(int min, int max)
{
srand((unsigned) time(0));
long random;
for (long i = min; i < 5; i++)
{
random = (rand() % max) + 1;
return random;
}
}