设计类层次结构中的角色扮演游戏典型人物 [英] designing class hierarchy for typical characters in role playing game

查看:148
本文介绍了设计类层次结构中的角色扮演游戏典型人物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设计一个简单的角色扮演游戏,拥有典型的性格类型,如战士,巫师,牧师,盗贼,等我的一个很好的方式来设置类层次结构需要咨询。

I'm trying to design a simple role playing game which has your typical character types like fighter, wizard, cleric, thief, etc. I need advice on a good way to setup the class hierarchy.

我最初的尝试是创建一个类的类型性格,使战士,巫师,牧师,派生类型从字符

My initial attempt was to create a class of type "Character" and make the fighter, wizard, cleric, derived types from "Character".

但后来我想这可能是最好创建一个字类,然后使用Decorator模式。所以说,一个战士装饰,精灵装饰等。

But then I thought it might be better to create a "Character" class and then use the decorator pattern. So say a fighter decorator, wizard decorator, etc.

还是有不同的方式,这将是更好的?

Or is there a different way that would be better?

推荐答案

我会用战略和装饰模式的组合。您最初的建议是像一个策略模式的方法。

I would use a combination of strategy and decorator pattern. Your initial suggestion is something like a strategy pattern approach.

尝试字符类型和性格特征进行区分。字符类型会像战士,巫师,牧师,......并与战略格局,导致一些层次树设计它。

Try to distinguish between character types and character traits. Character types would be something like fighter, wizard, cleric, … and design it with a strategy pattern, which result to some hierarchy tree.

性格特点会像火的元素元素,水元素,黑色的力量,...

Character traits would be elements like fire elemental, water elemental, black force, …

例如:一个战士的性格可能会火与水元素之间做出选择是他的家乡的起源,像一个海盗(aarrrr!)或铁匠。如果你设计这个层次,那么你注定的,因为这将让你的层次树的大小爆炸。

E.g. a fighter character might choose between fire and water elemental to be his native origin, like a pirate (aarrrr!) or a blacksmith. If you design this hierarchically, then you are doomed, because this will let your hierarchy tree explode in size.

这样的性格特质应该相当与Decorator模式实现的,因为这是正交的概念对字符的概念。所以你基本上是建立一个战士的性格和绕到一个水元素修饰获得海盗(aarrrr!)。或者创建一个向导的性格和他的包裹周围黑暗魔法修饰得到一个黑暗法师。或:木箱向导的性格和包装一个水元素和黑暗魔法修饰身边得到沼泽地向导

Such character traits should be rather implemented with the decorator pattern, because it’s an orthogonal concept to the character concept. So you’ll basically create a fighter character and wrap a water elemental decorator around to get a pirate (aarrrr!). Or create a wizard character and wrap a dark magic decorator around him to get a dark mage. Or: Crate a wizard character and wrap a water elemental and a dark magic decorator around him to get a swampland wizard.

有些食物的想法:


  • 如果您决定所有的字符
    具有点石成金的能力,然后设计
    神奇的性格特征。

  • If you decide to have all character have magic abilities, then design magic as character trait.

如果必要的:组织
的装饰某种
层次结构。你可能
有一个元素(水,火,
土,风)装饰等级和
魔法类(黑,白)装饰
层次。

If necessary: Organize the decorators in some kind of hierarchical structure. You might have an "elemental" (water, fire, earth, wind) decorator hierarchy and "magic type" (black, white) decorator hierarchy.

玩得开心!

这篇关于设计类层次结构中的角色扮演游戏典型人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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