As3 OOP游戏结构(类架构) [英] As3 OOP game structure (class architecture)

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

问题描述

游戏说明:每个级别都有不同级别和不同类型的视觉问题的测验.
到目前为止的 OOP:GameBoard(在那里回答问题)、Dialog、HighScore、Controller/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?

我有一个名为 Controller 的文档类,用于初始化游戏:

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 );
}

然后我开始将文档类/主时间线"的引用传递给我的不同对象,这些对象本身扩展了 MovieClip 或 Sprite.

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);
}

一段时间后这会变得非常混乱,我想知道从单个对象控制不同对象(例如 GameBoard 和 HighScore)和状态(级别)和动作(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.

推荐答案

Fire Crow 的想法是正确的.您要做的是将游戏中的更改与游戏本身分开.因此,您的 Controller 对象将包含适用于所有级别的游戏功能,例如分数、显示精灵、GUI 信息以及引用当前级别的一组级别.您的游戏由一系列关卡组成,因此它们自然应该由 Level 对象表示.每个级别都知道如何绘制自己并处理来自玩家的输入.level 对象可以在完成时通知 Controller,然后 Controller 可以显示数组中的下一个级别.

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 OOP游戏结构(类架构)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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