English 中文(简体)
2. 获得一类财产的途径有两种:
原标题:Accessing a class s properties two ways

我 st忙于建立一个阶级结构,以便做到这一点:

I have very many (About 78) types of block. The level for the game is made of these blocks. In the level s ByteArray, there are simply numbers, denoting the type of block. So for collision handling, I can just retrieve the number at the wanted position and get that block s properties. (Solid, selectable, visible, texture). BUT. I ll be reordering this list of blocks, and so, also need a way to access a block s properties by name.

因此,我希望能够通过一块块块获得财产。

封块[5]。 财产

以及

区块.Rock.Properties

我知道这些是NOT的事例,我不得不立即向他们介绍他们的财产。

最佳回答

如果你想要打区[5]。 财产和区块。 Rock.Properties, 区块必须是一个有指数的习俗级。 设置类似于一项行动:

public Block this[] (int index) 
{
   //getter logic here
}

索引员可以采用整体类型或体力,因此,您可使用区块以钥匙包装字典和接入值:Blocks[“Rock”]。 财产。 这确实涉及“魔法”,如果你听错的话,汇编者将无法追捕。

点名牌照是简单的读物:

public Block Rock { get{//getter logic here} }

如果是我的申请,我将设立一个单一州区级。 这些区块是贯穿整个一生的游戏的组成部分,你不想明确立即进行;单一州情景的定义(比一切静态情况更容易改变)。 该区级将包藏一批区块物体,然后将执行工作隐藏在区块入口处。 您可以通过使用Linq(我假设一个区块的特性包括区块及其名称)使用清单和进行搜查,或选择一个区块的索引或名称作为区块的选用地的关键。

问题回答

由于不同的阻塞类型是杂乱,你可以使用地图/字典/联系阵列。

Dictionary<string, int> BlockTypes = new Dictionary<string, int>();
BlockTypes["Rock"] = 1337;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...