|
@ -10,7 +10,7 @@ |
|
|
* @property {number} times 当前运动次数 play依次+1 |
|
|
* @property {number} times 当前运动次数 play依次+1 |
|
|
* @property {function} endCallback 结束后 调用的回调函数 |
|
|
* @property {function} endCallback 结束后 调用的回调函数 |
|
|
*/ |
|
|
*/ |
|
|
function Bird(endCallback, max) { |
|
|
function Main(endCallback, max) { |
|
|
this.lib = library; |
|
|
this.lib = library; |
|
|
|
|
|
|
|
|
this.element = null; |
|
|
this.element = null; |
|
@ -26,15 +26,15 @@ function Bird(endCallback, max) { |
|
|
* @param {function} endCallback 游戏结束的回调函数 |
|
|
* @param {function} endCallback 游戏结束的回调函数 |
|
|
* @param {number} max 最多运动次数 |
|
|
* @param {number} max 最多运动次数 |
|
|
*/ |
|
|
*/ |
|
|
Bird.of = function (endCallback, max = config.times) { |
|
|
Main.of = function (endCallback, max = config.times) { |
|
|
const instance = new Bird(endCallback, max); |
|
|
const instance = new Main(endCallback, max); |
|
|
instance.init(); |
|
|
instance.init(); |
|
|
return instance; |
|
|
return instance; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 初始方法
|
|
|
// 初始方法
|
|
|
Bird.prototype.init = function () { |
|
|
Main.prototype.init = function () { |
|
|
const target = new this.lib.Bird(); |
|
|
const target = new this.lib.Main(); |
|
|
this.element = target; |
|
|
this.element = target; |
|
|
stage.addChild(target); |
|
|
stage.addChild(target); |
|
|
}; |
|
|
}; |
|
@ -43,7 +43,7 @@ Bird.prototype.init = function () { |
|
|
// 限制了两次动作间隔时间不能少于2s
|
|
|
// 限制了两次动作间隔时间不能少于2s
|
|
|
// 游戏状态在进行中才能触发
|
|
|
// 游戏状态在进行中才能触发
|
|
|
// play次数 >= 最多完成次数 调用结束的callback
|
|
|
// play次数 >= 最多完成次数 调用结束的callback
|
|
|
Bird.prototype.play = function () { |
|
|
Main.prototype.play = function () { |
|
|
if (Date.now() - this.prevTime <= 2000 || state !== 1) return; |
|
|
if (Date.now() - this.prevTime <= 2000 || state !== 1) return; |
|
|
this.element.play(); |
|
|
this.element.play(); |
|
|
this.times += 1; |
|
|
this.times += 1; |