<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 一个无聊的游戏 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"> </HEAD>
<style type="text/css">
tr td{cursor: pointer;transition: all ease .3s;color: #fff;font-weight: 600;box-shadow: 0 0 5px 1px #000;}
tr:last-child td:last-child{color: #000}
.bd{margin: 0 auto;width: 300px;}
</style>
<BODY style="background-color:#eee">
<div class="bd">
<h4 style="margin:15px 15px;">全部换色即为过关!</h4>
<table width="300" height="180" border="0" cellpadding="0" cellspacing="3">
<tr align="center">
<td bgcolor="#4599cc" width="25%" id="0-0" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="0-1" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="0-2" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="0-3" onclick="ct(this)"></td>
</tr>
<tr align="center">
<td bgcolor="#4599cc" width="25%" id="1-0" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="1-1" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="1-2" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="1-3" onclick="ct(this)"></td>
</tr>
<tr align="center">
<td bgcolor="#4599cc" width="25%" id="2-0" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="2-1" onclick="ct(this)"></td>
<td bgcolor="#4599cc" width="25%" id="2-2" onclick="ct(this)"></td>
<td bgcolor="#f5f5d5" id="2-3" onclick="resetBox(this)"></td>
</tr>
</table>
<h4 id="mm"></h4>
</div>
</BODY>
</HTML>
<script type="text/javascript">
console.log("E H J I F C D H C")
var $ = function(ele){return document.getElementById(ele);}
var box = [
[1,1,1,1],
[1,1,1,1],
[1,1,1,0]
];
var maxX = 2; //最大行
var maxY = 3; //最大列
var count = 0;
function ct(ele){
var p = ele.id.split("-");
if(box[p[0]][p[1]] == 1){ //能点击
box[p[0]][p[1]] = -1; var sum = 0;
var aX = parseInt(p[0])-1,
bX = parseInt(p[0])+1,
cY = parseInt(p[1])-1,
dY = parseInt(p[1])+1;
if ( aX >= 0 ){
if(box[aX][p[1]] == -1){
box[aX][p[1]] = 1;
}else{
box[aX][p[1]] = -1;
}
}
if ( bX <= maxX ) {
if(box[bX][p[1]] == -1){
box[bX][p[1]] = 1;
}else{
box[bX][p[1]] = -1;
}
}
if( cY >= 0 ){
if(box[p[0]][cY] == -1){
box[p[0]][cY] = 1;
}else{
box[p[0]][cY] = -1;
}
}
if( dY <= maxY ){
if(box[p[0]][dY] == -1){
box[p[0]][dY] = 1;
}else{
box[p[0]][dY] = -1;
}
}
box[2][3] = 0;
$("mm").innerHTML = "第"+(++count)+"次尝试";
for(var i = 0; i<3 ; i++){
for(var j =0 ;j <4 ; j++){
sum += box[i][j];
if(box[i][j] == 1){
$(i+"-"+j).bgColor = "#4599cc";
$(i+"-"+j).style.color = "#fff"; }else if(box[i][j] == -1){
$(i+"-"+j).bgColor = "#d8cb59";
$(i+"-"+j).style.color = "#074d6d"; }else{
$(i+"-"+j).bgColor = "#f5f5d5";
};
}
};
if(sum == -11){ //
$("mm").innerHTML = "恭喜过关!尝试总次数:"+count;
$("mm").style.color = "#960000";
}
}
}
function resetBox(){
for(var i=0; i<3; i++){
for(var j=0; j<4; j++){
box[i][j] = 1;
$(i + '-' + j).bgColor = '#4599cc';
$(i + '-' + j).style.color = '#fff';
}
}
box[2][3] = 0;
count = 0;
$(2 + '-' + 3).bgColor = '#f5f5d5';
$('mm').innerHTML = '';
$("mm").style.color = "#000";
}
</script>

这里主要运用的技术就是数组了,逻辑很简单,让点击的元素四周元素全部变色,所有元素换色成功后即为过关

js小游戏---智力游戏的更多相关文章

  1. 一个js小游戏----总结

    花了大概一天左右的功夫实现了一个js小游戏的基本功能,类似于“雷电”那样的小游戏,实现了随即怪物发生器,碰撞检测,运动等等都实现了,下一个功能是子弹轨迹,还有其他一些扩展功能,没有用库,也没有用web ...

  2. html+css+js实现网页拼图游戏

    代码地址如下:http://www.demodashi.com/demo/14449.html 项目描述 使用 html+js+css 实现一个网页拼图游戏,可支持简单,中等,困难三种难度. 演示效果 ...

  3. BZOJ_1022_[SHOI2008]_小约翰的游戏John_(博弈论_反Nim游戏)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1022 反Nim游戏裸题.详见论文<组合游戏略述——浅谈SG游戏的若干拓展及变形>. ...

  4. SHOI2008小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1139  Solved: 701[Submit][ ...

  5. BZOJ2464: 中山市选[2009]小明的游戏

    2464: 中山市选[2009]小明的游戏 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 280  Solved: 124[Submit][Statu ...

  6. bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1189  Solved: 734[Submit][ ...

  7. BZOJ 1022 [SHOI2008]小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1635  Solved: 1036[Submit] ...

  8. 6、Cocos2dx 3.0游戏开发找小三之游戏的基本概念

    重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27689713 郝萌主友情提示: 人是习惯的产物,当你 ...

  9. 1022: [SHOI2008]小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1322  Solved: 829[Submit][ ...

随机推荐

  1. manachor

    在原字符串每个字符间各插入一个未曾出现的字符,在字符串头插入另一个未出现的字符防止越界,求出的p[i]-1既为以i为中心的最长回文串的长度 void manacher(){ ,id; ;i<=n ...

  2. 51Nod-1279 扔盘子

    51Nod:  http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1279 1279 扔盘子 题目来源: Codility 基 ...

  3. C 语言学习的第 05 课:C 语言基础(01)

    C语言程序中的绝大部分应该记录在以.c作为扩展名的文件里,这种文件叫做C语言    程序的源文件. C语言中还包括以.h作为扩展名的文件,这种文件叫做头文件. C语言中的四则运算: 加:+ 减:- 乘 ...

  4. jquery 实现类似于弹幕效果

    在别人网站中看到一个类似于弹幕的效果,闲来无事用jquery写了个备用~~ <!DOCTYPE html> <meta charset="utf-8"> & ...

  5. 【BZOJ-3747】Kinoman 线段树

    3747: [POI2015]Kinoman Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 715  Solved: 294[Submit][Stat ...

  6. python 2.6 与 2.4 区别

    class 要把 class config(): 改成 class config: except Exception as e # only works in python 2.4 to 2.7 tr ...

  7. Bzoj2154 Crash的数字表格 乘法逆元+莫比乌斯反演(TLE)

    题意:求sigma{lcm(i,j)},1<=i<=n,1<=j<=m 不妨令n<=m 首先把lcm(i,j)转成i*j/gcd(i,j) 正解不会...总之最后化出来的 ...

  8. SQLAlchemy文档翻译

    想记录一下SQLAlchemy的入门学习,然后突发奇想觉得:为什么不直接翻译一下文档呢?于是顺手查了查怎么使用Gitbook,2333 于是就在Github开了项目,然后导入了Gitbook,开始写. ...

  9. ionic 白屏

    昨天在发布新app的时候发现app在高版本的android的时候发现没有问题,在低版本的android 的时候发现存在白屏的情况,在run中alert,不能弹框,run不能运行, 参考这篇文章  ht ...

  10. cf723d Lakes in Berland

    The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cel ...