This commit is contained in:
2026-01-20 08:36:55 -06:00
parent 6e78e8f9c2
commit 187879a7c6
8 changed files with 26 additions and 26 deletions

View File

@@ -1,17 +1,19 @@
function grid(w, h) {
this.width = w;
this.height = h;
var newgrid = meme(grid_prototype)
newgrid.width = w;
newgrid.height = h;
// create a height×width array of empty lists
this.cells = array(h);
newgrid.cells = array(h);
for (var y = 0; y < h; y++) {
this.cells[y] = array(w);
newgrid.cells[y] = array(w);
for (var x = 0; x < w; x++) {
this.cells[y][x] = []; // each cell holds its own list
newgrid.cells[y][x] = []; // each cell holds its own list
}
}
return newgrid
}
grid.prototype = {
var grid_prototype = {
// return the array at (x,y)
cell(x, y) {
return this.cells[y][x];
@@ -66,4 +68,6 @@ grid.prototype = {
}
return out;
}
};
}
return grid