2

所以我目前正在使用一个名为 GameFile 的静态类,它包含游戏实例、当前地图、玩家位置、玩家姓名、玩家金钱等。基本上所有的全球信息。我想知道是否有替代方法?

这就是我当前在静态类中设置游戏实例的方式(例如):

GameFile.gameInstance = new ChromeGame();

然后当我需要使用我调用的信息时

GameFile.gameInstance.addScreen(SplashScreen).
4

1 回答 1

1

这就是我为手机游戏做的方式。您可以完全拥有 OOP 概念并拥有所有 setter/getter,但在低类型移动设备中,这种“OOP”成本很高。

public class GameData {

    public static Model activePlayerModel;
    public static GameMap currentMap;

    public static void load () {
        // read necessary data from external sources. e.g. a file
    }

    public static void updateMap () {
        // update currentMap
    }

    public static Model getActiveModel() {
        // get current model/set default/or read from file and return
    }

    public static GameMap getCurrentMap() {
        // e.g. Create a map or read map from a file, etc
        // return the map
    }

}

现在我可以直接访问 GameData 的成员了。

public class GameScreen extends Screen {

    Model playerModel;

    public GameScreen (Game game) {
        GameData.load();
        playerModel = Settings.activePlayerModel;   
    }

}
于 2013-08-21T00:21:00.373 回答