增加更新游戏伦次的方法
This commit is contained in:
parent
6d0f821f04
commit
acff67c4ba
@ -1,6 +0,0 @@
|
||||
import BaseController from '../../common/base.controller'
|
||||
import { role, router } from '../../decorators/router'
|
||||
|
||||
class ServerController extends BaseController {
|
||||
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
import { beginGame, endGame, sendQuestion, updateScore } from './WsSvr'
|
||||
import {
|
||||
beginGame,
|
||||
endGame,
|
||||
sendQuestion,
|
||||
updateRound,
|
||||
updateScore
|
||||
} from './WsSvr'
|
||||
import { Puzzle } from '../models/content/Puzzle'
|
||||
import { Schedule } from '../clock/Schedule'
|
||||
import { BaseConst } from '../constants/BaseConst'
|
||||
@ -58,6 +64,7 @@ export async function sendOneQuestion(history: any) {
|
||||
let record = await Puzzle.findById(qid)
|
||||
let qdata: any = transformRecord([record])[0]
|
||||
qdata.no = history.current
|
||||
await updateRound(roomId, history.current)
|
||||
await sendQuestion(roomId, qdata)
|
||||
history.current ++
|
||||
await history.save()
|
||||
|
@ -121,6 +121,12 @@ export async function sendQuestion(roomId: string, data: any) {
|
||||
return broadcast(roomId, 'question', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家的分数
|
||||
* @param {string} roomId
|
||||
* @param data
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function updateScore(roomId: string, data: any) {
|
||||
console.log(`updateScore: ${roomId}, ${JSON.stringify(data)}`)
|
||||
const url = `${apiBase}/room/call`
|
||||
@ -135,3 +141,24 @@ export async function updateScore(roomId: string, data: any) {
|
||||
return res.data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新游戏轮数
|
||||
* @param {string} roomId
|
||||
* @param {number} round
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function updateRound(roomId: string, round: number) {
|
||||
console.log(`updateRound: ${roomId}, ${round}`)
|
||||
const url = `${apiBase}/room/call`
|
||||
const args = [round]
|
||||
const params = {
|
||||
roomId,
|
||||
method: 'updateRound',
|
||||
args: JSON.stringify(args)
|
||||
}
|
||||
return axios.post(url, params)
|
||||
.then(res => {
|
||||
return res.data
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user