@ -1,5 +0,0 @@ |
|||||
module.exports = { |
|
||||
port: 3000, |
|
||||
https: false, |
|
||||
// registry: 'https://registry.npm.taobao.org',
|
|
||||
} |
|
@ -0,0 +1,34 @@ |
|||||
|
const { task, series, parallel, src, dest, watch } = require('gulp'); |
||||
|
const babel = require('gulp-babel'); |
||||
|
const uglify = require('gulp-uglify'); |
||||
|
const concat = require('gulp-concat'); |
||||
|
const clean = require('gulp-clean'); |
||||
|
const livereload = require('gulp-livereload'); |
||||
|
|
||||
|
const cleanTask = function () { |
||||
|
return src('dist/*', { read: false }).pipe(clean()); |
||||
|
}; |
||||
|
|
||||
|
const script = function () { |
||||
|
return src('src/**/*.js') |
||||
|
.pipe(babel({ presets: ['@babel/env'] })) |
||||
|
.pipe(uglify()) |
||||
|
.pipe(concat('main.js')) |
||||
|
.pipe(dest('dist/')) |
||||
|
.pipe(livereload({ start: true, port: 3001, reloadPage: 'dist/index.html' })); |
||||
|
}; |
||||
|
|
||||
|
const copy = function () { |
||||
|
src('./public/index.html').pipe(dest('dist/')); |
||||
|
src('./public/tomato-right.js').pipe(dest('dist/')); |
||||
|
src('./public/images/*').pipe(dest('dist/images')); |
||||
|
src('./public/libs/**/*').pipe(dest('dist/libs')); |
||||
|
src('./public/sounds/*').pipe(dest('dist/sounds')); |
||||
|
}; |
||||
|
|
||||
|
const watchTask = function () { |
||||
|
livereload.listen(); |
||||
|
watch('src/*', script); |
||||
|
}; |
||||
|
|
||||
|
exports.default = parallel(copy, script, watchTask); |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 437 KiB |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 214 KiB |
Before Width: | Height: | Size: 128 KiB |
Before Width: | Height: | Size: 324 KiB |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 116 KiB |
Before Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 98 KiB |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 214 KiB |
Before Width: | Height: | Size: 128 KiB |
Before Width: | Height: | Size: 346 KiB |
Before Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 116 KiB |
Before Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 98 KiB |
@ -1,47 +0,0 @@ |
|||||
<!DOCTYPE html> |
|
||||
<html> |
|
||||
<head> |
|
||||
<meta charset="UTF-8"> |
|
||||
<meta name="authoring-tool" content="Adobe_Animate_CC"> |
|
||||
<title>tomato-right</title> |
|
||||
<style> |
|
||||
html {background-color: #000} |
|
||||
#animation_container, #_preload_div_ { |
|
||||
position:absolute; |
|
||||
margin:auto; |
|
||||
left:0;right:0; |
|
||||
top:0;bottom:0; |
|
||||
} |
|
||||
</style> |
|
||||
|
|
||||
<script src="libs/1.0.0/createjs.min.js"></script> |
|
||||
<script src="tomato-right.js"></script> |
|
||||
<script src="js/index.js"></script> |
|
||||
<script src="js/custom.js"></script> |
|
||||
<script src="js/classes/main.js"></script> |
|
||||
<script src="js/classes/count.js"></script> |
|
||||
<script src="js/classes/back.js"></script> |
|
||||
<script src="js/classes/time.js"></script> |
|
||||
<script src="js/classes/level.js"></script> |
|
||||
<script src="js/classes/sound.js"></script> |
|
||||
<script src="js/classes/end.js"></script> |
|
||||
<script src="js/test.js"></script> |
|
||||
|
|
||||
<!-- write your code here --> |
|
||||
</head> |
|
||||
<body onload="init();" style="margin:0px;"> |
|
||||
<div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:1280px; height:720px"> |
|
||||
<canvas id="canvas" width="1280" height="720" style="position: absolute; display: none; background-color:rgba(255, 255, 255, 1.00);"></canvas> |
|
||||
<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:1280px; height:720px; position: absolute; left: 0px; top: 0px; display: none;"> |
|
||||
</div> |
|
||||
</div> |
|
||||
<div id='_preload_div_' style='position:absolute; top:0; left:0; display: inline-block; height:720px; width: 1280px; text-align: center;'> <span style='display: inline-block; height: 100%; vertical-align: middle;'></span> <img src=images/_preloader.gif style='vertical-align: middle; max-height: 100%'/></div> |
|
||||
|
|
||||
<div style="position: fixed; top: 0; left: 0; z-index: 999;padding: 20px"> |
|
||||
<h3>测试功能区</h3> |
|
||||
<button onclick="Count.of()">开始倒计时</button> |
|
||||
<button onclick="timeInstance.start()">开始游戏</button> |
|
||||
<button>结束游戏</button> |
|
||||
</div> |
|
||||
</body> |
|
||||
</html> |
|
@ -1,31 +0,0 @@ |
|||||
// 音频处理类
|
|
||||
function Sound() { |
|
||||
this.lib = library; |
|
||||
|
|
||||
this.music = {}; |
|
||||
} |
|
||||
|
|
||||
Sound.of = function () { |
|
||||
const instance = new Sound(); |
|
||||
instance.init(); |
|
||||
return instance; |
|
||||
}; |
|
||||
|
|
||||
Sound.prototype.init = function () { |
|
||||
createjs.Sound.alternateExtensions = ['mp3']; |
|
||||
const sounds = [ |
|
||||
{ src: 'sounds/bgmMusic.mp3', id: 'bgm' }, |
|
||||
{ src: 'sounds/excitationMusic.mp3', id: 'excitation' }, |
|
||||
{ src: 'sounds/amazing.mp3', id: 'amazing' }, |
|
||||
{ src: 'sounds/unbelievable.mp3', id: 'unbelievable' }, |
|
||||
]; |
|
||||
createjs.Sound.addEventListener('fileload', function (event) { |
|
||||
console.log('event: ', event); |
|
||||
this.music[event.id] = createjs.Sound.createInstance(event.id); |
|
||||
}); |
|
||||
createjs.Sound.registerSounds(sounds, '../../'); |
|
||||
}; |
|
||||
|
|
||||
Sound.prototype.playBgm = function () { |
|
||||
this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
|
|
||||
}; |
|
@ -1,28 +0,0 @@ |
|||||
const config = { |
|
||||
count: 5, // 默认倒计时时长
|
|
||||
duration: 60, // 总时长 s
|
|
||||
level: 1, // 游戏难度级别
|
|
||||
total: 100, // 总分
|
|
||||
times: 20, // 动作次数
|
|
||||
}; |
|
||||
|
|
||||
let library = null; |
|
||||
let state = 0; // 游戏状态 0->未开始 1->进行中 2->结束
|
|
||||
|
|
||||
function initStage(lib) { |
|
||||
library = lib; |
|
||||
|
|
||||
window.main = Main.of(gameOver); // 初始化鸟等
|
|
||||
window.timeInstance = Time.of(gameOver); // 初始化游戏时间
|
|
||||
// window.soundInstance = Sound.of(); // 初始化音频
|
|
||||
Level.of(2); // 游戏难度级别
|
|
||||
Back.of(); // 返回按钮
|
|
||||
} |
|
||||
|
|
||||
// 游戏结束 显示结束得分面板
|
|
||||
function gameOver() { |
|
||||
state = 2; |
|
||||
const times = main.times; |
|
||||
const score = parseInt((config.total / config.times) * times); |
|
||||
End.of(score); |
|
||||
} |
|
@ -1,7 +0,0 @@ |
|||||
function test() { |
|
||||
document.addEventListener('click', () => { |
|
||||
main.play(); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
test(); |
|
@ -0,0 +1,29 @@ |
|||||
|
{ |
||||
|
"name": "bird-go-home", |
||||
|
"version": "1.0.0", |
||||
|
"description": "", |
||||
|
"main": ".svrxrc.js", |
||||
|
"scripts": { |
||||
|
"dev": "gulp" |
||||
|
}, |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "gitea@dd.tall.wiki:ccsens_fe/bird-go-home.git" |
||||
|
}, |
||||
|
"keywords": [], |
||||
|
"author": "", |
||||
|
"license": "ISC", |
||||
|
"devDependencies": { |
||||
|
"@babel/core": "^7.15.5", |
||||
|
"@babel/preset-env": "^7.15.6", |
||||
|
"gulp": "^4.0.2", |
||||
|
"gulp-babel": "^8.0.0", |
||||
|
"gulp-clean": "^0.4.0", |
||||
|
"gulp-concat": "^2.6.1", |
||||
|
"gulp-livereload": "^4.0.2", |
||||
|
"gulp-uglify": "^3.0.2" |
||||
|
}, |
||||
|
"dependencies": { |
||||
|
"vinyl-paths": "^4.0.0" |
||||
|
} |
||||
|
} |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 214 KiB After Width: | Height: | Size: 214 KiB |
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 470 KiB |
After Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
Before Width: | Height: | Size: 612 KiB After Width: | Height: | Size: 612 KiB |
@ -0,0 +1,37 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<!-- |
||||
|
NOTES: |
||||
|
1. All tokens are represented by '$' sign in the template. |
||||
|
2. You can write your code only wherever mentioned. |
||||
|
3. All occurrences of existing tokens will be replaced by their appropriate values. |
||||
|
4. Blank lines will be removed automatically. |
||||
|
5. Remove unnecessary comments before creating your template. |
||||
|
--> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta name="authoring-tool" content="Adobe_Animate_CC"> |
||||
|
<title>tomato-right</title> |
||||
|
<!-- write your code here --> |
||||
|
<style> |
||||
|
#animation_container, #_preload_div_ { |
||||
|
position:absolute; |
||||
|
margin:auto; |
||||
|
left:0;right:0; |
||||
|
top:0;bottom:0; |
||||
|
} |
||||
|
</style> |
||||
|
<script src="libs/1.0.0/createjs.min.js"></script> |
||||
|
<script src="tomato-right.js"></script> |
||||
|
<script src="main.js"></script> |
||||
|
<!-- write your code here --> |
||||
|
</head> |
||||
|
<body onload="init();" style="margin:0px;"> |
||||
|
<div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:1280px; height:720px"> |
||||
|
<canvas id="canvas" width="1280" height="720" style="position: absolute; display: none; background-color:rgba(255, 255, 255, 1.00);"></canvas> |
||||
|
<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:1280px; height:720px; position: absolute; left: 0px; top: 0px; display: none;"> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div id='_preload_div_' style='position:absolute; top:0; left:0; display: inline-block; height:720px; width: 1280px; text-align: center;'> <span style='display: inline-block; height: 100%; vertical-align: middle;'></span> <img src=images/_preloader.gif style='vertical-align: middle; max-height: 100%'/></div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,47 @@ |
|||||
|
/** |
||||
|
* 再玩一次类 |
||||
|
* @property {object} lib 库对象 |
||||
|
* @property {object} btnAgain 面板元素对象 |
||||
|
*/ |
||||
|
function Again() { |
||||
|
this.lib = library; |
||||
|
|
||||
|
this.btnAgain = null; |
||||
|
} |
||||
|
|
||||
|
Again.of = (function () { |
||||
|
let instance = null; |
||||
|
return function () { |
||||
|
if (!instance) { |
||||
|
instance = new Again(); |
||||
|
} |
||||
|
instance.init(); |
||||
|
return instance; |
||||
|
}; |
||||
|
})(); |
||||
|
|
||||
|
// 初始化
|
||||
|
Again.prototype.init = function () { |
||||
|
this.showAgainBtn(); |
||||
|
}; |
||||
|
|
||||
|
// 渲染背景面板
|
||||
|
Again.prototype.showAgainBtn = function () { |
||||
|
const lib = this.lib; |
||||
|
const btnAgain = new lib.btnAgain(); |
||||
|
btnAgain.x = lib.properties.width / 2; |
||||
|
btnAgain.y = lib.properties.height / 2 + 150; |
||||
|
this.btnAgain = btnAgain; |
||||
|
this.btnAgain.addEventListener( |
||||
|
'click', |
||||
|
function () { |
||||
|
if (config.mode === 0) { |
||||
|
againMessage(); |
||||
|
} else { |
||||
|
location.reload(); |
||||
|
} |
||||
|
}, |
||||
|
false, |
||||
|
); |
||||
|
stage.addChild(btnAgain); |
||||
|
}; |
@ -0,0 +1,47 @@ |
|||||
|
/** |
||||
|
* 演示模式类 |
||||
|
* @property {object} lib 库对象 |
||||
|
* @property {object} stopDemo 面板元素对象 |
||||
|
*/ |
||||
|
function Demo() { |
||||
|
this.lib = library; |
||||
|
|
||||
|
this.stopDemo = null; |
||||
|
} |
||||
|
|
||||
|
Demo.of = (function () { |
||||
|
let instance = null; |
||||
|
return function () { |
||||
|
if (!instance) { |
||||
|
instance = new Demo(); |
||||
|
} |
||||
|
instance.init(); |
||||
|
return instance; |
||||
|
}; |
||||
|
})(); |
||||
|
|
||||
|
// 初始化
|
||||
|
Demo.prototype.init = function () { |
||||
|
this.showStopDemo(); |
||||
|
}; |
||||
|
|
||||
|
// 显示演示模式按钮
|
||||
|
Demo.prototype.showStopDemo = function () { |
||||
|
const lib = this.lib; |
||||
|
const stopDemo = new lib.stopDemo(); |
||||
|
stopDemo.x = 50; |
||||
|
stopDemo.y = lib.properties.height - 100; |
||||
|
this.stopDemo = stopDemo; |
||||
|
// 关闭演示模式
|
||||
|
this.stopDemo.addEventListener( |
||||
|
'click', |
||||
|
function () { |
||||
|
stage.removeChild(stopDemo); |
||||
|
location.hash = ''; |
||||
|
location.reload(); |
||||
|
isDemo = false; |
||||
|
}, |
||||
|
false, |
||||
|
); |
||||
|
stage.addChild(stopDemo); |
||||
|
}; |
@ -0,0 +1,47 @@ |
|||||
|
// 音频处理类;
|
||||
|
function Sound() { |
||||
|
this.lib = library; |
||||
|
|
||||
|
this.music = {}; |
||||
|
} |
||||
|
|
||||
|
Sound.of = (function () { |
||||
|
let instance = null; |
||||
|
return function () { |
||||
|
if (!instance) { |
||||
|
instance = new Sound(); |
||||
|
} |
||||
|
instance.init(); |
||||
|
return instance; |
||||
|
}; |
||||
|
})(); |
||||
|
|
||||
|
Sound.prototype.init = function () { |
||||
|
createjs.Sound.alternateExtensions = ['mp3']; |
||||
|
const sounds = [{ src: 'sounds/bgmMusic.mp3', id: 'bgm' }]; |
||||
|
const _this = this; |
||||
|
createjs.Sound.addEventListener('fileload', function (event) { |
||||
|
_this.music[event.id] = createjs.Sound.createInstance(event.id); |
||||
|
}); |
||||
|
createjs.Sound.registerSounds(sounds, './'); |
||||
|
this.playBgm(); |
||||
|
}; |
||||
|
|
||||
|
Sound.prototype.playBgm = function () { |
||||
|
this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
|
||||
|
}; |
||||
|
|
||||
|
// let music = {};
|
||||
|
// function initSound() {
|
||||
|
// createjs.Sound.alternateExtensions = ['mp3'];
|
||||
|
// const sounds = [
|
||||
|
// { src: 'public/sounds/bgmMusic.mp3', id: 'bgm' },
|
||||
|
// { src: 'public/sounds/excitationMusic.mp3', id: 'excitation' },
|
||||
|
// { src: 'public/sounds/amazing.mp3', id: 'amazing' },
|
||||
|
// { src: 'public/sounds/unbelievable.mp3', id: 'unbelievable' },
|
||||
|
// ];
|
||||
|
// createjs.Sound.addEventListener('fileload', function (event) {
|
||||
|
// music[event.id] = createjs.Sound.createInstance(event.id);
|
||||
|
// });
|
||||
|
// createjs.Sound.registerSounds(sounds, '../../');
|
||||
|
// }
|
@ -0,0 +1,55 @@ |
|||||
|
/** |
||||
|
* 暂停游戏类(暂停继续游戏) |
||||
|
* @property {object} lib 库对象 |
||||
|
* @property {object} suspend 面板元素对象 |
||||
|
*/ |
||||
|
function Suspend() { |
||||
|
this.lib = library; |
||||
|
|
||||
|
this.suspend = null; |
||||
|
} |
||||
|
|
||||
|
Suspend.of = (function () { |
||||
|
let instance = null; |
||||
|
return function () { |
||||
|
if (!instance) { |
||||
|
instance = new Suspend(); |
||||
|
} |
||||
|
instance.init(); |
||||
|
return instance; |
||||
|
}; |
||||
|
})(); |
||||
|
|
||||
|
// 初始化
|
||||
|
Suspend.prototype.init = function () { |
||||
|
this.suspendGame(); |
||||
|
}; |
||||
|
|
||||
|
// 暂停游戏按钮
|
||||
|
Suspend.prototype.suspendGame = function () { |
||||
|
// const lib = this.lib;
|
||||
|
const suspend = new this.lib.suspend(); |
||||
|
suspend.x = 50; |
||||
|
suspend.y = this.lib.properties.height - 100; |
||||
|
this.suspend = suspend; |
||||
|
const _this = this; |
||||
|
// 继续游戏
|
||||
|
this.suspend.addEventListener( |
||||
|
'click', |
||||
|
function () { |
||||
|
_this.hide(); |
||||
|
continueMessage(); |
||||
|
}, |
||||
|
false, |
||||
|
); |
||||
|
// stage.addChild(this.suspend);
|
||||
|
// stage.removeChild(this.suspend);
|
||||
|
}; |
||||
|
|
||||
|
Suspend.prototype.hide = function () { |
||||
|
stage.removeChild(this.suspend); |
||||
|
}; |
||||
|
|
||||
|
Suspend.prototype.show = function () { |
||||
|
stage.addChild(this.suspend); |
||||
|
}; |
@ -0,0 +1,57 @@ |
|||||
|
const config = { |
||||
|
count: 5, // 默认倒计时时长
|
||||
|
duration: 60, // 总时长 s
|
||||
|
total: 100, // 总分
|
||||
|
times: 15, // 动作次数
|
||||
|
level: 1, // 游戏难度级别
|
||||
|
mode: 1, // 模式 0-> 正常模式 1-> 演示模式
|
||||
|
currentScore: 0, // 当前得分
|
||||
|
currentTimes: 0, // 当前次数
|
||||
|
config: { |
||||
|
scores: [ |
||||
|
{ direction: 0, score: 5 }, |
||||
|
{ direction: 1, score: 10 }, |
||||
|
{ direction: 2, score: 8 }, |
||||
|
], |
||||
|
directions: [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2, 2], |
||||
|
}, // 得分配置
|
||||
|
}; |
||||
|
|
||||
|
let library = null; |
||||
|
let state = 0; // 游戏状态 0->未开始 1->进行中 2->结束 3->暂停
|
||||
|
let isDemo = false; // 是不是演示模式
|
||||
|
let leftDuration = null; // 暂停时的时间
|
||||
|
|
||||
|
function initStage(lib) { |
||||
|
library = lib; |
||||
|
|
||||
|
window.main = Main.of(gameOver); // 初始化鸟等
|
||||
|
window.timeInstance = Time.of(gameOver); // 初始化游戏时间
|
||||
|
window.soundInstance = Sound.of(); // 初始化音频
|
||||
|
|
||||
|
Level.of(config.level); // 游戏难度级别
|
||||
|
Back.of(); // 返回按钮
|
||||
|
isHash(); |
||||
|
window.suspend = Suspend.of(); |
||||
|
|
||||
|
window.addEventListener( |
||||
|
'click', |
||||
|
function () { |
||||
|
if (!window.soundInstance) return; |
||||
|
window.soundInstance.playBgm(); |
||||
|
}, |
||||
|
false, |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
// 游戏结束 显示结束得分面板
|
||||
|
function gameOver() { |
||||
|
state = 2; |
||||
|
const times = main.times; |
||||
|
setTimeout(() => { |
||||
|
End.of(config.currentScore || 0); |
||||
|
if (config.mode === 0) { |
||||
|
finishMessage(config.currentScore, times); |
||||
|
} |
||||
|
}, 2000); |
||||
|
} |
@ -0,0 +1,131 @@ |
|||||
|
window.addEventListener( |
||||
|
'message', |
||||
|
function (e) { |
||||
|
const res = e.data; |
||||
|
console.log('子->接受: ', res); |
||||
|
switch (res.event) { |
||||
|
case 'start': |
||||
|
startGame(res.data); |
||||
|
return; |
||||
|
case 'play': |
||||
|
playGame(res.data); |
||||
|
return; |
||||
|
case 'pause': |
||||
|
pauseGame(res.data); |
||||
|
return; |
||||
|
case 'continue': |
||||
|
continueGame(res.data); |
||||
|
return; |
||||
|
default: |
||||
|
finishGame(res.data); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
function startGame(data) { |
||||
|
if (state === 2) { |
||||
|
location.reload(); |
||||
|
return; |
||||
|
} |
||||
|
const { count, game, status, param } = data; |
||||
|
config.count = count.duration; |
||||
|
config.duration = game.duration; |
||||
|
config.total = game.totalScore; |
||||
|
config.times = game.totalTimes; |
||||
|
config.level = game.level; |
||||
|
config.config = game.config; |
||||
|
config.mode = game.mode; |
||||
|
|
||||
|
window.timeInstance.setDuration(game.duration); |
||||
|
Level.of(config.level); |
||||
|
if (config.mode === 0) { |
||||
|
// 开始倒计时
|
||||
|
Count.of(countOver); |
||||
|
} else { |
||||
|
sevenClick(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function playGame(data) { |
||||
|
if (state !== 1) return; |
||||
|
const { status, param } = data; |
||||
|
console.log('param: ', param); |
||||
|
// config.currentScore = score;
|
||||
|
// config.currentTimes = times;
|
||||
|
state = status; |
||||
|
if (config.config.directions[config.currentTimes] === param.direction) { |
||||
|
main.play(param.direction); |
||||
|
} else { |
||||
|
alert('动作不匹配'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function pauseGame(data) { |
||||
|
if (state !== 1) return; |
||||
|
state = data.status; |
||||
|
window.suspend.show(); |
||||
|
window.timeInstance.pause(); |
||||
|
} |
||||
|
|
||||
|
function continueGame(data) { |
||||
|
if (state !== 3) return; |
||||
|
state = data.status; |
||||
|
window.suspend.hide(); |
||||
|
window.timeInstance.start(); |
||||
|
} |
||||
|
|
||||
|
function finishGame(data) { |
||||
|
const { score, times, status, param } = data; |
||||
|
state = status; |
||||
|
// config.total = score;
|
||||
|
// config.times = times;
|
||||
|
End.of(score || 0); |
||||
|
window.timeInstance.setDuration(0); |
||||
|
} |
||||
|
}, |
||||
|
false, |
||||
|
); |
||||
|
|
||||
|
// 发消息
|
||||
|
function sendMessage(data) { |
||||
|
if (!data) { |
||||
|
return alert('错误: 发送消息数据为空'); |
||||
|
} |
||||
|
console.log('子->发送: ', data); |
||||
|
top.postMessage(data, document.referrer); |
||||
|
} |
||||
|
|
||||
|
// 发送继续游戏消息
|
||||
|
function continueMessage() { |
||||
|
const data = { |
||||
|
event: 'continue', |
||||
|
data: { |
||||
|
status: 1, // 1 -> 进行中
|
||||
|
}, |
||||
|
}; |
||||
|
sendMessage(data); |
||||
|
} |
||||
|
|
||||
|
// 发送游戏结束消息
|
||||
|
function finishMessage(score, times) { |
||||
|
const data = { |
||||
|
event: 'finish', |
||||
|
data: { |
||||
|
score: score, // 得分
|
||||
|
times: times, // 次数
|
||||
|
status: 2, // 游戏状态 0 1 2
|
||||
|
param: {}, // 额外个性化参数
|
||||
|
}, |
||||
|
}; |
||||
|
sendMessage(data); |
||||
|
} |
||||
|
|
||||
|
// 发送再来一次消息
|
||||
|
function againMessage() { |
||||
|
const data = { |
||||
|
event: 'again', |
||||
|
data: { |
||||
|
param: {}, // 额外个性化参数
|
||||
|
}, |
||||
|
}; |
||||
|
sendMessage(data); |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
// 判断是否在演示模式 能否直接开始游戏
|
||||
|
function isHash() { |
||||
|
if (location.hash && location.hash === '#p') { |
||||
|
isDemo = true; |
||||
|
Demo.of(); |
||||
|
Count.of(countOver); |
||||
|
} else { |
||||
|
// 连点7次触发倒计时
|
||||
|
startGame(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function startGame() { |
||||
|
var count = 0, |
||||
|
timer; |
||||
|
document.onclick = function () { |
||||
|
if (isDemo || config.mode !== 1) return; |
||||
|
if (count < 6) { |
||||
|
if (timer) { |
||||
|
clearTimeout(timer); |
||||
|
} |
||||
|
count++; |
||||
|
timer = setTimeout(function () { |
||||
|
count = 0; |
||||
|
}, 300); |
||||
|
} else if (count === 6) { |
||||
|
count = 0; |
||||
|
clearTimeout(timer); |
||||
|
sevenClick(); |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
function sevenClick() { |
||||
|
isDemo = true; |
||||
|
Count.of(countOver); |
||||
|
addHash(); |
||||
|
} |
||||
|
|
||||
|
// 倒计时结束 开始游戏
|
||||
|
function countOver() { |
||||
|
timeInstance.start(); |
||||
|
} |
||||
|
|
||||
|
// 添加hash值
|
||||
|
function addHash() { |
||||
|
location.hash = '#p'; |
||||
|
Demo.of(); |
||||
|
} |
||||
|
|
||||
|
function test() { |
||||
|
document.addEventListener('click', () => { |
||||
|
if (!isDemo) return; |
||||
|
main.play(config.config.directions[config.currentTimes]); |
||||
|
}); |
||||
|
} |
||||
|
test(); |