java.lang.Object
java.util.Observable
Model.GuestModel
- All Implemented Interfaces:
ScrabbleModelFacade
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGuestModel(String name, String ip, int port) The GuestModel function is the constructor for the GuestModel class. -
Method Summary
Modifier and TypeMethodDescriptionvoidThe addObserver function adds a new observer to the list of observers.voidThe disconnect function is used to disconnect the client from the server.voidThe disconnectInvoked function is used to notify the observers that a disconnection has been invoked.Character[][]getBoard()The getBoard function is used to get the board from the server.getNewPlayerTiles(int amount) The getNewPlayerTiles function is used to get new tiles for the player.getScore()The getScore function returns a string containing the current score of all players in the game.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 called when the current player's turn ends.The startGame function is called when the game begins.booleansubmitWord(String word, int row, int col, boolean isVertical) The submitWord function is used to submit a word to the game board.voidThe waitForGameStart function is used to wait for the game to start.voidThe waitForTurn function is used to wait for the server to notify the client that it's their turn.Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Field Details
-
server
-
-
Constructor Details
-
GuestModel
The GuestModel function is the constructor for the GuestModel class. It takes in a String name, String ip and int port as parameters. The function creates a new socket with the given ip and port, then sends "Connect:name" to server to connect. If server responds with "GameIsFull", it throws an IOException saying that game is full. If server responds with "NameIsTaken", it throws an IOException saying that name is taken by another player already connected to game.- Parameters:
name- A String -Set the name of the playerip- A String -Connect to the server public void waitforgamestart() { try { bufferedreader br = new bufferedreader(new inputstreamreader(serverport- An int -Connect to the server- 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
-
disconnect
public void disconnect()The disconnect function is used to disconnect the client from the server. It sends a message to the server that it is disconnecting, and then closes its socket connection with the server.- Specified by:
disconnectin interfaceScrabbleModelFacade
-
isDisconnected
public boolean isDisconnected()The isDisconnected function checks to see if the client is disconnected.- Specified by:
isDisconnectedin interfaceScrabbleModelFacade- Returns:
- The value of the disconnect boolean variable
-
waitForGameStart
public void waitForGameStart()The waitForGameStart function is used to wait for the game to start. It waits until it receives a message from the server that says "GameStarted". Once this happens, it notifies all of its observers and then calls waitForTurn(). -
addObserver
The addObserver function adds a new observer to the list of observers.- Specified by:
addObserverin interfaceScrabbleModelFacade- Parameters:
vm- ScrabbleViewModel -Pass the view model to the super class
-
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 of true if it is the player's turn and false otherwise
-
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, false otherwise
-
waitForTurn
public void waitForTurn()The waitForTurn function is used to wait for the server to notify the client that it's their turn. The function will continue running until either: 1) It receives a message from the server saying that it's their turn, or 2) The game has ended (in which case, we close our connection with the server). -
nextTurn
public void nextTurn()The nextTurn function is called when the current player's turn ends. It sends a message to the server that it is no longer their turn, and then waits for a message from the server indicating that it is now their turn again. This function also sets myTurn to false, so that any further attempts by this client to send messages will be disabled until they receive another "YourTurn" message from the server.- Specified by:
nextTurnin interfaceScrabbleModelFacade
-
submitWord
The submitWord function is used to submit a word to the game board.- Specified by:
submitWordin interfaceScrabbleModelFacade- Parameters:
word- String -Pass the word that is being submitted to the serverrow- int -Specify 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 vertical or horizontal- Returns:
- true if word was successfully placed on board, false if not.
-
getScore
The getScore function returns a string containing the current score of all players in the game. The format of this string is as follows with a delimiter of ";" to separate between players.Example: Michal:104;Tal:98;Roie:57;Arik:82
- Specified by:
getScorein interfaceScrabbleModelFacade- Returns:
- String
-
getBoard
The getBoard function is used to get the board from the server.- Specified by:
getBoardin interfaceScrabbleModelFacade- Returns:
- A 2d array of characters
-
disconnectInvoked
public void disconnectInvoked()The disconnectInvoked function is used to notify the observers that a disconnection has been invoked. It sets the disconnect boolean to true, and notifies all of its observers. -
getNewPlayerTiles
The getNewPlayerTiles function is used to get new tiles for the player.- Specified by:
getNewPlayerTilesin interfaceScrabbleModelFacade- Parameters:
amount- int -Determine how many tiles the player needs to get from the bag- Returns:
- An arraylist of characters
-
startGame
The startGame function is called when the game begins. It returns an ArrayList of 7 characters, which are the tiles that will be given to a player at the start of a game. The function calls getNewPlayerTiles(7) to accomplish this task.- Specified by:
startGamein interfaceScrabbleModelFacade- Returns:
- An arraylist of character objects
- Throws:
IOExceptionClassNotFoundException
-