Я пытаюсь использовать метод getFreeAdjacentLocation из класса Field, но я получаю сообщение об ошибке из класса CleverSheep, указав, что он не может найти метод-символ getFreeAdjacentLocation (Location) 'Как вызвать метод List в другом классе
у меня есть класс Field
public class Field
{
// some fields
// constructor
// other methods
public List<Location> getFreeAdjacentLocations(Location location)
{
validLocation(location);
List<Location> free = new LinkedList<Location>();
List<Location> adjacent = adjacentLocations(location);
for(Location next : adjacent) {
if(getObjectAt(next) == null) {
free.add(next);
}
}
return free;
}
у меня есть умный класс SHEEP
public class CleverSheep
{
// constructor
public CleverSheep(Field field, Location location, int n)
{
super(field, location);
}
public void act()
{
if (isAlive()) {
Location newLocation = getField().freeAdjacentLocation(getLocation());
Location freeLocation = getField().getFreeAdjacentLocation(getLocation());
if(newLocation != null) {
moveToLocation(newLocation);
}
// If Wolf is in this location
else if (newLocation == null) {
moveToLocation(freeLocation);
}
}
}
}
где is getField()? –
Это 'getFreeAdjacentLocations' не' getFreeAdjacentLocation'. См. _s_? – GriffeyDog
@LawrenceAiello getField() из другого класса Animal (абстрактный класс) – tb1000