From 0741d19b7ff104f6cacb2aba90fb106489db9a18 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 12 May 2023 11:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=BA=A7=E4=BD=8D=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/builtin/room_seat.go | 32 ++++++++++++++++++++++++++++++++ game/room_seat.go | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/game/builtin/room_seat.go b/game/builtin/room_seat.go index e4ce3a5..283c070 100644 --- a/game/builtin/room_seat.go +++ b/game/builtin/room_seat.go @@ -172,6 +172,38 @@ func (slf *RoomSeat[PlayerID, Player]) GetSeatInfoWithPlayerIDMap() map[PlayerID return slf.seatPS.Map() } +func (slf *RoomSeat[PlayerID, Player]) GetNextSeat(seat int) int { + l := len(slf.seatSP) + if l == 0 || seat >= l || seat < 0 { + return -1 + } + var target = seat + for { + target++ + if target >= l { + target = 0 + } + if target == seat { + return seat + } + if slf.seatSP[target] != nil { + return target + } + } +} + +func (slf *RoomSeat[PlayerID, Player]) GetNextSeatVacancy(seat int) int { + l := len(slf.seatSP) + if l == 0 || seat >= l || seat < 0 { + return -1 + } + seat++ + if seat >= l { + seat = 0 + } + return seat +} + func (slf *RoomSeat[PlayerID, Player]) onJoinRoom(room game.Room[PlayerID, Player], player Player) { slf.AddSeat(player.GetID()) } diff --git a/game/room_seat.go b/game/room_seat.go index a8ea404..8b81cb0 100644 --- a/game/room_seat.go +++ b/game/room_seat.go @@ -26,4 +26,12 @@ type RoomSeat[PlayerID comparable, P Player[PlayerID]] interface { GetSeatInfoMapVacancy() map[int]*PlayerID // GetSeatInfoWithPlayerIDMap 获取座位信息,将以玩家ID作为key GetSeatInfoWithPlayerIDMap() map[PlayerID]int + // GetNextSeat 获取下一个座位号,空缺的位置将会被跳过 + // - 超出范围将返回-1 + // - 当没有下一个座位号时将始终返回本身 + GetNextSeat(seat int) int + // GetNextSeatVacancy 获取下一个座位号,空缺的位置将被保留 + // - 超出范围将返回-1 + // - 当没有下一个座位号时将始终返回本身 + GetNextSeatVacancy(seat int) int }