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.Level
getLevel()
Returns theLevel
object.MutableLiveData<Boolean>
getLevelWon()
Returns LiveData of a Boolean indicating whether the player has won the level.Mode
getMode()
Returns the mode of the scale.Note[]
getNotes()
Returns an array of correct notes.String
getNotesString()
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.Note
getTonic()
Returns the tonic of the scale.void
save(ChallengeAttempt challengeAttempt)
Saves a challenge attempt to the database.void
save(LearnLevelAttempt learnLevelAttempt)
Saves a learn attempt to the database.void
setGameMode(GameFragment.GameMode gameMode)
Sets the GameMode of the ViewModel to the enumerated types LEARN or CHALLENGE.void
setLevel(Level level)
Sets theLevel
object.void
setMode(Mode mode)
Sets the mode of the scale in the ViewModel to one of the enumerated types.void
setPaused(boolean paused)
Sets a boolean value indicating whether the game is paused or not.void
setResume(boolean resume)
Sets the resume value indicating dialog directions.void
setTonic(Note tonic)
Sets the tonic of the scale in the ViewModel to one of the enumerated types.void
startLevel()
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:
LiveData
of theScale
.
-
getLevelWon
public MutableLiveData<Boolean> getLevelWon()
Returns LiveData of a Boolean indicating whether the player has won the level.- Returns:
LiveData
of aBoolean
.
-
getScales
public LiveData<List<Scale>> getScales()
Returns LiveData of a list of scales, ordered by difficulty.- Returns:
LiveData
of aList
ofScale
-
getResume
public LiveData<Boolean> getResume()
Returns LiveData of a Boolean value indicating dialog directions.- Returns:
LiveData
of 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:
LiveData
of aInteger
.
-
getScore
public LiveData<Integer> getScore()
Returns LiveData of an Integer value that holds the player's score.- Returns:
LiveData
of 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.GameMode
type.
-
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 enumeratedNote
type.
-
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 enumeratedMode
type.
-
setLevel
public void setLevel(Level level)
Sets theLevel
object.- 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.
-
-