java.lang.Object
java.util.Observable
Model.HostModel
- All Implemented Interfaces:
ScrabbleModelFacade
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThe addObserver function adds a new observer to the list of observers.voidThe closeClient function closes the client's connection to the server.voidThe disconnect function is used to notify the other players that this player has disconnected.Character[][]getBoard()The getBoard function is used to return the board as a 2D array of characters.Character[][]The getBoardToCharacters function is a helper function that converts the board's tiles into characters.getNewPlayerTiles(int amount) The getNewPlayerTiles function is used to get a new set of tiles for the player.getScore()The getScore function returns a string of the players' names and scores.booleanThe isDisconnected function checks to see if the client is disconnected.booleanThe isGameOver function checks to see if the game is over.booleanThe isGameStarted function returns a boolean value that indicates whether the game has started or not.booleanisMyTurn()The isMyTurn function returns a boolean value that indicates whether it is the player's turn.voidnextTurn()The nextTurn function is used to determine which player's turn it is.The startGame function is responsible for starting the game.booleansubmitWord(String word, int row, int col, boolean isVertical) The submitWord function takes in a word, row, column and boolean value to determine if the word is vertical or horizontal.voidupdate()The update function is used to notify the observers that a change has been made.Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Field Details
-
board
-
players
-
name
-
myTurn
protected boolean myTurn -
gameStarted
public boolean gameStarted
-
-
Constructor Details
-
HostModel
The HostModel function is the constructor for the HostModel class. It initializes all the variables that are used in this class, and starts a server to listen for incoming connections from guests.- Parameters:
name- String -Set the name of the host- Throws:
IOException
-
-
Method Details
-
isGameStarted
public boolean isGameStarted()The isGameStarted function returns a boolean value that indicates whether the game has started or not.- Specified by:
isGameStartedin interfaceScrabbleModelFacade- Returns:
- A boolean value
-
isMyTurn
public boolean isMyTurn()The isMyTurn function returns a boolean value that indicates whether it is the player's turn.- Specified by:
isMyTurnin interfaceScrabbleModelFacade- Returns:
- A boolean value
-
isGameOver
public boolean isGameOver()The isGameOver function checks to see if the game is over.- Specified by:
isGameOverin interfaceScrabbleModelFacade- Returns:
- True if the game is over, and false otherwise
-
addObserver
The addObserver function adds a new observer to the list of observers.- Specified by:
addObserverin interfaceScrabbleModelFacade- Parameters:
vm- An ScrabbleViewModel -Pass the view model to the super class
-
startGame
The startGame function is responsible for starting the game. It shuffles the players, and then sends a message to all of them that the game has started. Then it waits 2 seconds before sending a message to either host or guest depending on who's turn it is first.- Specified by:
startGamein interfaceScrabbleModelFacade- Returns:
- A list of characters
- Throws:
IOExceptionClassNotFoundException
-
submitWord
public boolean submitWord(String word, int row, int col, boolean isVertical) throws IOException, ClassNotFoundException The submitWord function takes in a word, row, column and boolean value to determine if the word is vertical or horizontal. It then converts the string into a Word object using the stringToWord function. The tryPlaceWord function from Board is called with this new Word object as an argument and returns an integer score which represents how many points were earned by placing that word on the board. If no points are earned (score == 0), then false is returned because it was not possible to place that word on the board at those coordinates. Otherwise, true is returned because it was possible to place that word- Specified by:
submitWordin interfaceScrabbleModelFacade- Parameters:
word- String -Create a word object to be placed on the boardrow- int -Determine the row of the first letter in a wordcol- int -Determine the column of the first letter in a wordisVertical- boolean -Determine whether the word is placed vertically or horizontally on the board- Returns:
- A boolean, which is true if the word was successfully placed on the board
- Throws:
IOExceptionClassNotFoundException
-
update
public void update()The update function is used to notify the observers that a change has been made. This function will be called by the model whenever it needs to update its observers. -
isDisconnected
public boolean isDisconnected()The isDisconnected function checks to see if the client is disconnected.- Specified by:
isDisconnectedin interfaceScrabbleModelFacade- Returns:
- A boolean value that indicates whether the client is disconnected
-
getScore
The getScore function returns a string of the players' names and scores.- Specified by:
getScorein interfaceScrabbleModelFacade- Returns:
- A string with the scores of all players in the game
- Throws:
IOException
-
getBoard
The getBoard function is used to return the board as a 2D array of characters.- Specified by:
getBoardin interfaceScrabbleModelFacade- Returns:
- A character[][]
- Throws:
IOExceptionClassNotFoundException
-
getBoardToCharacters
The getBoardToCharacters function is a helper function that converts the board's tiles into characters.- Returns:
- A 2d array of characters
-
getNewPlayerTiles
public ArrayList<Character> getNewPlayerTiles(int amount) throws IOException, ClassNotFoundException The getNewPlayerTiles function is used to get a new set of tiles for the player.- Specified by:
getNewPlayerTilesin interfaceScrabbleModelFacade- Parameters:
amount- int -Determine how many tiles the player will receive- Returns:
- An arraylist of characters
- Throws:
IOExceptionClassNotFoundException
-
nextTurn
The nextTurn function is used to determine which player's turn it is. It also determines when the game ends, and if so, call the endGame function.- Specified by:
nextTurnin interfaceScrabbleModelFacade- Throws:
IOExceptionInterruptedException
-
disconnect
public void disconnect()The disconnect function is used to notify the other players that this player has disconnected. It also closes the client socket and stops listening for messages from the server.- Specified by:
disconnectin interfaceScrabbleModelFacade
-
closeClient
public void closeClient()The closeClient function closes the client's connection to the server. It does this by closing the DictionaryCommunication instance, which in turn closes its socket and input/output streams.
-