重置功能会重置我拥有的网格。 spotMaker函数为网格着色。我想运行reset函数并等到循环迭代之前完成。我尝试了几个带回调函数的东西,但仍无法让它以异步方式运行。
for (walkthroughs; walkthroughs < numberOfWalks; walkthroughs++) {
console.log("Walkthrough: " + walkthroughs);
reset();
}
// Repeat for as many number of walk
function reset() {
console.log("Walkthrough: " + (walkthroughs + 1));
ctx.clearRect(0, 0, dimensionX * 50, dimensionY * 50);
ctx.fillRect(playerPositionX * 50, playerPositionY * 50, 50, 50);
playerPositionX = 0, playerPositionY = (dimensionY - 1);
for (var i = 0; i < dimensionX; i++)
for (var j = 0; j < dimensionY; j++)
grid[i][j] = 0;
grid[0][dimensionY - 1] = 1;
maxX = 0, maxY = (dimensionY - 1);
minX = 0, minY = (dimensionY - 1);
i = 0;
// Start the process
spotMaker();
}