Skip to content

Instantly share code, notes, and snippets.

@lengarvey
Created May 2, 2015 01:51
Show Gist options
  • Save lengarvey/40184060183668bd49c6 to your computer and use it in GitHub Desktop.
Save lengarvey/40184060183668bd49c6 to your computer and use it in GitHub Desktop.
Minesweeper data model
// One key thing with programming (particularly for games or similar things)
// is to think about the "data structure" and have this data model separate
// from the logic.
MS = {
initialize: function(boardSize) {
MS.world = new Array(boardSize);
for(var i=0;i<boardSize;i++) {
MS.world[i] = MS.initRow(boardSize);
}
},
initRow: function(rowSize) {
var row = new Array(rowSize);
for(var i=0;i<rowSize;i++) {
// Create our cell and put some attributes into the object.
// It's expected that these attributes would expand based on the requirements
// of the project.
row[i] = {
visible: false,
bomb: false,
flagged: false
}
}
return row;
}
}
MS.initialize(3);
console.log(MS.world);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment