增加积分更洗机制
This commit is contained in:
parent
9314735fb5
commit
999984babe
@ -6,6 +6,7 @@ import { OnJoinCommand } from './commands/OnJoinCommand'
|
||||
import { Player } from './schema/Player'
|
||||
import { BeginGameCommand } from './commands/BeginGameCommand'
|
||||
import { PuzzleGameState } from './schema/PuzzleGameState'
|
||||
import { EndGameCommand } from './commands/EndGameCommand'
|
||||
|
||||
|
||||
export class PuzzleMathRoom extends Room {
|
||||
@ -88,6 +89,19 @@ export class PuzzleMathRoom extends Room {
|
||||
* 游戏结束
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
src/rooms/commands/EndGameCommand.ts
Normal file
13
src/rooms/commands/EndGameCommand.ts
Normal 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', {})
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ export class Player extends Schema {
|
||||
@type('string')
|
||||
id: string
|
||||
|
||||
@type('string')
|
||||
accountId: string
|
||||
|
||||
@type('number')
|
||||
@ -18,5 +19,6 @@ export class Player extends Schema {
|
||||
super()
|
||||
this.id = id
|
||||
this.accountId = accountId
|
||||
this.score = 0
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user