我创建了一个结构体列表,每个结构体都有几个属性。我的意图是使用一个基本的10x10地图来练习/学习为我正在开发的工具编写的A *搜索算法。我已经得到了地图的结构基本上瓷砖对象的数组,每个具有以下属性:为地图查看器添加多个复选框
public struct Tile
{
public int x { get; set; }
public int y { get; set; }
public int cost { get; set; }
public bool walkable { get; set; }
}
我也有一个节点结构,虽然这是不相干的这个问题,说真的,我会张贴柜面任何人有任何事情我喊的:
public struct Node
{
public int x { get; set; }
public int y { get; set; }
public int total { get; set; }
public int cost { get; set; }
public Tile parent { get; set; }
}
我formload事件看起来是这样的:
private void Form1_Load(object sender, EventArgs e)
{
CheckBox[] chbs = new CheckBox[100];
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
Map = new Structs.Tile[100];
Map[x + y].x = x;
Map[x + y].y = y;
Map[x + y].cost = 100;
Map[x + y].walkable = true;
//MessageBox.Show(Convert.ToString(Map[x + y].x) + " : " + Convert.ToString(Map[x + y].y));
if (x == 5)
{
if (y == 4 | y == 5 | y == 6)
{
Map[x + y].walkable = false;
}
}
}
}
int i = 0;
foreach (Structs.Tile tile in Map)
{
CheckBox chb = new CheckBox();
chb.Location = new Point(tile.x * 20, tile.y * 20);
chb.Text = "";
chbs[i] = chb;
i++;
}
this.Controls.AddRange(chbs);
}
而且我的手之前已经声明这一点,在全球范围内使用日粗糙这一类:
Structs.Tile[] Map;
问题是,为什么这只添加2个复选框?它似乎将它们添加到位于X:0,Y:0,X:1,Y:1的位置的正确位置,但是没有添加其他位置?我已经把这个表格扩大到了荒谬的尺寸,但仍然没有任何结果我完全被它困惑了。
下面是结果,每次用乘数设置为2:
我相信我已经正确设置它,我不能工作了,为什么它不工作。我可以理解,如果表单冻结但它不是,并且将值设置为某种愚蠢的高(100+)没有任何区别。 WinForms中的偏移量表示乘数需要大约为12 ...
像往常一样,任何建议都非常值得欢迎。我也会尽快回答一些问题,因为我从你那里学到了很多美妙的人!
谢谢!
修改稿FormLoad:
private void Form1_Load(object sender, EventArgs e)
{
int ind = 0;
CheckBox[] chbs = new CheckBox[100];
Map = new Structs.Tile[100];
for (int x = 1; x < 11; x++)
{
for (int y = 1; y < 11; y++)
{
Map[ind].x = x;
Map[ind].y = y;
Map[ind].cost = 100;
Map[ind].walkable = true;
//MessageBox.Show(Convert.ToString(Map[x + y].x) + " : " + Convert.ToString(Map[x + y].y));
if (x == 5)
{
if (y == 4 | y == 5 | y == 6)
{
Map[ind].walkable = false;
}
}
ind++;
}
}
int i = 0;
foreach (Structs.Tile tile in Map)
{
CheckBox chb = new CheckBox();
chb.Location = new Point(tile.x * 12, tile.y * 12);
chb.Text = "";
chbs[i] = chb;
i++;
}
this.Controls.AddRange(chbs);
}
我试过一些新的东西,在while循环中添加一个索引来设置X和Y,它似乎没有帮助,我现在编辑它。 – XtrmJosh 2013-02-14 21:55:47