-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
468 lines (349 loc) · 12.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<!DOCTYPE html>
<html><head>
<meta charset="utf-8"/>
<title>Tom and Jerry</title>
<meta name="viewport" content="width=device-width, initial-scale=1,target-densitydpi=device-dpi,user-scalable=no"/>
<style>
@font-face {
font-family: 'duboxregular';
src: url('fonts/dubox.eot');
src: url('fonts/dubox.eot?#iefix') format('embedded-opentype'),
url('fonts/dubox.woff') format('woff'),
url('fonts/dubox.ttf') format('truetype'),
url('fonts/dubox.svg#duboxregular') format('svg');
font-weight: normal;
font-style: normal;
}
html{background:#999;}
html,body{margin:0 auto;padding:0;width:100%;height:100px;overflow:hidden;}
*{-webkit-user-select:none;-moz-user-select:none;user-select:none;-o-user-select:none;-ms-user-select:none;}
#_grib {position: absolute;right:0;height:340px;border:solid 0px #000;font-family: 'duboxregular';}
#_grib div{position:absolute;border:solid 0px #000;}
div{padding:0;text-align:center;}
</style>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js1"></script>
<script src="js/WeixinApi.js"></script>
</head>
<body style="position: relative;background:#e9e9e9;display:block;">
<script type="text/javascript">
(Easouunion = window.Easouunion || {}).config = {
publisher:'8297_659',
style:2
};
</script>
<script type="text/javascript" src="http://assets.easou.com/union/easou-union.js"></script>
<!-- 横屏模式
<div id="_ctrl" style="position: absolute;left:0;bottom:0;width:200px;height:500px;">
<div id="_hummer" style="width:200px;height:250px;background:red;"></div>
<div id="_fish" style="width:200px;height:250px;background:green;"></div>
</div>
-->
<div id="game_area" style="width:100%;position: absolute;left:0;bottom:0;">
<!-- 竖屏模式 -->
<div id="_ctrl" style="position: absolute;left:0;bottom:0;width:100%;font-family: 'duboxregular';">
<div id="_hummer" style="float:left;width:50%;height:100%;text-align:center;"></div>
<div id="_fish" style="float:left;width:50%;height:100%;text-align:center;"></div>
</div>
<div id="_grib"></div>
</div>
<script>
if($(window).height()<$(window).width()){
$('body').height($(window).height());
$('body').width($(window).height()*9/16);
}else{
$('body').height($(window).height());
$('body').width($(window).width());
}
$('#game_area').height($('body').height()-50);
var game_w = $('#game_area').width();
var game_h = $('#game_area').height();
function cat_mouse(option){
var this1 = this;
var _grib_obj = $("#"+option.id);
var row = option.row; //
var cos = option.cos;
var countBlock = row*cos;
var ctrl = option.ctrl;
this1.showTime = option.showTime; //mouse or cat 出现的间隔时间(初始的)
this1.hideTime = option.hideTime; //mouse or cat 消失的等待时间(初始的)
this1.catOdds = option.catOdds; //cat 出现的概率(初始的 ,用小数表示)
this1.showTimeV = option.showTimeV; //mouse or cat 出现的间隔时间的增量
this1.hideTimeV = option.hideTimeV; //mouse or cat 消失的等待时间的增量
this1.catOddsV = option.catOddsV; //cat 出现的概率的增量
this1.countM = 0; //mouse的总数
this1.countC = 0; //cat的总数
this1.score = 0; //打到mouse的数量
this1._mouseHtml = option._mouseHtml;
this1._catHtml = option._catHtml;
this1._ctrl = false; //false _fish _hummer 当前道具
//计算网格大小
var _win_width,_win_height;
_win_width = game_w;
_win_height = game_h;
if(_win_width > _win_height){
_grib_obj.width(_win_height);
_grib_obj.height(_win_height);
}else{
_grib_obj.width(_win_width);
_grib_obj.height(_win_width);
}
//创建网格
this1.createBlock = function (row,cos){
//
var _gribW = _grib_obj.width();
var _gribH = _grib_obj.height();
//格子的尺寸 亦作为格子的大小
var BlockW = this1.BlockW = _gribW/cos;
var BlockH = _gribH/row;
//清除所有格子
_grib_obj.children().remove();
//生成格子
for(var j=0;j<row;j++){
for(var i=0;i<cos;i++){
_grib_obj.append('<div style="top:'+j*BlockH+'px;left:'+i*BlockW+'px;width:'+BlockW+'px;height:'+BlockH+'px;"></div>');
}
}
}
this1._mouse = function(){
var this2 = this;
this2._m = $(this1._mouseHtml);
this2._m.addClass('_mouse');
this2._m.bind('touchstart',function(){
if(this1._ctrl == '_hummer'){ //当前道具为_hummer 即打中
this2._m.remove(); //隐藏当前_mouse
this2._m = false;
this1.score++; //得分加1
$('#_score').html(this1.score); //更新得分显示
}
});
_grib_obj.children().eq(Math.round(Math.random()*(countBlock-1))).html(this2._m);
this2._hide = setTimeout(function(){
if(this2._m){ //没打到 则更新hide等待时间
this1.hideTime += this1.hideTimeV;
this2._m.remove();
this2._m = false;
$('#_lost').html(parseInt($('#_lost').html())+1);
}
},this1.hideTime);
}
this.hummered = function(){
this1.score++; //得分加1
$('#_score').html(this1.score); //更新得分显示
}
this._cat = function(){
this._c = $(this1._catHtml);
this._c.addClass('_cat');
this._c.bind('touchstart',function(){
if(this1._ctrl == '_fish'){ //当前道具为 _fish
var now_mouse_num = $('._mouse').size();
this1.score += now_mouse_num; //得分加上当前mouse的数量
$('._mouse').remove(); //消灭当前所有 mouse
this1.catOdds += this1.catOddsV; //更新 catOdds (增加)
//补偿隐藏等待时间(因为这里不能将 this2._m = false;)
this1.hideTime -= (this1.hideTimeV*now_mouse_num);
this2._c.remove();
this2._c = false;
$('#_score').html(this1.score); //更新得分显示
}else{ //用错道具
this1.catOdds -= this1.catOddsV; //更新 catOdds (减少)
this2._c.remove();
this2._c = false;
}
});
_grib_obj.children().eq(Math.round(Math.random()*(countBlock-1))).html(this._c);
var this2 = this;
setTimeout(function(){
if(this2._c){
this2._c.remove();
this2._c = false;
}
},this1.hideTime);
}
//监听控制按钮
this1.set_ctrl = function(){
for(var i in ctrl){
$('#'+ctrl[i])[0].addEventListener('touchstart',function(e){ //addEventListener
this1._ctrl = $(this).attr('id');
});
$('#'+ctrl[i])[0].addEventListener('touchmove',function(e){ //addEventListener
this1._ctrl = $(this).attr('id');
});
$('#'+ctrl[i])[0].addEventListener('touchend',function(e){ //addEventListener
this1._ctrl = false;
});
}
}
//定时出现 mouse and cat
this1._go = function(){
var goT = setTimeout(function(){
this1.gameover(); //监听game over
//随机选择出现 mouse or cat
if(Math.random() > this1.catOdds){
new this1._mouse();
this1.countM++; //统计mouse的总数
}else{
new this1._cat();
this1.countC++;
}
//更新 showTime
this1.showTime += this1.showTimeV;
this1._go();
},this1.showTime);
}
this1.gameover = function(callback){
if(this1.countM - this1.score >= row*cos*2){
this1._go = function(){};
$('._mouse').remove();
$('._cat').remove();
//$('#au_end')[0].play(); //播放结束音乐
setTimeout(function(){
share(this1.score);
_alert({title:'Game Over',ok:'再玩一次'},'<h2>哈哈!您消灭了'+this1.score+'只Jerry,点击右上角菜单将战绩分享到朋友圈...</h2>',game_start);
},0);
}
}
this1.init = function(){
window.addEventListener('touchstart', function(e){e.preventDefault();});
window.addEventListener('touchmove', function(e){e.preventDefault();});
window.addEventListener('touchend', function(e){e.preventDefault();});
this1.createBlock(row,cos);
this1._go();
this1.set_ctrl();
}
}
var game_start = function (){
$('#_score').html('0');
var cm = new cat_mouse({'id':'_grib','ctrl':['_fish','_hummer'],'row':4,'cos':4,'showTime':500,'hideTime':2000,'catOdds':0.1,'showTimeV':-5,'hideTimeV':-0.1,'catOddsV':0.02,'_catHtml':'<div style="width:100%;height:100%;"></div>','_mouseHtml':'<div style="width:100%;height:100%;"></div>'});
cm.init();
$('#_grib').css('font-size',cm.BlockW+'px');
$('#au_start')[0].pause();
}
$(function(){
// 控制区
if(game_w/2 < (game_h - game_w)){
$('#_ctrl').height(game_w/2);
$('#_ctrl').css('font-size',game_w/2+'px');
}else{
$('#_ctrl').height((game_h - game_w));
$('#_ctrl').css('font-size',(game_h - game_w)+'px');
}
/*
$('#_hummer,#_fish').bind('touchstart',function(e){ //addEventListener
e.preventDefault();
$(this).css('background','green');
}).bind('touchend',function(e){ //addEventListener
e.preventDefault();
$(this).css('background','');
});
*/
//插入记分牌
$('#_ctrl').before('<div id="_score" style="position: absolute;left:0;text-align:center;color:#aaa;font-size:200px;width:100%;"></div>');
$('#_score').height(game_w);
//音效
$('#_grib').bind('touchstart',function(){
//$('#au_single'+Math.floor(Math.random()*(8)+1))[0].play();
});
});
_alert({title:'Tom and Jerry',ok:'开始'},'<h1>玩法:</h1><h3>按住锤子打Jerry,按住鱼喂Tom。<br/>就这么简单!</h3>',game_start);
function _alert(opt,msg,fn_yes,fn_no){
var _dialog = '<div role="dialog" class="ui-dialog-contain ui-overlay-shadow ui-corner-all">'
+'<div data-role="header" data-theme="b" role="banner" class="ui-header ui-bar-b"><a href="#" class="ui-corner-all ui-btn-icon-notext ui-btn-left" data-rel="back"></a>'
+'<h1 class="ui-title" role="heading" aria-level="1">'+opt.title+'</h1>'
+'</div>'
+'<div role="main" class="ui-content" style="background:#fff;">'
+msg
+' <a id="_ok" class="ui-btn ui-shadow ui-corner-all ui-btn-a">'+opt.ok+'</a>';
if(fn_no){
_dialog += ' <a id="_cancel" class="ui-btn ui-shadow ui-corner-all ui-btn-a">'+opt.cancel+'</a>';
}
_dialog += '</div>';
_dialog += '</div>';
this._dialogObj = $(_dialog);
var this1 = this;
this1._dialogObj.find('#_ok').bind('touchend',function(){
if(fn_yes){
fn_yes();
}
this1._dialogObj.remove();
});
if(opt.cancel){
this1._dialogObj.find('#_cancel').bind('touchend',function(){
if(fn_no){
fn_no();
}
this1._dialogObj.remove();
});
}
$('body').append(this1._dialogObj);
}
</script>
<!--
<div id="audios" style="display:none;">
<audio id="au_start" src="audio/start.mp3" autoplay loop></audio>
<audio id="au_end" src="audio/end.mp3" preload></audio>
<audio id="au_single1" src="audio/single1.mp3" preload></audio>
<audio id="au_single2" src="audio/single2.mp3" preload></audio>
<audio id="au_single3" src="audio/single3.mp3" preload></audio>
<audio id="au_single4" src="audio/single4.mp3" preload></audio>
<audio id="au_single5" src="audio/single5.mp3" preload></audio>
<audio id="au_single6" src="audio/single6.mp3" preload></audio>
<audio id="au_single7" src="audio/single7.mp3" preload></audio>
<audio id="au_single8" src="audio/single8.mp3" preload></audio>
</div>
-->
<script>
// 微信分享的数据
window.wxData = {
"appId": "", // 服务号可以填写appId
"imgUrl":'http://www.dubox.org/apps/cat-mouse/icon.jpg',
"link":'http://www.dubox.org/apps/cat-mouse',
"desc":"Tom and Jerry 来咱村儿啦!!!",
"title":"Tom and Jerry 来咱村儿啦!!!"
};
function share(score){
window.wxData.desc = '哈哈!!我消灭了'+score+'只Jerry,不服气就来挑战吧!';
};
WeixinApi.ready(function(Api) {
// 分享的回调
var wxCallbacks = {
ready : function() {
//
},
cancel : function(resp) {
},
fail : function(resp) {
},
confirm : function(resp) {
},
all : function(resp) {
}
};
Api.shareToFriend(wxData, wxCallbacks);
Api.shareToTimeline(wxData, wxCallbacks);
Api.shareToWeibo(wxData, wxCallbacks);
});
</script>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://tongji.bl.ee/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 2]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="http://tongji.bl.ee/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
<div title="百度统计" style="display:none;">
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F5750e3c374836eb0ee5670c83a5931d5' type='text/javascript'%3E%3C/script%3E"));
</script>
</div>
</body></html>