新增获取玩家数量接口

This commit is contained in:
kercylan98 2023-05-09 18:56:06 +08:00
parent f1488fe7d3
commit da77329799
2 changed files with 6 additions and 0 deletions

View File

@ -43,6 +43,10 @@ func (slf *Room[PlayerID, Player]) GetPlayers() synchronization.MapReadonly[Play
return slf.players
}
func (slf *Room[PlayerID, Player]) GetPlayerCount() int {
return slf.players.Size()
}
func (slf *Room[PlayerID, Player]) IsExistPlayer(id PlayerID) bool {
return slf.players.Exist(id)
}

View File

@ -12,6 +12,8 @@ type Room[PlayerID comparable, P Player[PlayerID]] interface {
GetPlayer(id PlayerID) P
// GetPlayers 获取房间中的所有玩家
GetPlayers() synchronization.MapReadonly[PlayerID, P]
// GetPlayerCount 获取玩家数量
GetPlayerCount() int
// IsExistPlayer 检查房间中是否存在特定玩家
IsExistPlayer(id PlayerID) bool
// IsOwner 检查玩家是否是房主