diff --git a/src/services/GameLogic.ts b/src/services/GameLogic.ts index e907d54..5e7558d 100644 --- a/src/services/GameLogic.ts +++ b/src/services/GameLogic.ts @@ -1,5 +1,6 @@ import { - beginGame, closeRoom, + beginGame, + closeRoom, endGame, sendQuestion, updateRound, @@ -34,15 +35,22 @@ export function transformRecord(records: any[]) { }) } +/** + * 检查是否所有人都已经答了当前题目 + * + * @param history + * @param {string} qid + * @return {boolean} + */ export function checkSubFinish(history: any, qid: string) { - let count = 0 for (let [key, val] of history.members) { - if (val.answer?.has(qid)) { - count ++ + if (!val.answer?.has(qid)) { + return false } } - return count >= history.questions.length; + return true } + /** * 开始游戏 * @param {string} roomId @@ -81,9 +89,9 @@ export async function sendOneQuestion(history: any) { qdata.no = history.current await updateRound(roomId, history.current) await sendQuestion(roomId, qdata) - history.current ++ + history.current++ await history.save() - new Schedule().beginSchedule(BaseConst.MATCH_ANSWER_TIME, async function (){ + new Schedule().beginSchedule(BaseConst.MATCH_ANSWER_TIME, async function () { let subHistory = await PuzzleSession.findById(history.id) let datas = [] for (let [accountid, data] of subHistory.members) { @@ -91,7 +99,7 @@ export async function sendOneQuestion(history: any) { data.answer.set(qid, 0) data.errorCount++ data.comboCount = 0 - datas.push({accountid, score: -1}) + datas.push({ accountid, score: -1 }) } } subHistory.markModified('members')