|
@ -1,4 +1,5 @@ |
|
|
import { game } from './config'; |
|
|
import { game } from './config'; |
|
|
|
|
|
|
|
|
const { count, game: gameDuration, level, scores, directions, totalScore, totalTimes } = game; |
|
|
const { count, game: gameDuration, level, scores, directions, totalScore, totalTimes } = game; |
|
|
|
|
|
|
|
|
let currentScore = 0; // 当前得分
|
|
|
let currentScore = 0; // 当前得分
|
|
@ -74,17 +75,17 @@ const createFinishData = (score=currentScore, times=currentTimes) => { |
|
|
const createPlayData = (direction= 0) => { |
|
|
const createPlayData = (direction= 0) => { |
|
|
let data = null; |
|
|
let data = null; |
|
|
if (validatePlayCode(direction, currentTimes)) { // 动作正确
|
|
|
if (validatePlayCode(direction, currentTimes)) { // 动作正确
|
|
|
currentTimes += 1; |
|
|
// currentTimes += 1;
|
|
|
const directionTarget = scores.find(item => item.direction === direction); |
|
|
// const directionTarget = scores.find(item => item.direction === direction);
|
|
|
if (!directionTarget) { |
|
|
// if (!directionTarget) {
|
|
|
alert('配置信息有误, 未找到事件分值') |
|
|
// alert('配置信息有误, 未找到事件分值')
|
|
|
} |
|
|
// }
|
|
|
currentScore += directionTarget.score |
|
|
// currentScore += directionTarget.score
|
|
|
data = { |
|
|
data = { |
|
|
event: "play", |
|
|
event: "play", |
|
|
data: { |
|
|
data: { |
|
|
score: currentScore, // 得分
|
|
|
// score: currentScore, // 得分
|
|
|
times: currentTimes, // 次数
|
|
|
// times: currentTimes, // 次数
|
|
|
status: 1, // 游戏状态 0 1 2
|
|
|
status: 1, // 游戏状态 0 1 2
|
|
|
param: { |
|
|
param: { |
|
|
direction, // 0 1 2 3 4 5 共6中事件参数
|
|
|
direction, // 0 1 2 3 4 5 共6中事件参数
|
|
@ -123,6 +124,16 @@ export const creatData = (eventType, ...args) => { |
|
|
return data; |
|
|
return data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 接受play消息 并设置当前动作执行次数与分值 |
|
|
|
|
|
* 也就是说分值 次数由游戏来维护 |
|
|
|
|
|
* @param {*} data |
|
|
|
|
|
*/ |
|
|
|
|
|
export function onPlayMessage(data) { |
|
|
|
|
|
currentTimes = data.currentTimes; |
|
|
|
|
|
currentScore = data.currentScore; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 验证code是否是当前应该执行的动作代码 |
|
|
* 验证code是否是当前应该执行的动作代码 |
|
|
* @param code |
|
|
* @param code |
|
|