added matchmaker

This commit is contained in:
jhalitaksoy 2021-06-29 03:25:15 +03:00
parent 5b690521a1
commit e0fd248466

21
src/matcmaker.ts Normal file
View 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)
}
}