增加积分更洗机制

This commit is contained in:
zhl 2021-04-29 20:49:05 +08:00
parent 9314735fb5
commit 999984babe
3 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { OnJoinCommand } from './commands/OnJoinCommand'
import { Player } from './schema/Player' import { Player } from './schema/Player'
import { BeginGameCommand } from './commands/BeginGameCommand' import { BeginGameCommand } from './commands/BeginGameCommand'
import { PuzzleGameState } from './schema/PuzzleGameState' import { PuzzleGameState } from './schema/PuzzleGameState'
import { EndGameCommand } from './commands/EndGameCommand'
export class PuzzleMathRoom extends Room { export class PuzzleMathRoom extends Room {
@ -88,6 +89,19 @@ export class PuzzleMathRoom extends Room {
* *
*/ */
endGame() { endGame() {
console.log(`admin send end game cmd`)
this.dispatcher.dispatch(new EndGameCommand() )
}
updateScore(datas: any) {
console.log(`admin updateScore: ${JSON.stringify(datas)}`)
for (let data of datas) {
for (let [,player] of this.state.players) {
if (player.accountId == data.accountid) {
player.score += data.score
break
}
}
}
} }
} }

View File

@ -0,0 +1,13 @@
import { Command } from '@colyseus/command'
import { PuzzleGameState } from '../schema/PuzzleGameState'
import { GameStateConst } from '../../constants/GameStateConst'
/**
*
*/
export class EndGameCommand extends Command<PuzzleGameState, {}> {
async execute() {
this.state.updateGameState(GameStateConst.STATE_GAME_OVER)
this.room.broadcast('endgame', {})
}
}

View File

@ -4,6 +4,7 @@ export class Player extends Schema {
@type('string') @type('string')
id: string id: string
@type('string')
accountId: string accountId: string
@type('number') @type('number')
@ -18,5 +19,6 @@ export class Player extends Schema {
super() super()
this.id = id this.id = id
this.accountId = accountId this.accountId = accountId
this.score = 0
} }
} }