32 lines
587 B
TypeScript
32 lines
587 B
TypeScript
/**
|
|
* Node 網格節點
|
|
* @author chenkai
|
|
* @since 2017/11/3
|
|
*/
|
|
|
|
export default class Node {
|
|
public x:number; //列
|
|
public y:number; //行
|
|
public f:number; //代價 f = g+h
|
|
public h:number; //當前點到終點估計代價
|
|
public g:number; //起點到當前點代價
|
|
public parent:Node; //父節點
|
|
public walkable:boolean=true; //能否行走
|
|
|
|
public constructor(x:number,y:number) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
// 清理尋路標識
|
|
public clear(){
|
|
this.f=0;
|
|
this.g=0;
|
|
this.h=0;
|
|
this.parent=null;
|
|
}
|
|
|
|
public toString():string{
|
|
return "["+this.x+","+this.y+"]";
|
|
}
|
|
}
|