我是多维数组的新手,只是想确保在今天晚些时候开始针对它进行编码之前,我对搜索有正确的想法。
public int[,] LocationXY = new int[5,5];
编辑数组搜索多维数组:
用于搜索 5 x 5 的多维数组的伪代码会是这样的吗?
移动地图的 XNA 代码:
background.direction.X = background.position.X + 3000;
background.direction.Normalize();
background.position.X += background.direction.X *
ball.speed;
backgroundWest.direction.X = backgroundWest.position.X + 3000;
backgroundWest.direction.Normalize();
backgroundWest.position.X += background.direction.X * ball.speed;
Map.ArraySearch(XSearch, YSearch);
//if statement for changing background sprite.
if(LocationXY[0,1])
background01.LoadContent(this.content, "background01";
搜索功能:
public int [,] ArraySearch(XSearch, YSearch)
{
for(int X = 0; X < XSearch; X++)
for(int Y = 0; Y < YSearch; Y++)
if(Y == YSearch && X == XSearch)
return LocationXY[XSearch, YSearch]
}
一般的想法是为背景所在的 if 语句获取数组值。我希望 switch 语句可以采用多维数组。