microsoft visual studio minesweeper code

494 Views Asked by At

Here is the code I have. I am trying to add an onclick to each square so that when you click on that square you change it from a gray square to a square with its value. I have an 8 x 8 table. Also when I reveal a square I need to change its status so its no longer closed and shows its value. Also I need to randomly place 8 mines into the minefield without placing two mines in the same spot. I can not figure out the code for this.

Please help!

Thanks!

    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

There are 0 best solutions below