游戏设计:处理不同的游戏类型? [英] Game Design: handling different game types?

查看:79
本文介绍了游戏设计:处理不同的游戏类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,是否有一个好的策略来处理游戏中运行于同一主游戏循环中的各种游戏类型?换句话说,我有一个具有三种不同游戏类型的游戏.每种类型之间只有很少的区别,因此它们当前使用相同的循环/类运行.一个是您可以在时间用完之前获得多少个X",另一个是捕获10个X需要花费多长时间",最后一个是练习/无限时间"游戏类型.现在,我的策略是对游戏的所有差异部分进行if,then,else的检查,并对每种游戏类型执行适当的逻辑.

I'm curious if there is a good strategy for handling various game types inside a game that run off the same main game loop? In other words, I have a game with three different game types. There are only a few minor differences between each type, so they currently run using the same loop/classes. One is a 'how many X's can you get before time runs out', another is 'how long does it take you to capture 10 X's', and the last is a 'practice/ infinite time' game type. Right now my strategy is to run an if, then, else check at all differentiating parts of the game and perform the appropriate logic for each game type.

if (gameType == INFINITE)
{...}
else if (gameType == TIMED)
{...}
else
{...} 

这对我来说似乎是错误的,而且效率低下.我不想让CPU陷入所有这些不必要的检查中,好像我可以一次执行该检查并继续前进.我也不想复制粘贴所有的类,只对每个类进行微小的更改.有什么好方法吗?

This seems horribly wrong to me, and also inefficient. I don't want to bog down the CPU with all these unnecessary checks when it seems like I could do this check once and proceed forward. I also do not want to copy-paste all of my classes to only make minor changes in each. Is there a good way to do this?

推荐答案

一种解决方法是创建屏幕管理器系统.这实质上意味着您拥有一个具有更新和绘制操作的抽象类.然后,您拥有的每个游戏(屏幕)都将从中继承,从而使每个游戏都有自己的更新/绘制行为.最终,您需要使用if-else或switch语句来决定绘制/更新哪个.最小化此方法的一种方法是使用抽象类型的变量来跟踪当前的屏幕",然后可以将需要更新/绘制的屏幕多态地分配给该变量.然后,当您调用更新或在当前屏幕上绘制时,您不需要知道它的具体类型.

One way to handle that is to create a screen manager system. This essentially means that you have an abstract class with update and draw operations. Each game (screen) you have then inherits from this, allowing each to have its own update/draw behavior. Ultimately you need to have an if-else or switch statement to decide which to draw/update. One way to minimize this is to keep track of the current "screen" using a variable of your abstract type, you can then polymorphically assign whichever screen needs to be update/drawn to that variable. Then when you call update or draw on the current screen you don't need to know it's concrete type.

这里有很多示例,可以在以下位置找到不错的XNA: http://xbox.create.msdn.com/zh-CN/education/catalog/sample/game_state_management

There are lots of examples out there, a decent XNA one can be found at: http://xbox.create.msdn.com/en-US/education/catalog/sample/game_state_management

这个想法是完全可以转让的.大多数人使用此系统来添加菜单屏幕和事物,但是没有理由不能将其用于您的目的.

The idea is completely transferable. Most use this system to add menu screens and things, but there is no reason it couldn't be used for your purpose.

这篇关于游戏设计:处理不同的游戏类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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