It depends where your Survivor is being held. Your Zombie will need a reference to a Survivor from somewhere - what does it need it for? Who should be responsible for providing this?
It sounds like your Gui
is doing too much actually, I'd prefer to have a class called something like GameState
that manages the positions and then just have the Gui handle the output. In any case, if there's a single survivor you can simply have a getSurvivor()
method on your Gui/Gamestate - and the Zombie should probably have a reference to the current game state that it's part of. Alternatively you could make the GameState a singleton, and the Zombies could access it that way.
Edit: In response to your comment, perhaps something like this:
public class Zombie
{
private final Gui guiThatMadeMe;
public Zombie(Gui owner)
{
guiThatMadeMe = owner;
}
....
public void move()
{
Survivor guy = guiThatMadeMe.getSurvivor();
// Do whatever you need to with the survivor
}
}
public class Gui
{
private Survivor lonelyGuy;
...
public Survivor getSurvivor()
{
return lonelyGuy;
}
public void createNewGame() // I'm guessing you have some method like this
{
lonelyGuy = new Survivor();
for (int i = 0; i < NUM_ZOMBIES; i++)
{
Zombie zombie = new Zombie(this); // pass in this reference
// Do something with the zombie
}
// other setup
}
}
In any case, the Zombie will have to obtain a reference to something that knows how to get the survivor. An alternative option would be to have the Survivor passed directly into the Zombie, but that doesn't feel quite as clean somehow. It might be a viable option if Zombies must always have one and exactly one Survivor, but that feels like an artificial limitation.