Pass the weapons to the player before starting the game. So it is not the player object that knows which weapons it has, but the game (or the game mode) that knows the weapons.
There are many ways to do so, but as an example:
public abstract class Mode {
public abstract Collection<Weapon> getHumanWeapons();
public abstract CollectionWeapon> getBotWeapons();
}
public class Easy extends Mode{
public Collection<Weapon> getHumanWeapons() {
return Collections.singleton(new NukeBlaster()));
}
public Collection<Weapon> getBotWeapons() {
return Collections.singleton(new Flower()));
}
}
public HumanPlayer(Mode mode) {
this.weapons = mode.getHumanWeapons();
}
public BotPlayer(Mode mode) {
this.weapons = mode.getBotWeapons();
}
Or... have Mode
return a HumanConfiguration
and a BotConfiguration
which in turn supply weapons and behaviour. That would give the Player
class a single constructor and make sure bots do not secretly steal human weapons.
public abstract class Mode {
public abstract Configuraton getHumanConfiguration();
public abstract Configuraton getBotConfiguration();
}
public class Configuration {
public Collection<Weapon> getWeapons() { ... }
}
public class Player {
private Collection<Weapon> weapons;
public Player(Configuration configuration) {
this.weapons = configuration.getWeapons();
}
}