diff --git a/game/builtin/room.go b/game/builtin/room.go index 1fcc7e2..2315725 100644 --- a/game/builtin/room.go +++ b/game/builtin/room.go @@ -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) } diff --git a/game/room.go b/game/room.go index a2a9450..075bca1 100644 --- a/game/room.go +++ b/game/room.go @@ -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 检查玩家是否是房主