jquery实现消灭格子消除小游戏代码
代码语言:html
所属分类:游戏
代码描述:jquery实现消灭格子消除小游戏代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-1.8.3.js"></script> <style type="text/css"> body { background-color: black; } #main { width: 540px; height: 540px; } #msg { color: white; } .star { width: 50px; height: 50px; margin: 1px; border: 1px solid black; float: left; } .c0 { background-color: orange; } .c1 { background-color: green; } .c2 { background-color: red; } .c3 { background-color: yellow; } .c4 { background-color: blue; } .cleaned { background-color: black; } .clicked { border-color: silver; cursor: pointer; background-color: silver; } </style> <script type="text/javascript"> $(document).ready(function() { var blnIE = $.browser.msie; var intCnt = 0; var blnPlaying = true; var funForGetMore = function(x, y, c) { var star = $('#' + x + '_' + y); if (star.hasClass(c) && !star.hasClass('clicked')) { star.addClass('clicked'); getMore(x, y, c); } } var getMore = function(x, y, c) { x = parseInt(x); y = parseInt(y); (x > 0) && funForGetMore(x - 1, y, c); (y > 0) && funForGetMore(x, y - 1, c); (x < 9) && funForGetMore(x + 1, y, c); (y < 9) && funForGetMore(x, y + 1, c); } var cleanY = function(y, x) { y = parseInt(y); if (x > -1) { var star = $('#' + x + '_' + y); if (y == 9) { star.attr('class', 'star cleaned'); } else { var y_ = y + 1; star.attr('class', $('#' + x + '_' + y_).attr('class')); cleanY(y_, x); } } else { for (x = 0; x < 10; x++) { cleanY(y, x); } } } var cleanX = function(x, y) { var star = $('#' + x + '_' + y); if (x == 0) { star.attr('class', 'star cleaned'); } else { var x_ = x - 1; star.attr('class', $('#' + x_ + '_' + y).attr('class')); (!star.hasClass('cleaned')) && cleanX(x_, y); } } $('#btn').click(function() { if (blnIE) { alert('Sorry, 暂不支持IE浏览器!'); } else if (!blnPlaying) { if (confirm('游戏已结束, 再玩一次?')) { init(); } } else if (confirm('确定结束计算总分吗? 点确定游戏将结束!')) { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0