游戏开始后,第一题增加延迟, 游戏结束后,延迟关闭房间

This commit is contained in:
zhl 2021-04-30 14:05:40 +08:00
parent 7fb1ed3a5f
commit a0bf2797b6
3 changed files with 34 additions and 3 deletions

View File

@ -4,4 +4,8 @@ export class BaseConst{
public static readonly RANK_SCORE = 'rank_score'
// 多人答题时间
public static readonly MATCH_ANSWER_TIME = 10000
// 游戏结束后房间自动解散时间
public static readonly ROOM_AUTO_CLOSE_TIME = 100000
// 第一题延后发送时间
public static readonly FIST_QUESTION_DELAY = 2000
}

View File

@ -1,5 +1,5 @@
import {
beginGame,
beginGame, closeRoom,
endGame,
sendQuestion,
updateRound,
@ -27,7 +27,8 @@ export function transformRecord(records: any[]) {
title: o.question,
answers,
type: 1,
category: type + '-' + subType
category: type + '-' + subType,
quality: o.quality
}
})
}
@ -52,7 +53,10 @@ export async function startGame(roomId: string, history: any) {
let records = await Puzzle.randomQuestions({}, history.total)
history.questions = records.map(o => o._id)
await history.save()
await sendOneQuestion(history)
new Schedule().beginSchedule(BaseConst.FIST_QUESTION_DELAY, async function () {
await sendOneQuestion(history)
}, history.scheduleKey)
}
export async function sendOneQuestion(history: any) {
@ -63,6 +67,9 @@ export async function sendOneQuestion(history: any) {
history.status = 9
await history.save()
await endGame(roomId, {})
new Schedule().beginSchedule(BaseConst.ROOM_AUTO_CLOSE_TIME, async function () {
await closeRoom(roomId)
}, history.scheduleKey + '_close')
return
}

View File

@ -64,6 +64,26 @@ export async function kickClient(roomId, clientId) {
})
}
/**
*
* @param roomId
* @return {Promise<AxiosResponse<any>>}
*/
export async function closeRoom(roomId) {
console.log(`close room: ${roomId}`)
const url = `${apiBase}/room/call`
const args = []
const data = {
roomId,
method: 'disconnect',
args: JSON.stringify(args)
}
return axios.post(url, data)
.then(res => {
return res.data
})
}
/**
*
* @param roomId