<commit_before>
var Board = function (sizex, sizey, bombs) {
    this.sizex = sizex || 10;
    this.sizey = sizey || 10;
    this.bombs = bombs || 10;
    this.checkboard = [];
}

Board.prototype.init_checkboard = function (selector) {
    this.checkboard = [];
    for(var i=0;i<this.sizey;i++) {
        var tmp = [];
        for(var j=0;j<this.sizex;j++) {
            var new_cell = new Cell(j, i);
            tmp.push(new_cell);
        }
        this.checkboard.push(tmp);
    }

    if(selector) {
        $(selector).html("");
        $(selector).append(this.get_table());
        this.install_events();
    }
}

Board.prototype.init_bombs = function () {
    /*this.checkboard[0][0].has_bomb = true;
    this.checkboard[1][1].has_bomb = true;
    this.checkboard[2][2].has_bomb = true;
    this.checkboard[3][3].has_bomb = true;
    this.checkboard[4][4].has_bomb = true;
    this.checkboard[5][5].has_bomb = true;
    this.checkboard[6][6].has_bomb = true;
    this.checkboard[7][7].has_bomb = true;
    this.checkboard[8][8].has_bomb = true;
    this.checkboard[9][9].has_bomb = true;*/

    this.bombs = Math.min(this.bombs, this.sizey*this.sizex);

    for(var i = 0 ; i < this.bombs ; i++) {
        col = Math.floor(Math.random() * this.sizex);
        row = Math.floor(Math.random() * this.sizey);

        if(this.checkboard[row][col].has_bomb) i--;
        this.checkboard[row][col].has_bomb = true;
    }
}

Board.prototype.get_table = function () {
    var a_table = $('<table>');

    $.each(this.checkboard, function(rown, row) {
        var one_row = $('<tr>');
        $.each(row, function(coln, cell) {
            one_row.append(cell.get_cell());
        });
        a_table.append(one_row.clone());
    });

    return a_table;
}

Board.prototype.install_events = function () {
    $('body, html').contextmenu(function(ev) {
        ev.preventDefault();
        return false;
    });
    $(".cell-closed").mousedown(function (ev) {
        ev.preventDefault();

        start_watch();

        var col = $(this).attr('data-col');
        var row = $(this).attr('data-row');

        switch (event.which) {
            case 1:
                board.reveal_cell(row, col);
                break;
            case 3:
                board.flag_cell(row, col);
                break;
        }
    })
}

Board.prototype.end_game = function () {
    stop_watch();
    $(".cell-closed").unbind('mousedown');
}

Board.prototype.reveal_cell = function (cell_row,cell_col) {
    start_watch();
    var res = this.checkboard[cell_row][cell_col].reveal();
    switch(res) {
    case 2: 
        //GAME OVER
        $.each(this.checkboard, function(row) {
            $.each(this, function(col, val) {
                if(val.has_bomb) val.reveal(true);
                if(val.flagged) val.reveal(true);
            });
        });

        this.end_game();
    break;<commit_msg>Bug en firefox<commit_after>
var Board = function (sizex, sizey, bombs) {
    this.sizex = sizex || 10;
    this.sizey = sizey || 10;
    this.bombs = bombs || 10;
    this.checkboard = [];
}

Board.prototype.init_checkboard = function (selector) {
    this.checkboard = [];
    for(var i=0;i<this.sizey;i++) {
        var tmp = [];
        for(var j=0;j<this.sizex;j++) {
            var new_cell = new Cell(j, i);
            tmp.push(new_cell);
        }
        this.checkboard.push(tmp);
    }

    if(selector) {
        $(selector).html("");
        $(selector).append(this.get_table());
        this.install_events();
    }
}

Board.prototype.init_bombs = function () {
    /*this.checkboard[0][0].has_bomb = true;
    this.checkboard[1][1].has_bomb = true;
    this.checkboard[2][2].has_bomb = true;
    this.checkboard[3][3].has_bomb = true;
    this.checkboard[4][4].has_bomb = true;
    this.checkboard[5][5].has_bomb = true;
    this.checkboard[6][6].has_bomb = true;
    this.checkboard[7][7].has_bomb = true;
    this.checkboard[8][8].has_bomb = true;
    this.checkboard[9][9].has_bomb = true;*/

    this.bombs = Math.min(this.bombs, this.sizey*this.sizex);

    for(var i = 0 ; i < this.bombs ; i++) {
        col = Math.floor(Math.random() * this.sizex);
        row = Math.floor(Math.random() * this.sizey);

        if(this.checkboard[row][col].has_bomb) i--;
        this.checkboard[row][col].has_bomb = true;
    }
}

Board.prototype.get_table = function () {
    var a_table = $('<table>');

    $.each(this.checkboard, function(rown, row) {
        var one_row = $('<tr>');
        $.each(row, function(coln, cell) {
            one_row.append(cell.get_cell());
        });
        a_table.append(one_row.clone());
    });

    return a_table;
}

Board.prototype.install_events = function () {
    $('body, html').contextmenu(function(ev) {
        ev.preventDefault();
        return false;
    });
    $(".cell-closed").mousedown(function (ev) {
        ev.preventDefault();

        start_watch();

        var col = $(this).attr('data-col');
        var row = $(this).attr('data-row');

        switch (ev.which) {
            case 1:
                board.reveal_cell(row, col);
                break;
            case 3:
                board.flag_cell(row, col);
                break;
        }
    })
}

Board.prototype.end_game = function () {
    stop_watch();
    $(".cell-closed").unbind('mousedown');
}

Board.prototype.reveal_cell = function (cell_row,cell_col) {
    start_watch();
    var res = this.checkboard[cell_row][cell_col].reveal();
    switch(res) {
    case 2: 
        //GAME OVER
        $.each(this.checkboard, function(row) {
            $.each(this, function(col, val) {
                if(val.has_bomb) val.reveal(true);
                if(val.flagged) val.reveal(true);
            });
        });

        this.end_game();
    break;
{'fraction_non_alphanumeric': 0.1734623358673117, 'fraction_numerical': 0.0110573600552868, 'mean_word_length': 2.214325374791782, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4340134', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2003, 'n_words': 307}