微软视觉工作室扫雷编码

时间:2014-11-14 14:57:29

标签: javascript html arrays loops minesweeper

这是我的代码。我正在尝试为每个方块添加一个onclick,以便当您单击该方块时,将其从灰色方块更改为具有其值的方块。我有一个8 x 8的桌子。此外,当我揭示一个正方形时,我需要更改其状态,以便它不再关闭并显示其值。此外,我需要随机将8枚地雷放入雷区而不在同一地点放置两枚地雷。我无法弄清楚这个代码。

请帮忙!

谢谢!

    var aiSquareValue = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]
    var aiSquareStatus = [["c", "c", "c", "c", "c", "c", "c", "c"], ["o", "o", "o", "o", "o", "o", "o", "o"], ["f", "f", "f", "f", "f", "f", "f", "f", "f"]]
    var aiGridValue = 0
    var  bIsMatch = false


    function vBuild()
    {
        var strHTML
        var i, j


        //Start building the table
        strHTML = "<table style='margin-left:auto; margin-right:auto'>"

            strHTML += "<tr>"
            strHTML += "<td colspan='6' style='text-align:center; font-size:xx-large''>Minesweeper</td>"
                strHTML += "</tr>"
                strHTML += "<tr>"
                strHTML += "<td colspan='6' style='text-align:center' >"
                strHTML += "<input type='button' id='btnNewGame' value='New Game' onclick='vNewGame()'/>"
                strHTML += "</td>"
                strHTML += "</tr>"


        //Loop through the rows in the table
        for (i = 0; i < 6; i++) {
            strHTML += "<tr>"
            //loops through the columns
            for (j = 0; j < 6; j++) {
                strHTML += "<td>"

                //add image tag
                strHTML += "<img src='GraySquare.png' id = 'img" + i + "," + j + "' onclick='vClick(" + i + "," + j + ")' />"

                strHTML += "</td>"
            }
            strHTML += "</tr>"              

        }

        strHTML += "<tr>"
        strHTML += "<td colspan='6' style='text-align:center' >"
        strHTML += "<textarea id='taOut' style='margin-left:auto; margin-right:auto; text-align:center; align-content:center' rows='30' cols='60' ></textarea>"
        strHTML += "</td>"
        strHTML += "</tr>"
        strHTML += "</table>"

        //insert function in to document
        frmGrid.innerHTML = strHTML
    }

    function vMines()
    {
        var i, j;
        var iRow = (Math.floor(Math.random()*8))
        var iCol = (Math.floor(Math.random()*8))


        while (i <= 7) {
            aiSquareValue[iRow][iCol] = 9





        }


    }


    function vNewGame()
    {



    }

    function vClick()
    {




    }

0 个答案:

没有答案