$(document).ready(function() { var board_o = new board(10, 10, 15); $("#start").click(function(){ $("#splash").hide(); $("#boardsection").show(); board_o.initiate(); $("#board").replaceWith(board_o.draw()); $(".cell").on("click", function(){ $(this).replaceWith(board_o.flip($(this).attr('id'))); }); }); }); var cell = function (x, y){ this.pos=[x, y]; this.state="covered"; this.mine=false; this.neighbours=0; }; var board = function (sizex, sizey, mines){ this.size=[sizex, sizey]; this.mines=mines; this.cell_o=[]; this.initiate = function(){ for (i=0; i"; for (i=0; i"; } web_string=web_string + ""; } return web_string + ""; }; this.convertId = function(my_id){ return (my_id.split("_")); }; this.flip = function(my_id){ var pos=my_id.split("_"); var x=parseInt(pos[0]); var y=parseInt(pos[1]); if (this.cell_o[x][y].mine) { this.cell_o[x][y].state="explosion_uncovered"; this.showBoard(x,y); } else { this.cell_o[x][y].state=this.cell_o[x][y].neighbours + "_uncovered"; this.uncovered++; if(this.uncovered==(this.size[0]*this.size[1])-this.mines){ this.showBoard(this.size[0], this.size[1]); alert("You won!") } } return (""); }; this.showBoard = function(x,y){ for (i=0; i-1 && n>-1 && m