java.lang.Object
java.util.Observable
Model.Model
Model.PlayerModel
Model.HostModel
- All Implemented Interfaces:
Observer
Host server class
-
Method Summary
Modifier and TypeMethodDescriptionvoidmethod that add player to the game and create player, add the player to the map and create a string builder of ids Sends the information to the hostServer and notify with the format : requestedId + ":" + method + ":" + inputsvoidA method which check if the word is valid or not send the information to the handler with the method sendToHandler() notify to the binding objects by a format - requestedId + ":" + method + ":" + inputsvoidvoidconnectToBookScrabbleServer(int myPort, String gameServerIp, int gameServerPort) method that connect and start the connection with the server and open its own server.Character[][]A method that return the status of the boardchargetCharInPosition(int row, int col) getFixedWord(String word, int row, int col, boolean isVertical) static HostModelgetHost()method that return the host model itselfintA method that return the numbers of tile in the bagA method that create map with all the players number of tilesA method that create a map with all the players scoresvoidvoidA method which increase the turns in the game notify to the binding objects by a format - requestedId + ":" + method + ":" + inputsvoidrefillPlayerHand(int playerId) The refillPlayerHand function is called when a player's hand has less than 7 tiles.voidA method that set the prev-board to the new state of the board and notify to the other players that the board has changed notify to the binding objects by a format - requestedId + ":" +method + ":" + inputsvoidsetPlayerName(String name) voidvoidA method which take on tile randomly from the bag and put it in the player list of tiles notify to the binding objects by a format - requestedId + ":" + method + ":" + inputsa method that create a string include char and scorevoidtryPlaceWord(String word, int col, int row, boolean isVertical) A method that try to place the word on the board create tile[] from the string word, create Word.voidupdate(Observable o, Object arg) A method that take care of the reading by the format we have created and calls the method we need format: requestedId+":"+method+":"+inputsMethods inherited from class Model.PlayerModel
getCurrentPlayerId, getMyTiles, setCurrentPlayerIdMethods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Method Details
-
getHost
method that return the host model itself- Returns:
- hostModel
-
getFixedWord
-
getCharInPosition
public char getCharInPosition(int row, int col) -
getHostServer
- Returns:
- the host server
-
getConnectedPlayers
-
loadBooks
-
setPlayerName
-
connectToBookScrabbleServer
method that connect and start the connection with the server and open its own server.- Parameters:
myPort- this is my own port to the connection between the hostModel and the server add host server to the observergameServerIp- this parameter is the ip of the servergameServerPort- this parameter is the port of the server
-
startGame
public void startGame() -
closeConnection
public void closeConnection()- Specified by:
closeConnectionin classModel
-
addPlayer
method that add player to the game and create player, add the player to the map and create a string builder of ids Sends the information to the hostServer and notify with the format : requestedId + ":" + method + ":" + inputs- Parameters:
socket- - socket parameter that send to the hostServer
-
tryPlaceWord
A method that try to place the word on the board create tile[] from the string word, create Word. notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs- Specified by:
tryPlaceWordin classModel- Parameters:
word- a string that represent the word that the player want to place on the boardcol- represent the starting col of the word in the boardrow- represent the starting row of the word in the boardisVertical- represent if the word is vertical or not with boolean parameter
-
challenge
A method which check if the word is valid or not send the information to the handler with the method sendToHandler() notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs -
takeTileFromBag
public void takeTileFromBag()A method which take on tile randomly from the bag and put it in the player list of tiles notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs- Specified by:
takeTileFromBagin classModel
-
refillPlayerHand
public void refillPlayerHand(int playerId) The refillPlayerHand function is called when a player's hand has less than 7 tiles. It adds the missing number of tiles to the player's hand, and updates all players with the new number of tiles in their hands and in the bag.- Parameters:
playerId- int | Identify the player that is requesting to refill his hand
-
passTheTurn
public void passTheTurn()A method which increase the turns in the game notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs -
setBoardStatus
public void setBoardStatus()A method that set the prev-board to the new state of the board and notify to the other players that the board has changed notify to the binding objects by a format - requestedId + ":" +method + ":" + inputs -
tilesWithScores
a method that create a string include char and score- Returns:
- tiles with the scores in string
-
getBoardStatus
A method that return the status of the board- Specified by:
getBoardStatusin classModel- Returns:
- the board status in a Tile matrix
-
getNumberOfTilesInBag
public int getNumberOfTilesInBag()A method that return the numbers of tile in the bag- Specified by:
getNumberOfTilesInBagin classModel- Returns:
- the number of the tile which are in the bag with the parameter totalTiles
-
getPlayersScores
A method that create a map with all the players scores- Specified by:
getPlayersScoresin classModel- Returns:
- a map from key: id of the players to value: player score
-
getPlayersNumberOfTiles
A method that create map with all the players number of tiles- Specified by:
getPlayersNumberOfTilesin classModel- Returns:
- a map from key: id of the players to value: player number of tiles
-
getMyHand
-
update
A method that take care of the reading by the format we have created and calls the method we need format: requestedId+":"+method+":"+inputs
-