在 VB.net 中为网格创建变量
我需要将元素存储在多维数组中。具体来说,我需要将“图块”保存到网格中(例如 x:2 y:5 处的草、x:3 y:5 处的泥土等)。使用多维感觉非常混乱并且非常出问题(必须调整我的数组的大小,并且必须创建新的数组,如果它们不存在)。有没有为此制作某种元素?我可以说 obj.getPos(2,5) 并获取我的草元素并使用 obj.setPos(DirtObj, 3, 5) 将其设置为我的泥土元素?
我只是想知道 vb.net 中是否有比多维数组更容易使用的东西,仅此而已。谢谢!
I need to store elements in a multidimensional array. Specifically, I need to save "tiles" to a grid (e.g. Grass at x:2 y:5, Dirt at x:3 y:5, etc.). Using a multidimensional feels very hacked up and is very glitchy (having to resize my arrays and having to create new ones were they are non-existant). Is there some kind of element made for this? Something I can say obj.getPos(2,5) and get my Grass Element and use obj.setPos(DirtObj, 3, 5) to set it to my Dirt Element?
I'm just wondering if there is something easier to use than multidimensional arrays in vb.net, that is all. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
选项 1 - 类
如果您要添加、删除和插入对象,我会使用列表列表,因为这将使您可以直接访问给定坐标处的对象( X、Y),让您直接设置对象,而无需重新调整它们的大小。
例如,您可以有一个
Tile
类并使用如下所示的列表:Option 2 - Enum
如果您使用对象的全部目的只是它们的值,您甚至不需要创建
Tile
类,而只需创建一个TileTypes
枚举,其中包含一些值,例如 < code>Dirt、Grass
等并设置它们:您应该能够在此基础上进行构建并从那里获取它。
Option 1 - Class
If you're going to be adding, removing and inserting objects, I would use a List of Lists since this will give you direct access to the object at a given coordinate (X, Y) and let you set the object directly without having to re-size them.
For example, you could have a
Tile
class and use the Lists like this:Option 2 - Enum
If all you're using the objects for is their value you don't even need to create a
Tile
class instead you could just create aTileTypes
enum with some values likeDirt
,Grass
, etc and set them:You should be able to build upon this and take it from there.