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 Summary
Constructors Constructor Description GameViewModel(Application application)The constructor initializes repositories, services, and other elements needed by the ViewModel.
-
Method Summary
All 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.AndroidViewModel
getApplication
-
-
-
-
Constructor Detail
-
GameViewModel
public GameViewModel(@NonNull Application application)
The constructor initializes repositories, services, and other elements needed by the ViewModel.- Parameters:
application- The ScaleScroller application.
-
-
Method Detail
-
getScale
public 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 theScale.
-
getLevelWon
public MutableLiveData<Boolean> getLevelWon()
Returns LiveData of a Boolean indicating whether the player has won the level.- Returns:
LiveDataof aBoolean.
-
getScales
public LiveData<List<Scale>> getScales()
Returns LiveData of a list of scales, ordered by difficulty.- Returns:
LiveDataof aListofScale
-
getResume
public LiveData<Boolean> getResume()
Returns LiveData of a Boolean value indicating dialog directions.- Returns:
LiveDataof aBoolean.
-
setResume
public void setResume(boolean resume)
Sets the resume value indicating dialog directions.- Parameters:
resume- A boolean value.
-
getHearts
public LiveData<Integer> getHearts()
Returns LiveData of an Integer value that holds the player's hearts.- Returns:
LiveDataof aInteger.
-
getScore
public LiveData<Integer> getScore()
Returns LiveData of an Integer value that holds the player's score.- Returns:
LiveDataof aInteger.
-
setGameMode
public void setGameMode(GameFragment.GameMode gameMode)
Sets the GameMode of the ViewModel to the enumerated types LEARN or CHALLENGE.- Parameters:
gameMode- A enumeratedGameFragment.GameModetype.
-
getTonic
public Note getTonic()
Returns the tonic of the scale.- Returns:
- The tonic of the scale.
-
setTonic
public void setTonic(Note tonic)
Sets the tonic of the scale in the ViewModel to one of the enumerated types.- Parameters:
tonic- A enumeratedNotetype.
-
getMode
public Mode getMode()
Returns the mode of the scale.- Returns:
- The mode of the scale.
-
setMode
public void setMode(Mode mode)
Sets the mode of the scale in the ViewModel to one of the enumerated types.- Parameters:
mode- A enumeratedModetype.
-
setLevel
public void setLevel(Level level)
Sets theLevelobject.- Parameters:
level- The leve.
-
startLevel
public void startLevel()
Starts a single level.
-
setPaused
public 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.
-
getNotesString
public String getNotesString()
Returns a String representation of the correct notes of the scale.- Returns:
- A String of correctNotes.
-
getNotes
public Note[] getNotes()
Returns an array of correct notes.- Returns:
- An array of correct notes.
-
save
public void save(ChallengeAttempt challengeAttempt)
Saves a challenge attempt to the database.- Parameters:
challengeAttempt- The attempt to be saved.
-
save
public void save(LearnLevelAttempt learnLevelAttempt)
Saves a learn attempt to the database.- Parameters:
learnLevelAttempt- The attempt to be saved.
-
-