游戏描述:具有不同级别和每个级别的不同类型的视觉问题的测验。
到目前为止: GameBoard (回答问题的地方),对话框,HighScore,控制器/级别控制器?
我有一个名为Controller的文档类,它初始化游戏:
public function Controller()
{
initGame();
}
function initGame()
{
xmlGameData = levels, questions xml
highscore:HighScore = new HighScore();
startGame();
}
function startGame()
{
levelController = new LevelController( this, xmlGameData );
}然后,我开始将对“文档类/主时间线”的引用传递给我的不同对象,该对象本身扩展了MovieClip或Sprite。
public function LevelController(docClass, xml)
{
mainTimeLine = docClass;
xmlGameData = xml;
loadGameBoard();
nextLevel();
}
function loadGameBoard()
{
gameBoard = new GameBoard(mainTimeLine, this);
mainTimeLine.addChild(gameBoard);
}一段时间后,这会变得相当混乱,我想知道更好的方法来控制不同的对象(如GameBoard和HighScore)、状态(级别)和动作(AnswerQuestion、NextQuestion等)。也许是从一个单一的控制点。
发布于 2009-10-01 16:15:16
Fire Crow的想法是正确的。您要做的是将游戏中的更改与游戏本身分开。因此,您的Controller对象将包含应用于所有级别的游戏功能,例如分数、显示子画面、GUI信息和引用当前级别的级别数组。您的游戏由一系列关卡组成,因此它们自然应该由关卡对象表示。每一关都知道如何绘制自己和处理来自玩家的输入。level对象可以在完成时通知Controller,然后Controller可以显示数组中的下一级。
发布于 2009-09-28 18:43:15
为了控制游戏的“UI”和“支持”功能(屏幕流、分数提交、关卡),我在一个主游戏控制器类中放置了一系列静态函数,这个类处理显示/隐藏游戏屏幕的所有逻辑,在levelData数组中推进迭代器,并从一个中心位置处理所有服务器端提交的内容。
它基本上是一个包含一系列静态函数的类,例如:
public static function LoadUserData() {}
public static function SaveUserData() {}
public static function PlayNextLevel() {}
public static function SubmitScore() {}
public static function ShowLevelPlayScreen() {}
public static function ShowLevelPauseScreen() {}
public static function ShowGameOverScreen() {}等等。
只会有一个这样的控制器,所以封装在静态函数中会起到作用,使其易于从代码中的任何位置进行访问,并且在语法上比将其放入Singleton中更容易调用。
发布于 2009-09-28 18:37:19
嗯..。我假设你的问题是“什么是比我这里的更好的管理游戏的结构”,尽管这并没有明确说明这是我试图回答的。
我不认为多态性对于你所做的事情是最好的解决方案。OOP不仅仅是一系列的对象。它将功能分组为有用的对象。
我建议将更多的功能转移到控制器中
1.) a main object with all the following functionality that will be present
throuhout the game
a.) go to level (next/previous)
b.) keep track of score
c.) controll the state of the game
d.) anything else that exists throughout the game
2.) level objects that handle level specific information
a.) interactivity of the questions such as buttons etc.
b.) managing the correct answer and the impact it has on the score in mainhttps://stackoverflow.com/questions/1486032
复制相似问题