I'm getting back into programming in greenfoot after about a year long hiatus and I've realized I've forgotten all the simple stuff I used to know. If somebody could help me out and jog my memory when it comes to creating a random number. I'm making a little bop it style game just for fun and I'm using a random number to determine which command the player will have to do. For example, I've got three buttons and each option is assigned a number (0, 1, or 2) and I just need the random number generator to choose a random number between 0 and 2 everytime the appropriate button is clicked and then choose another number and so on and so forth.
This is what I've attempted so far but obviously this isn't working. This is inside an if statement inside the act method. Thanks for the help in advance.
1 2 3 4 5 6 7 8 9 10 | getRandomNumber( 2 ); if (getRandomNumber == 0 ) { addObject( new OpYellow(), 280 , 65 ); } if (getRandomNumber == 1 ) { addObject( new OpRed(), 280 , 65 ); } if (getRandomNumber == 2 ) { addObject( new OpBlue(), 280 , 65 ); } |