I want to make it to be controlled by the computer and chace in order to kill the other opponent(blue) which is controlled by the player with the arrows.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; public class PlayerPink extends Actor { private GreenfootImage pink = new GreenfootImage("PinkPlayer.jpg"); int lastMovement = Greenfoot.getRandomNumber(4); int newMovement = lastMovement; public void act() { moveTron(); die(); leaveTrail(getX(), getY()); } /** This method allows the player to interact with the actor. * It detects when and which button is pressed * The actor will move in the direction accordingly. * This is done by connecting the button keys with a command * "last pressed", which allows it to repeate infinitely. */ public void moveTron() { int z = 3; int decideToTurn =Greenfoot.getRandomNumber(100); if (decideToTurn<5) { newMovement = Greenfoot.getRandomNumber(4); if ((java.lang.StrictMath.abs(newMovement-lastMovement)!=1) || (newMovement*lastMovement==2)) { lastMovement=newMovement; } } switch (lastMovement) { case 0: setLocation(getX() - z, getY()); break; case 1: setLocation(getX() + z, getY()); break; case 2: setLocation(getX(), getY() - z); break; case 3: setLocation(getX(), getY() + z); break; default: break; } } /** This method checks whether or not pink has collided. * If it is true, then the scenario will stop. */ public void die() { TronWorld a=(TronWorld) getWorld(); if (getOneObjectAtOffset(0,0,null)!=null) { a.stopTheGame("BLUE"); getWorld().addObject(new GameOverText("PINK"), 400, 300); } } /** This method requests for the world to add a static actor that is a replica of this one wherever it goes. */ public void leaveTrail(int x, int y) { getWorld().addObject(new TrailPink(), x, y); } }