Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 3be6e672 authored by 62160052's avatar 62160052
Browse files

Update game restart logic

parent 65d31cdf
No related branches found
No related tags found
No related merge requests found
...@@ -44,12 +44,14 @@ class GameFragment : Fragment() { ...@@ -44,12 +44,14 @@ class GameFragment : Fragment() {
// If the fragment is re-created, it receives the same GameViewModel instance created by the // If the fragment is re-created, it receives the same GameViewModel instance created by the
// first fragment // first fragment
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
binding = GameFragmentBinding.inflate(inflater, container, false) binding = GameFragmentBinding.inflate(inflater, container, false)
Log.d("GameFragment", "GameFragment created/re-created!") Log.d("GameFragment", "Word: ${viewModel.currentScrambledWord} " +
"Score: ${viewModel.score} WordCount: ${viewModel.currentWordCount}")
return binding.root return binding.root
} }
...@@ -95,7 +97,12 @@ class GameFragment : Fragment() { ...@@ -95,7 +97,12 @@ class GameFragment : Fragment() {
* Increases the word count. * Increases the word count.
*/ */
private fun onSkipWord() { private fun onSkipWord() {
if (viewModel.nextWord()) {
setErrorTextField(false)
updateNextWordOnScreen()
} else {
showFinalScoreDialog()
}
} }
/* /*
...@@ -112,6 +119,7 @@ class GameFragment : Fragment() { ...@@ -112,6 +119,7 @@ class GameFragment : Fragment() {
* restart the game. * restart the game.
*/ */
private fun restartGame() { private fun restartGame() {
viewModel.reinitializeData()
setErrorTextField(false) setErrorTextField(false)
updateNextWordOnScreen() updateNextWordOnScreen()
} }
......
...@@ -62,5 +62,12 @@ class GameViewModel: ViewModel() { ...@@ -62,5 +62,12 @@ class GameViewModel: ViewModel() {
return false return false
} }
fun reinitializeData() {
_score = 0
_currentWordCount = 0
wordsList.clear()
getNextWord()
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment