Avatar
1
azqhdyt4pggs7smw Beginner
LocatedPlayerManager for a mahjong game
I tried to turn the one-two-three demo to a mahjong game. I stuck at where to get the available() method. It was in the AbstractPlayerManager but it is not extended in the DefaultLocatedPlayerManager. Is this the right class to implement a room that has a max players count?
  • Answer
Remain: 5
1 Answer
Avatar
tvd12 Beginner
tvd12 Beginner
The Best Answer
If you want to use DefaultLocatedPlayerManager you need to LocatedRoom then when you add an player, if the room is full, it will throw an exception, here is source code of LocatedRoom.addPlayer.
public int addPlayer(LocatedPlayer player) {
    if (slots.isEmpty()) {
        throw new NoSlotException("has no available slot");
    }
    int location = slots.poll();
    playerManager.addPlayer(player, location);
    return location;
}

Or you can check room is available or not by check like bellow:

LocatedRoom room = ...
if (room.getSlots().isEmpty()) { // room is full}

But LocatedRoom and DefaultLocatedPlayerManager is suitable for table game example poker.

You have other choice is use NormalRoom with DefaultPlayerManager or SimplePlayerManager or SynchronizedPlayerManager.

For more details, could you take a look here? https://youngmonkeys.org/game-box/guides/game-box-room-management

  • 0
  • Reply