java.lang.Object
java.util.Observable
ViewModel.ViewModel
- All Implemented Interfaces:
Observer
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()The close function closes the connection.Character[][]getBoard()intstatic ViewModelcreate a new ViewModel if it doesn't exist, and return it (singleton)voidThe resetModel function is used to reset the model of the game.voidset the model only if it is null (to avoid setting it twice)voidvoidvoidRun when the player clicks the "Place Word" button.voidupdate(Observable o, Object arg) this method start when the observable object (the model [HostModel/GuestModel]) notify to the observer (VM)Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Field Details
-
vm
-
changesList
-
numberOfTilesInBagProperty
public javafx.beans.property.StringProperty numberOfTilesInBagProperty
-
-
Method Details
-
getViewModel
create a new ViewModel if it doesn't exist, and return it (singleton)- Returns:
- the ViewModel
-
getPlayers
-
getMyPlayer
-
getCurrentPlayerId
public int getCurrentPlayerId() -
getBoard
-
startGame
public void startGame() -
setModel
set the model only if it is null (to avoid setting it twice)- Parameters:
model- - the model that the ViewModel is observing (GuestModel or HostModel)
-
resetModel
public void resetModel()The resetModel function is used to reset the model of the game. This function is called when a new game is started, and it deletes any observers that are attached to the old model. It then sets this.model = null; so that we can create a new instance of our GameModel class in our startGame function in GameController class. -
close
public void close()The close function closes the connection. If the model is GuestModel, it closes the connection to the server. If the model is HostModel, it closes the connection to the BookScrabbleServer (MyServer) and close the HostServer. -
tryPlaceWord
public void tryPlaceWord()Run when the player clicks the "Place Word" button. Tries to place the word on the board if it is valid (from changesList) using the Model. If the word is invalid, notify the view -
challenge
-
takeTileFromBag
public void takeTileFromBag() -
update
this method start when the observable object (the model [HostModel/GuestModel]) notify to the observer (VM)
-