Game Box Player Management
Updated at 1685687881000- Normal player: For regular purpose like player in a lobby room. You can extends this class for your business.
- Located player: For turn base game or any game required a location (a slot) for a player. You can extends this class for your business.
- MMO player: For MMO game or any game required a postion (on a map) for a player. You can extends this class for your business.
And Game Box provides some manager classes to manage above Player types:
- SimplePlayerManager: Provides common functions to add, remove, list players ... This class is not thread safe, so you must use synchronization or lock when you use it. You can extends this class for your business.
- DefaultPlayerManager: Same as SimplePlayerManager
- SynchronizedPlayerManager: Provides common functions to add, remove, list players ... 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.
- DefaultLocatedPlayerManager: For LocatedPlayer management. Provides some additional method for update master and update player's location. You can extends this class for your business.
1. Normal Player
A normal player has some properties:
- name: the username
- role: of one NULL, MASTER, SPECTATOR, PLAYER, NPC or you can define your enum value by extends the
IPlayerRole
interface - status: one of: NULL, VIEWING, PLAYING, SPEAKING or you can define your enum value by extends the
IPlayerStatus
interface - currentRoomId: current joined room id
You can create a normal class like this:
Player other = Player.builder()
.name("foo")
.build();
2. Located Player
It's extended from Player class, and it has an additional property:
- location: a number represent for a player's index or location or slot in a room or in a game.
You can create a located player like this:
LocatedPlayer master = LocatedPlayer.builder()
.name("bar")
.build();
3. MMO player
It's extended from Player class, and it has some additional properties:
- position: the position of a player on a map or a room
- rotation: the rotation of a player
- clientTimeTick: current time tick of a player, you can use this property check state of a player
- stateChanged: a boolean flag to indicates player's state change or not
- nearbyPlayers: near by plaers in a map or a room of a player
You can create a MMO player like this:
MMOPlayer player = new MMOPlayer("foo_bar");
4. SimplePlayerManager
You can create a SimpletPlayerManager with max player like this:
PlayerManager playerManager = new SimplePlayerManager.Builder<>()
.maxPlayer(100)
.build();
Or if you don't care about max player, you just need use default constructor like this:
PlayerManager playerManager = new SimplePlayerManager<>();
Add a player: playerManager.addPlayer(player);
Remove a player: playerManager.removePlayer(player1);
You can find out another functions at PlayerManager interface
5. DefaultPlayerManager
You can create a DefaultPlayerManager with max player like this:
PlayerManager playerManager = new DefaultPlayerManager.Builder<>()
.maxPlayer(100)
.build();
Or if you don't care about max player, you just need use default constructor like this:
PlayerManager playerManager = new DefaultPlayerManager<>();
5. SynchronizedPlayerManager
You can create a SynchronizedPlayerManager with max player like this:
PlayerManager playerManager = new SynchronizedPlayerManager.Builder<>()
.maxPlayer(100)
.build();
Or if you don't care about max player, you just need use default constructor like this:
PlayerManager playerManager = new SynchronizedPlayerManager<>();
5. DefaultLocatedPlayerManager
You can create a DefaultLocatedPlayerManager like this:
LocatedPlayerManager playerManager = new DefaultLocatedPlayerManager();
Add a player: playerManager.addPlayer(player, location);
Set the master: playerManager.setMaster(master);
Set which player that's taken the turn: playerManager.setSpeakinger(player);
You can find out another functions at the LocatedPlayerManager class
Next step
You can take a look Room Management.