»
AnglaisFrançaisVietnamien

Imprimer - Javascript Lights Out - JavaScriptBank.com

Version complète: jsB@nk » Game » Qualification » Javascript Lights Out
URL: https://www.javascriptbank.com/javascript-lights-out.html

Javascript Lights Out © JavaScriptBank.comEssayez d'éliminer toutes les cases pour gagner. Lorsque vous cochez une case, toutes les places autour de lui (l'un au-dessus, celui ci-dessous, et un de chaque côté) sont dé-sélectionnés.

Version complète: jsB@nk » Game » Qualification » Javascript Lights Out
URL: https://www.javascriptbank.com/javascript-lights-out.html



JavaScript
<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-->


HTML
<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='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" +" 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> &nbsp;&nbsp;<FONT face=arial size=2>Moves:</FONT>&nbsp; <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-->