js魔方游戏网页版

news/2024/7/19 13:23:21 标签: js, 游戏

网页版的魔方游戏,什么时候你能把黄色方块填满你就赢了,我感觉我什么时候也填不满,也许你有超人智慧可以完成这一光荣使命,那你就试试吧?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>魔方游戏</title>
<script>
function ShowMenu(bMenu) {
document.all.idFinder.style.display = (bMenu) ? "none" : "block"
document.all.idMenu.style.display = (bMenu) ? "block" : "none"
idML.className = (bMenu) ? "cOn" : "cOff"
idRL.className = (bMenu) ? "cOff" : "cOn"
return false
}
</script>
<style>
A.cOn {text-decoration:none;font-weight:bolder}
#article {font: 12pt Verdana, geneva, arial, sans-serif; background: white; color: black; padding: 10pt 15pt 0 5pt}
#article P.start {text-indent: 0pt}
#article P {margin-top:0pt;font-size:10pt;text-indent:12pt}
#article #author {margin-bottom:5pt;text-indent:0pt;font-style: italic}
#pageList P {padding-top:10pt}
#article H3 {font-weight:bold}
#article DL, UL, OL {font-size: 10pt}
</style>
<script>
function addList(url,desc) {
if ((navigator.appName=="Netscape") || (parseInt(navigator.appVersion)>=4)) {
var w=window.open("","_IDHTML_LIST_","top=0,left=0,width=475,height=150,history=no,menubar=no,status=no,resizable=no")
var d=w.document
if (!w._init) {
d.open()
d.write("<TITLE>Loading...</TITLE><EM>Loading...</EM>")
d.close()
d.location.replace("/assist/listing.asp?url="+escape(url)+"&desc="+escape(desc))
w.opener=self
window.status="Personal Assistant (Adding): " + desc
} else {
window.status=w.addOption(url,desc)
w.focus()
}
}
else
alert("Your browser does not support the personal assistant.")
return false
}
</script>
<style>
#board {cursor: default}
#board TD {width: 25px; height: 25px; }
</style>
<script>
var size=10
var moves = 0
var off = size*2
var on = 0
var current = null
function doOver() {
if ((event.srcElement.tagName=="TD") && (current!=event.srcElement)) {
if (current!=null)
current.style.backgroundColor = current._background
event.srcElement._background = event.srcElement.style.backgroundColor
event.srcElement.style.backgroundColor = "lightgrey"
current = event.srcElement
}
}

function setColor(el) {
if ((el._background=="") || (el._background==null)) {
el.style.backgroundColor = "yellow"
el._background = "yellow"
} else {
el.style.backgroundColor = ""
el._background = ""
}
}

function countLights() {
off = 0; on = 0
for (var x=0; x < size; x++)
for (var y=0; y < size; y++) {
var p = board.rows[x].cells[y]
if (p._background=="yellow")
on++
else
off ++
}
document.all.on.innerText = on
if (off!=0)
document.all.off.innerText = off
else
document.all.off.innerText = "You Win!"
return (off==0)
}

function doClick() {
setColor(current)
var cellIdx = current.cellIndex
var rowIdx = current.parentElement.rowIndex
if (rowIdx>0)
setColor(board.rows[rowIdx-1].cells[cellIdx])
if (rowIdx<size-1)
setColor(board.rows[rowIdx+1].cells[cellIdx])
if (cellIdx>0)
setColor(board.rows[rowIdx].cells[cellIdx-1])
if (cellIdx<size-1)
setColor(board.rows[rowIdx].cells[cellIdx+1])
moves++
document.all.moves.innerText = moves
win = countLights()
if (win) {
board.onclick = null
board.onmouseover = null
current.style.background = "yellow"
}
}

function buildBoard() {
var str = "<TABLE ID=board ONSELECTSTART=\"return false\" ONCLICK=\"doClick()\" ONMOUSEOVER=\"doOver()\" cellspacing=0 cellpadding=0 border=5>"
for (var x=0; x < size; x++) {
str+="<TR>"
for (var y=0; y < size; y++) {
str+="<TD> </TD>"
}
str+="</TR>"
}
str+="</TABLE>"
return str
}

function newGame() {
size = document.all.gameSize.value
if (size<3)
size=3
if (size>15)
size=15
document.all.gameSize.value = size
document.all.board.outerHTML = buildBoard()
moves=0
document.all.moves.innerText = moves
countLights()

}

</script>
</head>

<body>
<table border="1" width="100%">
<tr>
<td width="50%"><div align="right"><table ID="score" border="0" width="284">
<tr>
<td width="52">移动: </td>
<td id="moves" width="33">0</td>
<td width="42">灯灭:</td>
<td id="off" width="36">25</td>
<td width="46">灯亮:</td>
<td id="on" width="39">0</td>
</tr>
</table>
</div></td>
<td width="50%"><div align="left"><table width="204">
<tr>
<td width="54">大小: </td>
<td width="41"><input ID="gameSize" TYPE="text" VALUE="10" SIZE="2"></td>
<td width="97"><input ONCLICK="newGame()" TYPE="button" VALUE="开始游戏"></td>
</tr>
</table>
</div></td>
</tr>
</table>
<p align="center"><script>
document.write(buildBoard())
</script></p>
</body>
</html>

 


摘自:http://www.q3060.com/list3/list115/7649.html


http://www.niftyadmin.cn/n/485715.html

相关文章

[Java] 多态相关的题目

目录多态相关的题目1. 问答题2. 编程题多态相关的题目 1. 问答题 1. 请用一句话描述出用代码怎样实现“多态”&#xff1f;1. 继承或实现&#xff08;二选一&#xff09;2. 方法重写3. 父类引用指向子类对象2. 请写出多态的好处和弊端。好处&#xff1a;多态的好处是提高代码…

android studio 图片轮播_打造一个丝滑般自动轮播无限循环Android库

最近公司项目在升级AndroidX&#xff0c;由于项目中用到的一些比较老的库都已停止更新维护&#xff0c;因此需要将这些库替换掉&#xff0c;其中就包括自动轮播的Banner库。恰逢笔者在之前写过一个轮播图&#xff0c;因此就在此基础上重构&#xff0c;打造出了一个全新的支持多…

两种不同版本的防注入函数

//************** 防注入函数 function inject_check($sql_str) { $checkeregi(and|or|where|limit|group by|select|insert|update|delete|\|\\*|\*|\.\.\/|\.\/|union|into|load_file|outfile,$sql_str); // 进行过滤 PHP5.3以前用//$check preg_match(/and|or|where|lim…

[Java] 权限修饰符、内部类与代码块相关题目

目录权限修饰符、内部类与代码块相关题目1. 访问权限修饰符2. 内部类3. 代码块权限修饰符、内部类与代码块相关题目 1. 访问权限修饰符 1. 请按作用范围从小到大的顺序写出四种访问权限修饰符。private、protected、default&#xff08;默认的&#xff09;、public2. 请问修饰…

在线 python 环境_Python 和Django在线环境安装

Ngnix安装&#xff1a;自动化数字化之芯&#xff1a;Nginx的安装step by step​zhuanlan.zhihu.com Python安装。 下载Python包&#xff1a;cd /usr 解压&#xff1a;cd /usr tar xf Python-3.7.1.tar.xz 配置&#xff1a; 进入python目录cd Python-3.7.1 安装依赖包插件&#…

[JavaScript] 实现全选与反选功能

目录全选与反选功能1. 主要功能2. 代码实现3. 展示效果全选与反选功能 1. 主要功能 全选&#xff1a;点击全选按钮,所有复选框都被选中反选&#xff1a;点击反选按钮,所有复选框状态取反 2. 代码实现 <!DOCTYPE html> <html lang"zh"> <head>&l…

【转载】php的xml分析函数

转载自&#xff1a;http://www.q3060.com/list3/list117/17740.html 首先我得承认我喜欢计算机标准。如果每个人都遵从这个行业的标准&#xff0c;互联网将会是一个更好的媒体。使用标准化的数据交换格式才能使开放的和独立于平台的计算模式切实可行。这就是我作为XML爱好者的原…

[JavaScript] 实现省市关联

目录省市关联1. 主要功能2. 代码实现省市关联 1. 主要功能 页面加载完成后自动装载省数据&#xff1b;当选中省时&#xff0c;装载对应该省的市数据。 2. 代码实现 <!DOCTYPE html> <html> <head><meta charset"utf-8"/><title>省市…