JSFiddle - React, Tailwind, and code Playground
by brigand
JavaScript
function Field(coordinates) {
this.coordinates = coordinates;
this.coordinates.x = coordinates[0];
this.coordinates.y = coordinates[1];
this.occupied = false;
}
function Board(width, height) {
this.createMatrix = function(){
Array.from({ length: width }, () => Array(height).fill(null));
var boardArray = [];
for(let i = 0; i < width; i++){
boardArray.push();
}
return boardArray;
}
this.matrix = Array.from({ length: width }, () => Array(height).fill(null));;
this.addFieldsToMatrix = function(){
for(let i = 0; i < width; i++){
for(let j = 0; j < height; j++){
let coordinates = [i, j];
let newField = new Field(coordinates);
this.matrix[i][j] = newField;
}
}
}
this.addFieldsToMatrix();
}
var board = new Board(6,7)
console.log(board.matrix[0][0])