java.lang.Object
it.polimi.ingsw.network.server.Lobby
- All Implemented Interfaces:
EndGameListener
,PlayerLostListener
public class Lobby extends java.lang.Object implements PlayerLostListener, EndGameListener
The place where a game is created
A Lobby object is a container for a group of players: once created, the owner can select the size and, when full, start a new game
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
addUser(User user)
Adds a user to the roomvoid
askGods(java.util.List<GodData> godData)
Asks the "owner" to choose the gods for the gamevoid
askToChooseGod(java.lang.String username)
Asks a player to choose its personal god for the gamevoid
assignGod(java.lang.String username, GodData godData)
Assigns a god to the player who chose itvoid
broadcastMessage(Message message)
Sends a message to all the users in the roomvoid
chooseGods(java.util.List<GodData> gods)
Receives the list of chosen gods from the lobby owner and, if correct, asks the next player to choose its godvoid
createGame()
Creates and starts a new gameboolean
gameStarted()
gameStarted getterjava.lang.String
getRoomName()
roomName getterMessageManagerParser
getRoomParser()
messageParser getterboolean
hasLost(User user)
Determines if a given user has lost the game in this lobbyjava.util.List<java.lang.String>
lobbyInfo()
Creates a list containing this lobby information, with the following format: lobby name number of users in the lobby number of available slots list of users in the lobbyvoid
onEndGame(java.lang.String name)
Sends a WinnerDeclaredEvent to all users, deletes the saved game, moves all the player to the waiting room and removes the lobby from the server's lobby listvoid
onPlayerLoss(java.lang.String username, java.util.List<Cell> gameBoard)
Removes the user which lost from the in-game players, and overrides the saved filevoid
reloadMatch(boolean wantToReload)
Based on the user choice, reloads a previously saved match or creates a new onevoid
removeUser(User user)
Removes a user from the lobbyvoid
selectStartingPlayer(java.lang.String username)
Rotates the players' list, based on the first player chosen, then starts the gamevoid
sendMessage(java.lang.String username, Message message)
Sends a message to a given user
-
Constructor Details
-
Lobby
Default constructor- Parameters:
server
- the server objectroomName
- the room namenumOfPlayers
- the lobby sizeuser
- the first use
-
-
Method Details
-
getRoomName
public java.lang.String getRoomName()roomName getter- Returns:
- the lobby name
-
getRoomParser
messageParser getter- Returns:
- this lobby's message parser
-
hasLost
Determines if a given user has lost the game in this lobby- Parameters:
user
- the user to check for loss- Returns:
true
if the player has lost
-
sendMessage
Sends a message to a given userThe message is sent only if the recipient is in the same room of the sender.
- Parameters:
username
- the message recipient, as a stringmessage
- the message to send
-
broadcastMessage
Sends a message to all the users in the room- Parameters:
message
- the message to send
-
addUser
Adds a user to the room- Parameters:
user
- the user to add- Throws:
RoomFullException
- if the room is fullInvalidUsernameException
- if the username is already taken in the lobby
-
reloadMatch
public void reloadMatch(boolean wantToReload)Based on the user choice, reloads a previously saved match or creates a new one- Parameters:
wantToReload
- the user choice
-
chooseGods
Receives the list of chosen gods from the lobby owner and, if correct, asks the next player to choose its god- Parameters:
gods
- the list of chosen gods
-
askGods
Asks the "owner" to choose the gods for the game- Parameters:
godData
- the list of all the available gods
-
askToChooseGod
public void askToChooseGod(java.lang.String username)Asks a player to choose its personal god for the game- Parameters:
username
- the user's username to ask to choose to
-
assignGod
Assigns a god to the player who chose it- Parameters:
username
- the player's usernamegodData
- the chosen god
-
selectStartingPlayer
public void selectStartingPlayer(java.lang.String username)Rotates the players' list, based on the first player chosen, then starts the game- Parameters:
username
- the first player's username
-
createGame
public void createGame()Creates and starts a new game -
gameStarted
public boolean gameStarted()gameStarted getter- Returns:
- true if the game started
-
removeUser
Removes a user from the lobby- Parameters:
user
- the user to remove
-
lobbyInfo
public java.util.List<java.lang.String> lobbyInfo()Creates a list containing this lobby information, with the following format:- lobby name
- number of users in the lobby
- number of available slots
- list of users in the lobby
- Returns:
- a list containing the lobby information as described above
-
onPlayerLoss
Removes the user which lost from the in-game players, and overrides the saved file- Specified by:
onPlayerLoss
in interfacePlayerLostListener
- Parameters:
username
- the loser's usernamegameBoard
- the changed gameBoard without the loser's workers as a list of cells
-
onEndGame
public void onEndGame(java.lang.String name)Sends a WinnerDeclaredEvent to all users, deletes the saved game, moves all the player to the waiting room and removes the lobby from the server's lobby list- Specified by:
onEndGame
in interfaceEndGameListener
- Parameters:
name
- the winner's username
-