Skip to content

Instantly share code, notes, and snippets.

@lengarvey
Created May 2, 2015 01:51
Show Gist options
  • Select an option

  • Save lengarvey/40184060183668bd49c6 to your computer and use it in GitHub Desktop.

Select an option

Save lengarvey/40184060183668bd49c6 to your computer and use it in GitHub Desktop.

Revisions

  1. lengarvey created this gist May 2, 2015.
    32 changes: 32 additions & 0 deletions minesweeper.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // 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);