Full version: jsB@nk » Game » Skill » Javascript Lights Out
URL: https://www.javascriptbank.com/javascript-lights-out.html
Try to eliminate all the boxes to win. When you check a box, all the squares around it (one above, one below, and one to each side) are unselected.
Full version: jsB@nk » Game » Skill » Javascript Lights Out
URL: https://www.javascriptbank.com/javascript-lights-out.html
<SCRIPT lanugage="javascript"><!-- // Change these values from 3 - 9 for // different levels of difficultyvar nRows = 6;var nCols = 6;//change to edit win message.var sWinMsg = "You get some cake.";/////////////////////////////////// Do not edit below this line ///////////////////////////////////// below 3 is impossible to win, above 9 crashes programif (nRows > 9) nRows = 9;if (nRows < 3) nRows = 3;if (nCols > 9) nCols = 9;if (nCols < 3) nCols = 3;var nMoves = 0;function clickButton(x, y) {nMoves++;document.frm.moves.value = nMoves;// toggle clickedtoggleButton(eval("document.frm.b" + x + y));//toggle leftif (x != 0)toggleButton(eval("document.frm.b" + String(x-1) + String(y)));//toggle rightif (x != nCols-1)toggleButton(eval("document.frm.b" + String(x+1) + String(y)));//toggle aboveif (y != 0)toggleButton(eval("document.frm.b" + String(x) + String(y-1)));//toggle belowif (y != nRows-1)toggleButton(eval("document.frm.b" + String(x) + String(y+1)));//did they win?checkWin();}function toggleButton(b) {if (b.style.backgroundColor == "#000000" ||b.style.backgroundColor == "rgb(0,0,0)"){b.style.backgroundColor = "#ffff00";} else {b.style.backgroundColor = "#000000";}}function restart() {var i, j;for (i=0; i<nRows; i++) {for (j=0; j<nCols; j++) {eval("document.frm.b" + i + j + ".style.backgroundColor = '#ffff00'");}}nMoves = 0;if (document.frm.moves)document.frm.moves.value = 0;}function checkWin() {var i, j;var bWon = true;for (i=0; i<nRows; i++) {for (j=0; j<nCols; j++) {if (eval("document.frm.b" + i + j + ".style.backgroundColor == '#ffff00'") ||eval("document.frm.b" + i + j + ".style.backgroundColor == 'rgb(255,255,0)'"))bWon = false;}}if (!bWon)return;alert("You win with " + nMoves + " moves.\n" + sWinMsg);restart();}// --></SCRIPT><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM name=frm><TABLE cellSpacing=0 cellPadding=3 border=0> <SCRIPT language=javascript><!--var i, j;for (i=0; i<nRows; i++) {document.write("<tr>");for (j=0; j<nCols; j++) {document.write("<td><input type='button' value=' '" +" name='b" + j + i + "' onClick='clickButton(" + j + ", " + i + ")'><td>\n");}document.write("</tr>");}restart();// --> </SCRIPT> <TBODY></TBODY></TABLE><BR><INPUT onclick=restart() type=button value=Restart> <FONT face=arial size=2>Moves:</FONT> <INPUT readOnly size=5 value=0 name=moves></FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->