HTML:
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>Minesweeper</title> <script src="minesweeper.js" type="text/javascript"></script> <link rel="stylesheets" href="minesweeper.css" type="text/css" /> </head> <body> <div> <form id="form"> <input type="radio" name="radio" value="1" onclick="clearTable();newGame(this.value);" /><label> - BEGINNER</label> <input type="radio" name="radio" value="2" onclick="clearTable();newGame(this.value);" /><label> - EASY</label> <input type="radio" name="radio" value="3" onclick="clearTable();newGame(this.value);" /><label> - MEDIUM</label> <input type="radio" name="radio" value="4" onclick="clearTable();newGame(this.value);" /><label> - HARD</label> <input type="radio" name="radio" value="5" onclick="clearTable();newGame(this.value);" /><label> - EXPERT</label> </form> </div> <div id="div2"> <table id="table"> </table> </div> </body> </html>
JS:
var table, allChildren, i, difficulty, winloss, hw, mines, tdCounter, trCounter, tr, td, tdClass;
// radios = document.getElementById("form").childNodes;
table = document.getElementById("table");
allChildren = table.childNodes;
function askNewGame(winloss) {
alert("You " + winloss +" To play again, choose a difficulty.");
}
function makeGame(hw, mines, tdClass) {
for (trCounter=0;trCounter<hw;trCounter++) {
tr = document.getElementById("table").insertRow(trCounter);
tr.id = ("row" + trCounter.toString());
for (tdCounter=0;tdCounter<hw;tdCounter++) {
td = document.getElementById("row" + trCounter.toString()).insertCell(tdCounter);
td.className = tdClass;
//document.getElementById("row" + trCounter.toString()).appendChild(td);
}
}
}
function newGame(difficulty) {
switch (difficulty) {
case "1":
hw=5;
mines=5;
tdClass = "beginner";
break;
case "2":
hw=7;
mines=20;
tdClass = "easy";
break;
case "3":
hw=10;
mines=25;
tdClass = "medium";
break;
case "4":
hw=20;
mines=100;
tdClass = "hard";
break;
case "5":
hw=30;
mines=450;
tdClass = "expert";
break;
}
makeGame(hw, mines, tdClass);
}
function gameOver() {
askNewGame("Lost.");
}
function clearTable() {
for (i=0;i<=allChildren.length;i++) {
table.removeChild(allChildren[i]);
}
}
CSS:
td {
border: 3px solid #555;
}
.beginner {
width: 100px;
height: 100px;
}
.easy {
width: 71px;
height: 71px;
}
.medium {
width: 50px;
height: 50px;
}
.hard {
width: 25px;
height: 25px;
}
.expert {
width: 16px;
height: 16px;
}
My errors could easily be in the HTML or CSS so I included all 3.

New Topic/Question
Reply


MultiQuote



|