/// 判断下一步可能的位置,计算猫可移动的位置
/// </summary>
/// <returns></returns>
private ArrayList FindSteps()
{
Items items = cat.GetComponent<Items>();
int rowIndex = items.rowIndex;
int columnIndex = items.columnIndex;
ArrayList steps = new ArrayList();
Vector2 nextStep = new Vector2();
#region 获得可以行走的位置 上下左右
//left
nextStep.y = rowIndex;
nextStep.x = columnIndex-1;
if (Movable(nextStep))
steps.Add(nextStep);
//right
nextStep.y = rowIndex;
nextStep.x = columnIndex + 1;
if (Movable(nextStep))
steps.Add(nextStep);
//top
nextStep.y = rowIndex + 1;
nextStep.x = columnIndex;
if (Movable(nextStep))
steps.Add(nextStep);
//bottom
nextStep.y = rowIndex - 1;
nextStep.x = columnIndex;
if (Movable(nextStep))
steps.Add(nextStep);
#endregion
//奇数行topleft,偶数行topright
nextStep.y = rowIndex + 1;
if (rowIndex % 2 == 1)
nextStep.x = columnIndex - 1;
else
nextStep.x = columnIndex + 1;
if (Movable(nextStep))
steps.Add(nextStep);
//奇数行bottomleft,偶数行bottomright
nextStep.y = rowIndex - 1;
if (rowIndex % 2 == 1)
nextStep.x = columnIndex - 1;
else
nextStep.x = columnIndex + 1;
if (Movable(nextStep))
steps.Add(nextStep);
return steps;
}
/// <summary>
/// 根据指定的位置找最大的通路
/// </summary>
/// <param name="vector"></param>
/// <returns></returns>
int FindSteps(Vector2 vector)
{
Items items = GetPot((int)vector.y, (int)vector.x);
int rowIndex = items.rowIndex;
int columnIndex = items.columnIndex;
ArrayList steps = new ArrayList();
Vector2 nextStep = new Vector2();
#region 获得可以行走的位置 上下左右
//left
nextStep.y = rowIndex;
nextStep.x = columnIndex - 1;
if (Movable(nextStep))
steps.Add(nextStep);
//right
nextStep.y = rowIndex;
nextStep.x = columnIndex + 1;
if (Movable(nextStep))
steps.Add(nextStep);
//top
nextStep.y = rowIndex + 1;
nextStep.x = columnIndex;
if (Movable(nextStep))
steps.Add(nextStep);
//bottom
nextStep.y = rowIndex - 1;
nextStep.x = columnIndex;
if (Movable(nextStep))
steps.Add(nextStep);
#endregion
//奇数行topleft,偶数行topright
nextStep.y = rowIndex + 1;
if (rowIndex % 2 == 1)
nextStep.x = columnIndex - 1;
else
nextStep.x = columnIndex + 1;
if (Movable(nextStep))
steps.Add(nextStep);
//奇数行bottomleft,偶数行bottomright
nextStep.y = rowIndex - 1;
if (rowIndex % 2 == 1)
nextStep.x = columnIndex - 1;
else
nextStep.x = columnIndex + 1;
if (Movable(nextStep))
steps.Add(nextStep);
return steps.Count;
}
private void SetAllPaths()
{
//左上角
for (int i = 0; i < rowNum ; i++)
{
for (int j = 0; j < columnNum ; j++)
{
if (Movable(new Vector2(i, j)))
ChangePath(new Vector2(i, j));
if (Movable(new Vector2(j, i)))
ChangePath(new Vector2(j, i));
}
}
//左下角
for (int i = 0; i < rowNum ; i++)
{
for (int j = 0; j < columnNum ; j++)
{
if(Movable (new Vector2 (i,rowNum -1-j)))
ChangePath (new Vector2 (i,rowNum -1-j));
if(Movable (new Vector2 (columnNum -1-j,i)))
ChangePath (new Vector2 (columnNum -1-j,i));
}
}
//右上角
for (int i = 0; i < rowNum; i++)
{
for (int j = 0; j < columnNum; j++)
{
if (Movable(new Vector2(i, rowNum - 1 - j)))
ChangePath(new Vector2(i, rowNum - 1 - j));
if (Movable(new Vector2(j, columnNum - 1 - i)))
ChangePath(new Vector2(j, columnNum - 1 - i));
}
}
//右下角
for (int i = 0; i < rowNum; i++)
{
for (int j = 0; j < columnNum; j++)
{
if (Movable(new Vector2(rowNum - 1 - i, rowNum - 1 - j)))
ChangePath(new Vector2(rowNum - 1 - i, rowNum - 1 - j));
if (Movable(new Vector2(columnNum - 1 - j, columnNum - 1 - i)))
ChangePath(new Vector2(columnNum - 1 - j, columnNum - 1 - i));
}
}
}