I am making a maze game in Java, where you have to escape the maze without being caught by the randomly-moving AI.
The code I am using to decide which direction the enemy moves in causes the character to change direction way too fast. It currently chooses a random number, which corresponds to the direction in which the AI moves.
How can I edit this method so it only chooses a random number every 3 seconds?
if(new Random().nextInt(4) == 0){
xMove = speed;
}
if(new Random().nextInt(4) == 1){
xMove = -speed;
}
if(new Random().nextInt(4) == 2){
yMove = speed;
}
if(new Random().nextInt(4) == 3){
yMove = -speed;
}