AS3面向对象的游戏结构(级架构) [英] As3 OOP game structure (class architecture)

查看:211
本文介绍了AS3面向对象的游戏结构(级架构)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

游戏介绍: 测验与不同层次,不同类型的视觉问题,每个级别。
OOP至今:游戏键盘(其中一个回答问题),对话,高分,控制器/ LevelController

Game description: A quiz with different levels and different types of visual questions for each level.
OOP so far: GameBoard (where one answers questions), Dialog, HighScore, Controller/LevelController?

我有一个文件类叫做控制器,它初始化游戏:

I have a document class called Controller which initializes the game:

public function Controller() 
{
    initGame();
}    

function initGame() 
{
    xmlGameData = levels, questions xml
    highscore:HighScore = new HighScore();
    startGame();
}

function startGame() 
{
    levelController = new LevelController( this, xmlGameData );
}

然后我开始围绕一个引用传递到文档类/主时间轴来我这本身扩展了影片剪辑或雪碧不同的对象。

Then I'm starting to pass around a reference to the "Document class / main timeline" to my different object which in themselves extends MovieClip or Sprite.

public function LevelController(docClass, xml)
{
   mainTimeLine = docClass;
   xmlGameData = xml;

   loadGameBoard(); 
   nextLevel();
} 

function loadGameBoard()
{
   gameBoard = new GameBoard(mainTimeLine, this);
   mainTimeLine.addChild(gameBoard);
}

这得到pretty的凌乱过了一段时间,我想知道,从控制对象的不同(如游戏键盘和高分)和国家(级)和行动(AnswerQuestion,NextQuestion等)更好的方法,也许,一个单一的控制点。

This gets pretty messy after some time and I'd like to know better ways of controlling the different objects (like GameBoard and HighScore) and states (Levels) and actions (AnswerQuestion, NextQuestion etc.) from, maybe, a single point of control.

推荐答案

火鸦有正确的想法。什么,你想要做的是,分离出在你的游戏从游戏本身的变化。所以,你的控制器对象将包含一个适用于所有级别,如得分,显示精灵,界面信息和水平的一个参考目前的水平数组的游戏功能。您的游戏包括一系列的水平,所以他们自然应该由级别对象psented重新$ P $。每个级别都知道如何绘制自己和处理来自玩家的投入。该级别的对象可以通知控制器,当它是完整的,然后所述控制器可以显示阵列中的下一级。

Fire Crow has the right idea. What you want to do is to separate what changes in your game from the game itself. So your Controller object will contain game functionality that applies to all levels, such as the score, the display sprite, GUI info, and an array of levels with a reference to the current level. Your game consists of a series of levels, so they should naturally be represented by Level objects. Each level knows how to draw itself and handle inputs from the player. The level object can inform the Controller when it is complete, and the Controller can then display the next level in the array.

这篇关于AS3面向对象的游戏结构(级架构)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆