I need help with fixing my ai. At the moment, the ai works even if the playerRedControlled boolean is false. I don't know what is wrong. If there is an error, it is a logic error as there is no syntax or runtime error showing up.
boolean playerRedControlled = false;
// int w = Greenfoot.getRandomNumber(3);
/**
* Act - do whatever the Red wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeypress(); // This statement calls the checkKeyPress method.
}
public void checkKeypress() // This method controls the movement of the Red player.
{
Actor pongball = getWorld().getObjects(PongBall.class).get(0);
Paddles paddles = new Paddles();
if(pongball.getX() > 615)
{
if(getY() > pongball.getY())
{
if(Greenfoot.getRandomNumber(5) != 0)
{
setLocation(getX(),getY() - 10);
}
else if(Greenfoot.getRandomNumber(5) == 0)
{
setLocation(getX(),getY() - 5);
}
}
else if(getY() < pongball.getY())
{
if(Greenfoot.getRandomNumber(5) != 0)
{
setLocation(getX(),getY() + 10);
}
else if(Greenfoot.getRandomNumber(5) == 0)
{
setLocation(getX(),getY() + 5);
}
}
if(playerRedControlled = true)
{
if (Greenfoot.isKeyDown("up")) // Pressing the up arrow key will move the red paddle up.
{
setLocation(getX(),getY() - 10);
}
if (Greenfoot.isKeyDown("down")) // Pressing the down arrow key will move the red paddle down.
{
setLocation(getX(),getY() + 10);
}
}
else if(playerRedControlled = false)
{
paddles.act();
}
BorderCheck();
}
}

