From e480435aa456b6d2d9e0774a6336c7ad9cf7e6b0 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 6 May 2021 11:27:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A3=80=E6=9F=A5=E6=89=80?= =?UTF-8?q?=E6=9C=89=E4=BA=BA=E6=98=AF=E5=90=A6=E9=83=BD=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E7=AD=94=E4=BA=86=E5=BD=93=E5=89=8D=E9=A2=98=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/GameLogic.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) 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')