Skip to content

Commit

Permalink
Improve set solver method
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlvtech committed Feb 8, 2019
1 parent d3c4e81 commit 305319a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ export default class CatchTheCatGame extends Phaser.Game {
this.mainScene = scene;
}

private _solver;

get solver() {
return this._solver;
}

set solver(value) {
this.mainScene.cat.solver = value;
this._solver = value;
try {
this.mainScene.cat.solver = value;
} finally {
}
}
}
5 changes: 5 additions & 0 deletions src/scenes/mainScene.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import data from "../data";
import CatchTheCatGame from "../game";
import Cat from "../sprites/cat";
import Block from "../sprites/block";
import ResetButton from "../sprites/resetButton";
Expand Down Expand Up @@ -26,6 +27,7 @@ export default class MainScene extends Phaser.Scene {
public readonly r: number;
public readonly dx: number;
public readonly dy: number;
public game: CatchTheCatGame;

constructor(w: number, h: number, r: number) {
super({
Expand Down Expand Up @@ -135,6 +137,9 @@ export default class MainScene extends Phaser.Scene {
this.createStatusText();
this.createResetButton();
this.reset();
if (this.game.solver) {
this.cat.solver = this.game.solver;
}
}

getPosition(i: number, j: number): NeighbourData {
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/defaultSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function defaultSolver(blocksIsWall: boolean[][], i: number, j: n
let result = -1;
let neighbours = MainScene.getNeighbours(i, j);
neighbours.forEach((neighbour, direction) => {
if (direction == -1) {
if (result === -1) {
if (blocksIsWall[neighbour.i] !== undefined
&& blocksIsWall[neighbour.i][neighbour.j] !== undefined
&& !blocksIsWall[neighbour.i][neighbour.j]) {
Expand Down

0 comments on commit 305319a

Please # to comment.