public class Manager
extends java.lang.Object
An instance of this class is responsible for managing users and game instances.
The methods of this class are those needed by web client thus it follows the Facade design pattern. It also follows the Singleton design pattern to provide a single instance of this class to the application.
jpleal@fc.up.pt
Modifier and Type | Method and Description |
---|---|
void |
addBotPlayer(java.lang.String gameId)
Add a bot to the given game instance.
|
void |
addPlayer(java.lang.String gameId,
java.lang.String nick,
java.lang.String password)
Add a player to a given game instance.
|
java.lang.String |
createGame(java.lang.String name)
Create a new game instance of the game with given name.
|
java.util.List<GameInfo> |
getAvailableGameInfos()
A list with information on games available to be played.
|
java.util.List<java.lang.String> |
getGameNames()
A list of available game names, required to create a new game instance.
|
(package private) static Manager |
getInstance()
Single instance of this class.
|
java.util.List<GameEvent> |
getRecentEvents(java.lang.String nick,
java.lang.String password)
Get a list of recent events sent to the given user by game instances.
|
void |
playCards(java.lang.String gameId,
java.lang.String nick,
java.lang.String password,
java.util.List<Card> cards)
Play cards on a game on behalf of an authenticated user.
|
void |
registerPlayer(java.lang.String nick,
java.lang.String password)
Register a human player (an user) to participate in card games.
|
(package private) void |
reset()
Resets manager's fields to enable unit testing.
|
static Manager getInstance() throws CardGameException
CardGameException
- if an error occurs in the instantiation
of the UserPool
void reset()
public java.util.List<java.lang.String> getGameNames()
public java.lang.String createGame(java.lang.String name) throws CardGameException
getGameNames()
.name
- of game.CardGameException
- if name is invalid.public java.util.List<GameInfo> getAvailableGameInfos()
public void registerPlayer(java.lang.String nick, java.lang.String password) throws CardGameException
nick
- of playerpassword
- of playerCardGameException
- if user exists,
or if either nick or password are null
.public void addPlayer(java.lang.String gameId, java.lang.String nick, java.lang.String password) throws CardGameException
gameId
- of game instance to join.nick
- of player.password
- of player.CardGameException
- if gameId is invalid
or player authentication failed.public void addBotPlayer(java.lang.String gameId) throws CardGameException
gameId
- of game instance to add player.CardGameException
- if gameId
is invalid.public void playCards(java.lang.String gameId, java.lang.String nick, java.lang.String password, java.util.List<Card> cards) throws CardGameException
gameId
- of game instance.nick
- of player.password
- of players.cards
- to play.CardGameException
- if gameId is invalid, authentication fails,
or given cards cannot be playedpublic java.util.List<GameEvent> getRecentEvents(java.lang.String nick, java.lang.String password) throws CardGameException
nick
- of player.password
- of player.CardGameException
- if authentication fails.