I am making a maze game in javaJava, where you have to escape the maze without being caught by the random moving airandomly-moving AI.
The code iI am using to decide which direction the enemy moves is shown below but thisin causes the character to change direction way too fast. It currently chooses a random number and depending on, which number it chooses corresponds to whichthe direction in which the aiAI moves.
How can iI 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; }
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;
}