方法1:
不需要調用的內線球員,但是從外面getAvailableMoves和您可以在getAvailableMoves通過播放器作爲一個參數:
class GameWorld {
main(){
GameLogic gl = new GameLogic();
AIPlayer player = new AIPlayer();
player.move(gl.getAvailableMoves(player));
}
}
GameLogic類
class GameLogic {
public object getAvailableMoves(Player player){
player.getX();
player.getY();
return availableMoves;
}
}
Player類
class Player{
float x;
float y;
}
AIPlayer類
class AIPlayer extends Player {
void move(){
}
}
方法2:
也是另一種方法是使getAvailableMoves靜態和內線球員類調用它。
AIPlayer類
class AIPlayer extends Player {
void move(){
GameLogic.getAvailableMoves(this);
}
}
GameLogic類
class GameLogic {
public static object getAvailableMoves(Player player){
player.getX();
player.getY();
return availableMoves;
}
}
您將需要一個服務類。 – SynchroDynamic