什么是安排数据结构的最佳方式 [英] Whats the best way to arrange data structures

查看:83
本文介绍了什么是安排数据结构的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑为java构建我的第一个游戏。在游戏中,我想象玩家或任何NPC可以被多态化为不同的生物类型。每种生物类型都有自己的统计数据修饰符,并且可能具有自己的一些特殊属性。我很确定我会构建类似Mobile_Object类的东西,而PC和NPC将会从该类中继承。但我不确定如何处理PC和NPC可能存在的所有子类型。为这样的事情安排数据结构的最佳方法是什么?有一个大类,其中包含所有子类型,或某种形式的子类,或者(更可能)其他我不知道的东西?

I''m thinking of building my first game for java. In the game I''m imagining it will be possible for the player or any of the NPCs to be polymorphed into a different creature type. Each creature type would have its own modifiers to stats and possibly have some sprecial properties of its own. I''m pretty sure I''ll be building something like a "Mobile_Object" class and the PC and NPC will inhertit from that class. But I''m not really sure how to handle all the possible sub-types that the PC and NPCs can be. What would be the best way to arrange the data structures for something like that? One big class that has all the sub types built into it, or some form of sub class, or (more likely) something else I''m simply not aware of?

推荐答案

你在想错误的方向。简短的回答是:使用OOP。我不想尝试理解OOP的概念是一个快速解答。只是一个暗示:后期绑定。你只需要在心里学习OOP。



-SA
You are thinking in a wrong direction. The short answer is: use OOP. I don''t want to try to understand the idea of OOP is one Quick Answer. Just a hint: late binding. You just need to learn OOP in its heart.

—SA


参见本教程 [ ^ ]。从具有所有常见属性和方法的基类开始,并为所有真实对象继承。
See this tutorial[^]. Start with a base class that has all the common properties and methods, and inherit that for all the ''real'' objects.


这篇关于什么是安排数据结构的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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