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
class FooController | |
def index | |
# The controller is responsible for gathering the things needed | |
# to make the response. This should be a single line of code | |
@things = Foo.things | |
# The controller is responsible for sending the view back to the user. | |
# the view uses our instance variable above to render @things | |
render :some_view | |
end |
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); |
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
// init process | |
Minesweeper.initEvents(); // initialize events. Remember to listen on $(document).on('click', '.cell') | |
// etc... | |
Minesweeper.initializeBoard('M'); // create the board of the right size. | |
Minesweeper.placeMines(); // update Minesweeper.world to update the random cells with mine = true; | |
Minesweeper.calculateSurroundingMines(); // updates each cell to figure out the number of mines surrounding it. | |
Minesweeper.render(); // renders the game board. |