LastMUD/internal/game/room.go

52 lines
836 B
Go
Raw Normal View History

2025-06-22 17:54:07 +03:00
package game
2025-06-22 22:27:56 +03:00
import "github.com/google/uuid"
2025-06-22 17:54:07 +03:00
type RoomPlayer interface {
2025-06-22 22:27:56 +03:00
Identity() uuid.UUID
2025-06-22 17:54:07 +03:00
SetRoom(room *Room)
}
type Room struct {
2025-06-22 22:27:56 +03:00
world *World
2025-06-22 17:54:07 +03:00
North *Room
South *Room
East *Room
West *Room
Name string
Description string
2025-06-22 22:27:56 +03:00
players map[uuid.UUID]RoomPlayer
2025-06-22 17:54:07 +03:00
}
2025-06-22 22:27:56 +03:00
func CreateRoom(world *World, name, description string) *Room {
2025-06-22 17:54:07 +03:00
return &Room{
2025-06-22 22:27:56 +03:00
world: world,
2025-06-22 17:54:07 +03:00
Name: name,
Description: description,
2025-06-22 22:27:56 +03:00
players: map[uuid.UUID]RoomPlayer{},
2025-06-22 17:54:07 +03:00
}
}
func (r *Room) PlayerJoinRoom(player RoomPlayer) (err error) {
r.players[player.Identity()] = player
return
}
func (r *Room) PlayerLeaveRoom(player RoomPlayer) (err error) {
delete(r.players, player.Identity())
return
}
2025-06-22 22:27:56 +03:00
func (r *Room) Players() map[uuid.UUID]RoomPlayer {
2025-06-22 17:54:07 +03:00
return r.players
}
2025-06-22 22:27:56 +03:00
func (r *Room) World() *World {
return r.world
}