下载了:图标连连看

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

下面是文件下载网址:http://download.youkuaiyun.com/source/873086

下面是界面的代码:

  1. <html>
  2. <head>
  3. <title>图标连连看</title>
  4. </head>
  5. <scriptsrc="link.js"></script>
  6. <body>
  7. <tablecellpadding=0cellspacing=0><tr><td><tbodystyle="background-color:black;"id="gamecanvas"></tbody></td></tr></table>
  8. <script>
  9. varwidth=14;
  10. varheight=14;
  11. vareleWidth=40;
  12. vareleHeight=40;
  13. vargameEles=newArray();
  14. varlinkStack=newArray();
  15. varlock=false;
  16. functioncreateCanvas(_width,_height){
  17. vargc=document.getElementById("gamecanvas");
  18. vartempEles;
  19. vartempEle;
  20. vartempTr;
  21. vartempTd;
  22. for(varx=0;x<_width;x++){
  23. tempEles=newArray();
  24. tempTr=document.createElement("tr");
  25. tempTr.style.height=eleHeight+"px";
  26. for(vary=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. functioneleChoose(_event){
  47. if(lock){
  48. return;
  49. }
  50. lock=true;
  51. varevent;
  52. varp;
  53. varpath;
  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. functionchoose(_point){
  101. vargameEle=gameEles[_point.x][_point.y];
  102. gameEle.style.width=eleWidth-2+"px";
  103. gameEle.style.height=eleHeight-2+"px";
  104. }
  105. functionunchoose(_point){
  106. vargameEle=gameEles[_point.x][_point.y];
  107. gameEle.style.width=eleWidth+"px";
  108. gameEle.style.height=eleHeight+"px";
  109. }
  110. functionlinkSus(_path){
  111. varsourcePoint=_path.shift();
  112. vartargetPoint=_path.pop();
  113. sourcePoint.value=0;
  114. targetPoint.value=0;
  115. varsourceEle=gameEles[sourcePoint.x][sourcePoint.y];
  116. vartargetEle=gameEles[targetPoint.x][targetPoint.y];
  117. sourceEle.onclick=null;
  118. sourceEle.setAttribute("src","img/0.jpg");
  119. targetEle.onclick=null;
  120. targetEle.setAttribute("src","img/0.jpg");
  121. }
  122. functiongetPoint(_id){
  123. varpatterner=/ele(/d+)_(/d+)/;
  124. varresult=_id.match(patterner);
  125. returnpoints[result[1]][result[2]];
  126. }
  127. createPoints(width,height);
  128. createCanvas(width,height);
  129. </script>
  130. </body>
  131. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值