Created
May 2, 2015 01:51
-
-
Save lengarvey/40184060183668bd49c6 to your computer and use it in GitHub Desktop.
Minesweeper data model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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