function cellClicked(elCell, i, j) {

    var currCell = gBoard[i][j];

    if (gIsFirstClick) {

        //TODO: load after first click
        // CR: You didn't verify that the first cell cannot be a mine.
        addMines(gCurrLevel, gBoard, currCell);

        for (var i = 0; i < gBoard.length; i++) {
            for (var j = 0; j < gBoard[0].length; j++) {
                setMinesNegsCount(gBoard, i, j);
            }
        }
        gState.isGameOn = true;

        gTimeStart = Date.now();
        gTimeCount = setInterval(calcCurrTime, 100);

        gIsFirstClick = false;
        changeEmogi(EMOGI_PLAYING);


    }
    // CR: You don't need to write '=== boolean'.
    // CR: e.g only write 'if (gState.isGameOn)' for true
    // CR: and 'if (!gState.isGameOn)' for false.
    // CR: I would do the if statement reverse: if (!gState.isGameOn) return;
    // CR: and then you don't need the else statement.
    if (gState.isGameOn === true) {
        //left mouse click
        if (event.which === 1) {
            if (currCell.isMarked) return;
            else {
                showCell(currCell, i, j);
                checkGameOver(gCurrLevel);
            }

        }

        //right mouse click
        if (event.which === 3) {

            if (currCell.isShown) {
                return;
            } else if (!currCell.isMarked) {
                currCell.isMarked = true;
                elCell = getClassName(currCell);
                gState.markedCount++;
                cellMarked(elCell);
                checkGameOver(gCurrLevel);

            } else {
                currCell.isMarked = false;
                elCell = getClassName(currCell);
                unMarkCell(elCell);
            }
        }

    } else return;
}
//Called when a cell (td) is clicked
Called when a cell (td) is clicked
Called when a cell ( td ) is clicked
function cellClicked(elCell, i, j) {
    var currCell = gBoard[i][j];
    if (gIsFirstClick) {
        addMines(gCurrLevel, gBoard, currCell);
        for (var i = 0; i < gBoard.length; i++) {
            for (var j = 0; j < gBoard[0].length; j++) {
                setMinesNegsCount(gBoard, i, j);
            }
        }
        gState.isGameOn = true;
        gTimeStart = Date.now();
        gTimeCount = setInterval(calcCurrTime, 100);
        gIsFirstClick = false;
        changeEmogi(EMOGI_PLAYING);
    }
    if (gState.isGameOn === true) {
        if (event.which === 1) {
            if (currCell.isMarked) return;
            else {
                showCell(currCell, i, j);
                checkGameOver(gCurrLevel);
            }
        }
        if (event.which === 3) {
            if (currCell.isShown) {
                return;
            } else if (!currCell.isMarked) {
                currCell.isMarked = true;
                elCell = getClassName(currCell);
                gState.markedCount++;
                cellMarked(elCell);
                checkGameOver(gCurrLevel);
            } else {
                currCell.isMarked = false;
                elCell = getClassName(currCell);
                unMarkCell(elCell);
            }
        }
    } else return;
}
function cellClicked ( elCell , i , j ) { var currCell = gBoard [ i ] [ j ] ; if ( gIsFirstClick ) { addMines ( gCurrLevel , gBoard , currCell ) ; for ( var i = 0 ; i < gBoard . length ; i ++ ) { for ( var j = 0 ; j < gBoard [ 0 ] . length ; j ++ ) { setMinesNegsCount ( gBoard , i , j ) ; } } gState . isGameOn = true ; gTimeStart = Date . now ( ) ; gTimeCount = setInterval ( calcCurrTime , 100 ) ; gIsFirstClick = false ; changeEmogi ( EMOGI_PLAYING ) ; } if ( gState . isGameOn === true ) { if ( event . which === 1 ) { if ( currCell . isMarked ) return ; else { showCell ( currCell , i , j ) ; checkGameOver ( gCurrLevel ) ; } } if ( event . which === 3 ) { if ( currCell . isShown ) { return ; } else if ( ! currCell . isMarked ) { currCell . isMarked = true ; elCell = getClassName ( currCell ) ; gState . markedCount ++ ; cellMarked ( elCell ) ; checkGameOver ( gCurrLevel ) ; } else { currCell . isMarked = false ; elCell = getClassName ( currCell ) ; unMarkCell ( elCell ) ; } } } else return ; }
Called when a cell (td) is clicked
Called when a cell ( td ) is clicked
//TODO: load after first click // CR: You didn't verify that the first cell cannot be a mine. // CR: You don't need to write '=== boolean'. // CR: e.g only write 'if (gState.isGameOn)' for true // CR: and 'if (!gState.isGameOn)' for false. // CR: I would do the if statement reverse: if (!gState.isGameOn) return; // CR: and then you don't need the else statement. //left mouse click //right mouse click