Skip to content

Commit

Permalink
add: indication for failed search. closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
qiao committed Apr 22, 2012
1 parent 2dda504 commit fc9a02a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion visual/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ window.GridView = {
fill: '#afeeee',
'stroke-opacity': 0.2,
},
failedNodeAttr: {
fill: '#ffff88',
'stroke-opacity': 0.2,
},
pathAttr: {
stroke: 'yellow',
'stroke-width': 3,
Expand Down Expand Up @@ -328,6 +332,20 @@ window.GridView = {
}
},

showFailure: function() {
var i, node,
fill = this.failedNodeAttr.fill,
startX = GridModel.getStartX(),
startY = GridModel.getStartY();

for (i = 0; node = this.changedNodes[i]; ++i) {
if (GridModel.isWalkableAt(node.x, node.y) &&
!(node.x === startX && node.y === startY)) {
this.colorizeNodeAt(node.x, node.y, fill);
}
}
},

colorizeNodeAt: function(x, y, color) {
this.rects[y][x].animate({
fill: color,
Expand Down Expand Up @@ -485,7 +503,11 @@ window.GridController = {
self.step(function() {
self.stop();
callback();
GridView.drawPath(self.path);
if (self.path.length) {
GridView.drawPath(self.path);
} else {
GridView.showFailure();
}
});
}, interval);

Expand Down

0 comments on commit fc9a02a

Please sign in to comment.