|
|

楼主 |
发表于 2005-12-9 12:22:00
|
显示全部楼层
Re:计算部队可移动范围的方法
还是得fix一个bug,在Four_point 的初始化错误了一个数据,并且重新调整了一下程序的结构.
public ArrayList 移动列表(C部队 部队)
{
ArrayList 返回列表 = new ArrayList();
Queue 搜索队列 = new Queue();
Point [] Four_point = {new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1)};
搜索队列.Enqueue(new 移动位置属性(部队.x, 部队.y, 部队.行动力));
while(搜索队列.Count > 0)
{
移动位置属性 当前位置 = (移动位置属性)搜索队列.Dequeue();
foreach(Point pt in Four_point) // 判断四个方向是否可以移动
{
int new_x = 当前位置.x + pt.x;
int new_y = 当前位置.y + pt.y;
if (this.战场.是否可以移动(new_x, new_y, 当前位置.行动力))
{
Point pt_new = new Point(new_x, new_y);
bool flag = false;
foreach(Point pt_list in 返回列表)
if (pt_list.Equals(pt_new))
{
flag = true;
break;
}
if (!flag)
{
返回列表.Add(pt_new);
int 新行动力 = 当前位置.行动力 - 战场.地图[new_x, new_y].类型.行动力;
搜索队列.Enqueue(new 移动位置属性(new_x, new_y, 新行动力));
}
}
}
}
return 返回列表;
}
|
|