Skip to content

Instantly share code, notes, and snippets.

@amysimmons
Forked from lengarvey/minesweeper.js
Last active August 29, 2015 14:20
Show Gist options
  • Save amysimmons/ac5ec69a0d41d09d8ab7 to your computer and use it in GitHub Desktop.
Save amysimmons/ac5ec69a0d41d09d8ab7 to your computer and use it in GitHub Desktop.
// 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