added matchmaker
This commit is contained in:
parent
5b690521a1
commit
e0fd248466
21
src/matcmaker.ts
Normal file
21
src/matcmaker.ts
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
// todo : use queue
|
||||
export class MatchMaker {
|
||||
private waitingUserKey : string | undefined
|
||||
|
||||
public onPlayersPaired!: (userKey1: string, userKey2: string) => void
|
||||
|
||||
public find(userKey : string) : void{
|
||||
if(this.waitingUserKey){
|
||||
const user1 = this.waitingUserKey as string
|
||||
this.waitingUserKey = undefined
|
||||
this.fireOnPlayerPaired(user1, userKey)
|
||||
}else{
|
||||
this.waitingUserKey = userKey
|
||||
}
|
||||
}
|
||||
|
||||
private fireOnPlayerPaired(userKey1 : string, userKey2 : string) : void {
|
||||
this.onPlayersPaired!!(userKey1, userKey2)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user