这是我的文件的结构:
1111111111111111111111111
2222222222222222222222222
3333333333333333333333333
4444444444444444444444444
5555555555555555555555555
6666666666666666666666666
7777777777777777777777777
8888888888888888888888888
9999999999999999999999999
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
0000000000000000000000000
Run Code Online (Sandbox Code Playgroud)
这是我用来将其读入数组的代码:
using (StreamReader reader = new StreamReader(mapPath))
{
string line;
for (int i = 0; i < iMapHeight; i++)
{
if ((line = reader.ReadLine()) != null)
{
for (int j = 0; j < iMapWidth; j++)
{
iMap[i, j] = line[j];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我做了一些调试,并line[j]正确迭代当前读取行中的每个字符.问题在于iMap[i, j].执行此代码块后,这是以下内容iMap:
- iMap {int[14, 25]} int[,]
[0, 0] 49 int
[0, 1] 49 …Run Code Online (Sandbox Code Playgroud) 我正在使用C#与XNA框架进行游戏.玩家是屏幕上的2D士兵,用户可以发射子弹.子弹存储在一个阵列中.我已经研究过使用列表和数组,我得出的结论是阵列对我来说好多了,因为会有很多子弹一下子被击中并被摧毁,我读到的内容列表不能处理好吧
阅读了XNA论坛上的一些帖子后,我注意到了这一点:http: //forums.xna.com/forums/p/16037/84353.aspx
我创建了一个像这样的结构:
// Bullets
struct Bullet
{
Vector2 Position;
Vector2 Velocity;
float Rotation;
Rectangle BoundingRect;
bool Active;
}
Run Code Online (Sandbox Code Playgroud)
我做了这样的数组:
Bullet[] bulletCollection = new Bullet[100];
Run Code Online (Sandbox Code Playgroud)
但是当我尝试做这样的代码时:
// Fire bullet
if (mouseState.LeftButton == ButtonState.Pressed)
{
for (int i = 0; i < bulletCollection.Length; i++)
{
if (!bulletCollection[i].Active)
{
// something
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
'Zombie_Apocalypse.Game1.Bullet.Active'由于其防护等级而无法访问
任何人都可以伸出援手吗?我不知道为什么会出现这个错误,或者即使我正确地声明数组或其他任何东西......因为XNA论坛上的帖子没有详细说明.
感谢您提供任何帮助.:)