這怎麼實現的?
您可以創建架構來實現它。你的具體例子可以這樣來處理:
首先,你想要定義這些迷你遊戲或單獨批量內容的運行基礎。這個基礎將處理迷你遊戲的運行,以及跟蹤他們的狀態和與他們相關的信息,你想傳遞給後續的迷你遊戲。
其次,你想定義代表這些迷你遊戲之一的基類。本課將針對您要創建並在平臺上運行的每款新遊戲進行擴展。這個基類將處理通知變化的平臺。
最後,您想創建一些模型,用於在迷你遊戲中更改狀態變化。內置的Event
系統是解決這個問題的好方法,但是您可以在此實例中輕鬆創建自己的數據模型,並直接傳遞給平臺。
代碼示例。
平臺的基礎可能是沿着線的東西:
public class Platform
{
private var _game:MiniGame;
private var _recentGameStateData:GameStateData;
public function loadGame(game:MiniGame):void
{
if(_game != null) game.unload();
_game = game;
_game.start(this, _recentGameStateData);
}
public function update():void
{
if(_game != null) _game.update();
}
internal function manageStateChange(gameStateData:GameStateData):void
{
_recentGameStateData = gameStateData;
// Do stuff with the new game state data, like save the current score
// to use in your next game.
//
}
}
你的迷你遊戲:爲平臺
public class MiniGame
{
private var _platform:Platorm;
private var _score:int = 0;
public function start(platform:Platform, previousGameStateData:GameStateData):void
{
_platform = platform;
// Use previous GameStateData here.
//
}
public function update():void{}
public function unload():void{}
public function notifyPlatform(gameStateData:GameStateData):void
{
_platform.manageStateChange(gameStateData);
}
protected function get score():int{ return _score; }
}
你的遊戲狀態數據管理:
public class GameStateData
{
private var _game:MiniGame;
private var _score:int;
public function GameStateData(game:MiniGame, score:int)
{
_game = game;
_score = score;
}
public function get game():MiniGame{ return _game; }
public function get score():int{ return _score; }
}
然後在您自己的迷你遊戲中將這些信息發送到平臺的示例:
public class TetrisGame extends MiniGame
{
override public function unload():void
{
// Let the Platform know about the current score when this game is
// being unloaded.
var state:GameStateData = new GameStateData(this, _score);
notifyPlatform(state);
}
}
'謝謝moskito,'這會更好的評論。除了我之外,沒有人知道你的意思。 – 2013-02-28 13:45:22