PDA

View Full Version : [AS2] Increasing random number generated by pressing space or any other button


maplealvon
06-24-2009, 10:03 AM
I'm a newbie at using actionscript and I'm trying to make a game where the player has to press the space bar repeatedly to win against the pc.
My idea is to have to random numbers, one belonging to the player and the other belonging to the computer.
If the player's random number is larger compared to the computer's the player wins and moves on; if the computer's random number is smaller or equal to the player's, the player loses and the game ends.
So how do I make the script so that the by repeatedly pressing the space button, the player can increase his/her chance of getting a higher random number and thus winning.

lemoncurds
07-12-2009, 12:04 AM
Try using this randRange function. It returns a random number between the two specified numbers. You could have a variable that stores the max number, and every time you press space it goes up. That way you have more chance of getting a higher number.


function randRange(min:Number,max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max - min + 1))+min;
return randomNum;
}