游戏开始后,第一题增加延迟, 游戏结束后,延迟关闭房间
This commit is contained in:
parent
7fb1ed3a5f
commit
a0bf2797b6
@ -4,4 +4,8 @@ export class BaseConst{
|
|||||||
public static readonly RANK_SCORE = 'rank_score'
|
public static readonly RANK_SCORE = 'rank_score'
|
||||||
// 多人答题时间
|
// 多人答题时间
|
||||||
public static readonly MATCH_ANSWER_TIME = 10000
|
public static readonly MATCH_ANSWER_TIME = 10000
|
||||||
|
// 游戏结束后房间自动解散时间
|
||||||
|
public static readonly ROOM_AUTO_CLOSE_TIME = 100000
|
||||||
|
// 第一题延后发送时间
|
||||||
|
public static readonly FIST_QUESTION_DELAY = 2000
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
beginGame,
|
beginGame, closeRoom,
|
||||||
endGame,
|
endGame,
|
||||||
sendQuestion,
|
sendQuestion,
|
||||||
updateRound,
|
updateRound,
|
||||||
@ -27,7 +27,8 @@ export function transformRecord(records: any[]) {
|
|||||||
title: o.question,
|
title: o.question,
|
||||||
answers,
|
answers,
|
||||||
type: 1,
|
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)
|
let records = await Puzzle.randomQuestions({}, history.total)
|
||||||
history.questions = records.map(o => o._id)
|
history.questions = records.map(o => o._id)
|
||||||
await history.save()
|
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) {
|
export async function sendOneQuestion(history: any) {
|
||||||
@ -63,6 +67,9 @@ export async function sendOneQuestion(history: any) {
|
|||||||
history.status = 9
|
history.status = 9
|
||||||
await history.save()
|
await history.save()
|
||||||
await endGame(roomId, {})
|
await endGame(roomId, {})
|
||||||
|
new Schedule().beginSchedule(BaseConst.ROOM_AUTO_CLOSE_TIME, async function () {
|
||||||
|
await closeRoom(roomId)
|
||||||
|
}, history.scheduleKey + '_close')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* @param roomId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user