Class GameViewModel
- java.lang.Object
- 
- androidx.lifecycle.ViewModel
- 
- androidx.lifecycle.AndroidViewModel
- 
- edu.cnm.deepdive.scalescroller.viewmodel.GameViewModel
 
 
 
- 
- All Implemented Interfaces:
- LifecycleObserver
 
 public class GameViewModel extends AndroidViewModel implements LifecycleObserver Serves as the ViewModel for the GameFragment.
- 
- 
Constructor SummaryConstructors Constructor Description GameViewModel(Application application)The constructor initializes repositories, services, and other elements needed by the ViewModel.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description LiveData<Integer>getHearts()Returns LiveData of an Integer value that holds the player's hearts.LevelgetLevel()Returns theLevelobject.MutableLiveData<Boolean>getLevelWon()Returns LiveData of a Boolean indicating whether the player has won the level.ModegetMode()Returns the mode of the scale.Note[]getNotes()Returns an array of correct notes.StringgetNotesString()Returns a String representation of the correct notes of the scale.LiveData<Player>getPlayer()Returns LiveData of the current player.LiveData<Boolean>getResume()Returns LiveData of a Boolean value indicating dialog directions.LiveData<Scale>getScale(Note tonic, Mode mode)Returns LiveData of a scale, given tonic and mode.LiveData<List<Scale>>getScales()Returns LiveData of a list of scales, ordered by difficulty.LiveData<Integer>getScore()Returns LiveData of an Integer value that holds the player's score.NotegetTonic()Returns the tonic of the scale.voidsave(ChallengeAttempt challengeAttempt)Saves a challenge attempt to the database.voidsave(LearnLevelAttempt learnLevelAttempt)Saves a learn attempt to the database.voidsetGameMode(GameFragment.GameMode gameMode)Sets the GameMode of the ViewModel to the enumerated types LEARN or CHALLENGE.voidsetLevel(Level level)Sets theLevelobject.voidsetMode(Mode mode)Sets the mode of the scale in the ViewModel to one of the enumerated types.voidsetPaused(boolean paused)Sets a boolean value indicating whether the game is paused or not.voidsetResume(boolean resume)Sets the resume value indicating dialog directions.voidsetTonic(Note tonic)Sets the tonic of the scale in the ViewModel to one of the enumerated types.voidstartLevel()Starts a single level.- 
Methods inherited from class androidx.lifecycle.AndroidViewModelgetApplication
 
- 
 
- 
- 
- 
Constructor Detail- 
GameViewModelpublic GameViewModel(@NonNull Application application) The constructor initializes repositories, services, and other elements needed by the ViewModel.- Parameters:
- application- The ScaleScroller application.
 
 
- 
 - 
Method Detail- 
getScalepublic LiveData<Scale> getScale(Note tonic, Mode mode) Returns LiveData of a scale, given tonic and mode.- Parameters:
- tonic- The scale's tonic.
- mode- The scale's mode.
- Returns:
- LiveDataof the- Scale.
 
 - 
getLevelWonpublic MutableLiveData<Boolean> getLevelWon() Returns LiveData of a Boolean indicating whether the player has won the level.- Returns:
- LiveDataof a- Boolean.
 
 - 
getScalespublic LiveData<List<Scale>> getScales() Returns LiveData of a list of scales, ordered by difficulty.- Returns:
- LiveDataof a- Listof- Scale
 
 - 
getResumepublic LiveData<Boolean> getResume() Returns LiveData of a Boolean value indicating dialog directions.- Returns:
- LiveDataof a- Boolean.
 
 - 
setResumepublic void setResume(boolean resume) Sets the resume value indicating dialog directions.- Parameters:
- resume- A boolean value.
 
 - 
getHeartspublic LiveData<Integer> getHearts() Returns LiveData of an Integer value that holds the player's hearts.- Returns:
- LiveDataof a- Integer.
 
 - 
getScorepublic LiveData<Integer> getScore() Returns LiveData of an Integer value that holds the player's score.- Returns:
- LiveDataof a- Integer.
 
 - 
setGameModepublic void setGameMode(GameFragment.GameMode gameMode) Sets the GameMode of the ViewModel to the enumerated types LEARN or CHALLENGE.- Parameters:
- gameMode- A enumerated- GameFragment.GameModetype.
 
 - 
getTonicpublic Note getTonic() Returns the tonic of the scale.- Returns:
- The tonic of the scale.
 
 - 
setTonicpublic void setTonic(Note tonic) Sets the tonic of the scale in the ViewModel to one of the enumerated types.- Parameters:
- tonic- A enumerated- Notetype.
 
 - 
getModepublic Mode getMode() Returns the mode of the scale.- Returns:
- The mode of the scale.
 
 - 
setModepublic void setMode(Mode mode) Sets the mode of the scale in the ViewModel to one of the enumerated types.- Parameters:
- mode- A enumerated- Modetype.
 
 - 
setLevelpublic void setLevel(Level level) Sets theLevelobject.- Parameters:
- level- The leve.
 
 - 
startLevelpublic void startLevel() Starts a single level.
 - 
setPausedpublic void setPaused(boolean paused) Sets a boolean value indicating whether the game is paused or not.- Parameters:
- paused- A boolean that indicates whether the game is paused or not.
 
 - 
getNotesStringpublic String getNotesString() Returns a String representation of the correct notes of the scale.- Returns:
- A String of correctNotes.
 
 - 
getNotespublic Note[] getNotes() Returns an array of correct notes.- Returns:
- An array of correct notes.
 
 - 
savepublic void save(ChallengeAttempt challengeAttempt) Saves a challenge attempt to the database.- Parameters:
- challengeAttempt- The attempt to be saved.
 
 - 
savepublic void save(LearnLevelAttempt learnLevelAttempt) Saves a learn attempt to the database.- Parameters:
- learnLevelAttempt- The attempt to be saved.
 
 
- 
 
-