This discussion is archived
11 Replies Latest reply: Jun 1, 2010 9:48 PM by DarrylBurke RSS

Help! Class, interface, or enum expected, don't know where the error is

843789 Newbie
Currently Being Moderated
hey all, I am doing a project for school but I keep getting a compiler error and I don't know why. Here is the code that keeps getting the error:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Green Survivor
*
* @author
* @version
*/
public class Green extends Survivor
{

/**
* Constructor that simply calls Survivor's no-argument constructor.
*/
public Green()
{
super();
}

/**
* Does whatever a Survivor does
*/
public void act()
{
getNextMove();
updateLife();
}


/**
* Update a Survivor's life based on its neighbors.
*/
public void updateLife()
{
//Get a list of all neighbors that are in a square directly next
//to us that are of type Survivor. Traverse the list. For every
//neighbor of type Green, add one to life. For any other Survivor,
//subtract two from life.
ArrayList<Object> update = new ArrayList<Object>();
update.add(getOneObjectAtOffset(1, 0, Survivor.class));
update.add(getOneObjectAtOffset(-1, 0, Survivor.class));
update.add(getOneObjectAtOffset(1, 1, Survivor.class));
update.add(getOneObjectAtOffset(0, 1, Survivor.class));
update.add(getOneObjectAtOffset(0, -1, Survivor.class));
update.add(getOneObjectAtOffset(-1, -1, Survivor.class));
update.add(getOneObjectAtOffset(1, -1, Survivor.class));
update.add(getOneObjectAtOffset(-1, 1, Survivor.class));

for(int i = 0; i < update.size(); i++)
{

if(update.get(i) == Green.class)
{
changeLife(1);
}
else
{
changeLife(-2);
}


}

//If green is outnumbered by blue by more than 500, subtract 5 from life.
if(green + 500 < blue)
{
changeLife(-5);
}
//If green is outnumbered by red by more than 500, subtract 5 from life.
if(green + 500 < red)
{
changeLife(-5);
}
}
/**
* Put a new object of type Green into the world at coordinates x and y.
* Then increment green's static counter accordingly.
*/
public void createNew(int x, int y)
{
int one = x;
int two = y;
new Green();
setLocation(one, two);
green = green + 1;
}

/**
* Green pieces should just choose an available move at random. If there
* are no available moves, return -1.
*/
public int getNextMove()
{
if(canMove(1) || canMove(2) || canMove(3) || canMove(0))
{
int counter = (int) (Math.random() * 4);
if(canMove(counter))
{
move(counter);
}
else
{
counter = (int) (Math.random() * 4);
if(canMove(counter))
{
move(counter);
}
else
{
counter = (int) (Math.random() * 4);
if(canMove(counter))
{
move(counter);
}
else
{
counter = (int) (Math.random() * 4);
if(canMove(counter))
{
move(counter);
}
}
}
}


}
else
{
return -1;
}


}
}
}

}

It is the subclass of a class that has all the methods used here (it wouldn't allow me to add that too as it said it was too many characters, I will post it if need be)
Thanks in advance!