下载了:图标连连看

 在写过Python版和JavaScript版连连看的算法后,特为JavaScript版连连看算法写了一个图形交互界面。至此完整的连连看游戏出炉了。

下面是文件下载网址:http://download.csdn.net/source/873086

下面是界面的代码:

  1. <html>
  2.     <head>
  3.         <title>图标连连看</title>
  4.     </head>
  5.     <script src="link.js"></script>
  6.     <body>
  7.         <table cellpadding=0 cellspacing=0><tr><td><tbody style="background-color:black;" id="gamecanvas"></tbody></td></tr></table>
  8.         <script>
  9.             var width = 14;
  10.             var height = 14;
  11.             var eleWidth = 40;
  12.             var eleHeight = 40;
  13.             var gameEles = new Array();
  14.             var linkStack = new Array();
  15.             var lock = false;
  16.             function createCanvas(_width,_height){
  17.                 var gc = document.getElementById("gamecanvas");
  18.                 var tempEles;
  19.                 var tempEle;
  20.                 var tempTr;
  21.                 var tempTd;
  22.                 for(var x = 0 ; x < _width ; x++){
  23.                     tempEles = new Array();
  24.                     tempTr = document.createElement("tr");
  25.                     tempTr.style.height = eleHeight+"px";
  26.                     for(var y = 0 ; y < _height ; y++){
  27.                         tempEle = document.createElement("img");
  28.                         tempEle.setAttribute("src","img/"+points[x][y].value+".jpg");
  29.                         tempEle.setAttribute("id","ele"+x+"_"+y);
  30.                         tempEle.style.width = eleWidth+"px";
  31.                         tempEle.style.height = eleHeight+"px";
  32.                         if(x>1 && x<_width-2 && y>1 && y<_height-2){
  33.                             tempEle.onclick = eleChoose;
  34.                         }
  35.                         tempTd = document.createElement("td");
  36.                         tempTd.style.width = eleWidth+"px";
  37.                         tempTd.style.textAlign = "center";
  38.                         tempTd.appendChild(tempEle);
  39.                         tempTr.appendChild(tempTd);
  40.                         gc.appendChild(tempTr);
  41.                         tempEles[y] = tempEle;
  42.                     }
  43.                     gameEles[x] = tempEles;
  44.                 }
  45.             }
  46.             function eleChoose(_event){
  47.                 if(lock){
  48.                     return;
  49.                 }
  50.                 lock = true;
  51.                 var event;
  52.                 var p;
  53.                 var path;
  54.                 if(window.event){
  55.                     event = window.event;
  56.                     p = getPoint(event.srcElement.getAttribute("id"));
  57.                 }
  58.                 else{
  59.                     event = _event;
  60.                     p = getPoint(event.target.getAttribute("id"));
  61.                 }
  62.                 if(linkStack.length == 0){
  63.                     choose(p);
  64.                     linkStack.push(p);
  65.                 }
  66.                 else{
  67.                     if(p.x == linkStack[0].x && p.y == linkStack[0].y){
  68.                         unchoose(linkStack.pop());
  69.                         lock = false;
  70.                         return;
  71.                     }
  72.                     choose(p);
  73.                     if(p.value == linkStack[0].value){
  74.                         path = linkPoints(linkStack[0],p);
  75.                         if(path){
  76.                             unchoose(linkStack.pop());
  77.                             unchoose(p);
  78.                             linkSus(path);
  79.                         }
  80.                         else{
  81.                             path = linkPoints(p,linkStack[0]);
  82.                             if(path){
  83.                                 unchoose(linkStack.pop());
  84.                                 unchoose(p);
  85.                                 linkSus(path);
  86.                             }
  87.                             else{
  88.                                 unchoose(linkStack.pop());
  89.                                 linkStack.push(p);
  90.                             }
  91.                         }
  92.                     }
  93.                     else{
  94.                         unchoose(linkStack.pop());
  95.                         linkStack.push(p);
  96.                     }
  97.                 }
  98.                 lock = false;
  99.             }
  100.             
  101.             function choose(_point){
  102.                 var gameEle = gameEles[_point.x][_point.y];
  103.                 gameEle.style.width = eleWidth-2+"px";
  104.                 gameEle.style.height = eleHeight-2+"px";
  105.             }
  106.             
  107.             function unchoose(_point){
  108.                 var gameEle = gameEles[_point.x][_point.y];
  109.                 gameEle.style.width = eleWidth+"px";
  110.                 gameEle.style.height = eleHeight+"px";
  111.             }
  112.             
  113.             function linkSus(_path){
  114.                 var sourcePoint = _path.shift();
  115.                 var targetPoint = _path.pop();
  116.                 sourcePoint.value = 0;
  117.                 targetPoint.value = 0;
  118.                 var sourceEle = gameEles[sourcePoint.x][sourcePoint.y];
  119.                 var targetEle = gameEles[targetPoint.x][targetPoint.y];
  120.                 sourceEle.onclick=null;
  121.                 sourceEle.setAttribute("src","img/0.jpg");
  122.                 targetEle.onclick=null;
  123.                 targetEle.setAttribute("src","img/0.jpg");
  124.             }
  125.             
  126.             function getPoint(_id){
  127.                 var patterner = /ele(/d+)_(/d+)/;
  128.                 var result = _id.match(patterner);
  129.                 return points[result[1]][result[2]];
  130.             }
  131.             
  132.             createPoints(width,height);
  133.             createCanvas(width,height);
  134.         </script>
  135.     </body>
  136. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值