I''m doing a game in Java that''s kinda like a multiplayer breakout. It''s done and now I''m just adding some neat little features like powerups for breaking various bricks. I would like the bricks themselves to decide whether or not they contain these power ups so I have imported java.util.* and have created a random number generator (creatively called "random") within the class. Kinda looks like this:
//block class
class Block extends Object
{
private int type;
private Random random = new Random();
public Block()
{
width = 80;
height = 25;
posX = 400;
posY = 300;
type = random.nextInt(2);
if(type == 1)
immortal = true;
}
Obviously there''s more to the class than that, but that''s really just the relavent part. Now, what this says to me is that every time a ball is created, it''s constructor sets its width, height, position, and rolls up a random number (in this case 0 or 1, small just for testing purposes) and if the number is 1 then it makes the block immortal (can''t be destroyed, in other words). The blocks are all part of an array that is initialized as such:
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 3; j++)
{
blockArray[arrayCount] = new Block();
blockArray[arrayCount].setPos(i*80, j*25);
arrayCount++;
}
}
So.....each element should be created individually and since random is seeded based on time, each block should have a different value for type, right? Wrong. Either all of the blocks are normal or all are immortal. Is it the way the array is set up? Or perhaps java constructors work differently than C++ (my native language)? Or some other weird thing I don''t know about?Any and all help is appreciated.
Thanks,
Mike
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...
Without order nothing can exist - without chaos nothing can evolve.