Game Box Room Management

Updated at 1704244258000
For game, Game Box provides some Room types for logic:
  1. Normal room: For regular purpose like lobby room. You can extends this class for your business.
  2. Located room: For turn base game or any game required a location (a slot) for players. You can extends this class for your business.
  3. MMO room: For MMO game or any game required a postion (on a map) for players. You can extends this class for your business.

And Game Box provides some manager classes to manage above Room types:

  1. SimpleRoomManager: Provides common functions to add, remove, list rooms ... This class is thread safe but it's not atomic, so you should use synchronization or lock when you use it. You can extends this class for your business.
  2. DefaultRoomManager: Provides common functions to add, remove, list rooms ... This class is not thread safe, so you should use synchronization or lock when you use it. You can extends this class for your business.
  3. SynchronizedRoomManager: Provides common functions to add, remove, list rooms ... This class is thread safe, so you can use synchronization or lock when you use it or not. You can extends this class for your business.

1. Normal Room

A normal room has some properties:

  • id: the room Id
  • name: the room's name
  • password: the room's password
  • status: one of WAITING, STARTABLE, PLAYING, FINISHING, FINISHED or you can define your enum value by extends the IRoomStatus interface
  • playerManager: the playerManager

You can create a normal room like this:

    Room room = NormalRoom.builder()
        .defaultPlayerManager(100)
        .build();

2. Located Room

It's extended from Room class, and it has an additional property:

  • maxSlot: the maximum number of slot in the room
  • slots: the slot queue to allocate for player in the room
  • playerManager: the playerManager (LocatedPlayerManager)

You can create a located room like this:

    LocatedRoom sut = LocatedRoom.builder()
        .maxSlot(2)
        .build();

3. MMO Room

It's extended from NormalRoom class, and it has some additional properties:

  • master: the room's master
  • distanceOfInterest: the distance to detect near by players for a player
  • roomUpdatedHandlers: the room's update handlers

You can create a MMO room like this:

    MMORoom sut = MMORoom.builder()
        .defaultPlayerManager(2)
        .distanceOfInterest(100)
        .build();
  

4. SimpleRoomManager

You can create a SimpleRoomManager with max room like this:

    SimpleRoomManager roomManager = new SimpleRoomManager<>(200);

Or if you don't care about max room, you just need use default constructor like this:

    SimpleRoomManager roomManager = new SimpleRoomManager<>();

Add a room: roomManager.addRoom(room); Remove a room: roomManager.removeRoom(room); You can find out another functions at RoomManager interface

5. DefaultPlayerManager

You can create a DefaultPlayerManager with max player like this:

    DefaultRoomManager roomManager = new DefaultRoomManager<>(200);

Or if you don't care about max player, you just need use default constructor like this:

    DefaultRoomManager roomManager = new DefaultRoomManager<>();

5. SynchronizedPlayerManager

You can create a SynchronizedPlayerManager with max player like this:

    SynchronizedRoomManager roomManager = new SynchronizedRoomManager<>(100);

Or if you don't care about max player, you just need use default constructor like this:

    SynchronizedRoomManager roomManager = new SynchronizedRoomManager<>();

Next step

You can take a look MMO Game.