Skip to content

Commit

Permalink
添加获取第一个可用座位号函数
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed May 12, 2023
1 parent 915163d commit b61a76e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions game/builtin/room_seat.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func (slf *RoomSeat[PlayerID, Player]) GetSeatInfoWithPlayerIDMap() map[PlayerID
return slf.seatPS.Map()
}

func (slf *RoomSeat[PlayerID, Player]) GetFirstSeat() int {
for seat, playerId := range slf.seatSP {
if playerId != nil {
return seat
}
}
return -1
}

func (slf *RoomSeat[PlayerID, Player]) GetNextSeat(seat int) int {
l := len(slf.seatSP)
if l == 0 || seat >= l || seat < 0 {
Expand Down
2 changes: 2 additions & 0 deletions game/room_seat.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type RoomSeat[PlayerID comparable, P Player[PlayerID]] interface {
GetSeatInfoMapVacancy() map[int]*PlayerID
// GetSeatInfoWithPlayerIDMap 获取座位信息,将以玩家ID作为key
GetSeatInfoWithPlayerIDMap() map[PlayerID]int
// GetFirstSeat 获取第一个非空缺座位号,不存在时将返回-1
GetFirstSeat() int
// GetNextSeat 获取下一个座位号,空缺的位置将会被跳过
// - 超出范围将返回-1
// - 当没有下一个座位号时将始终返回本身
Expand Down

0 comments on commit b61a76e

Please sign in to comment.