private void btnSearch_Click(object sender, EventArgs e)
{
for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++)
{
m_resultLine[resultTrav].Dispose();
}
m_resultLine.Clear();
for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++)
{
m_resultBox[resultTrav].Dispose();
}
m_resultBox.Clear();
GridPos startPos = new GridPos();
GridPos endPos = new GridPos();
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if (m_rectangles[widthTrav][heightTrav].boxType != BoxType.Wall)
{
searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), true);
}
else
{
searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), false);
}
if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.Start)
{
startPos.x = widthTrav;
startPos.y = heightTrav;
}
if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.End)
{
endPos.x = widthTrav;
endPos.y = heightTrav;
}
}
}
jumpParam.CrossCorner = cbCrossCorners.Checked;
jumpParam.CrossAdjacentPoint = cbCrossAdjacentPoint.Checked;
jumpParam.UseRecursive = cbUseRecursive.Checked;
jumpParam.Reset(startPos, endPos);
List <GridPos> resultList = JumpPointFinder.FindPath(jumpParam);
for (int resultTrav = 0; resultTrav < resultList.Count - 1; resultTrav++)
{
m_resultLine.Add(new GridLine(m_rectangles[resultList[resultTrav].x][resultList[resultTrav].y], m_rectangles[resultList[resultTrav + 1].x][resultList[resultTrav + 1].y]));
}
for (int widthTrav = 0; widthTrav < jumpParam.SearchGrid.width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < jumpParam.SearchGrid.height; heightTrav++)
{
if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav) == null)
{
continue;
}
if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isOpened)
{
ResultBox resultBox = new ResultBox(widthTrav * 20, heightTrav * 20 + 50, ResultBoxType.Opened);
m_resultBox.Add(resultBox);
}
if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isClosed)
{
ResultBox resultBox = new ResultBox(widthTrav * 20, heightTrav * 20 + 50, ResultBoxType.Closed);
m_resultBox.Add(resultBox);
}
}
}
this.Invalidate();
}