Gitlab@Informatics

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

Populate ViewModel

parent 652f79b4
No related branches found
No related tags found
No related merge requests found
......@@ -10,12 +10,16 @@ class GameViewModel: ViewModel() {
private var _currentWordCount = 0
val currentWordCount: Int
get() = _currentWordCount
private var _currentScrambledWord = "test"
private lateinit var _currentScrambledWord: String
val currentScrambledWord: String
get() = _currentScrambledWord
private var wordsList: MutableList<String> = mutableListOf()
private lateinit var currentWord: String
init {
Log.d("GameFragment", "GameViewModel created!")
getNextWord()
}
override fun onCleared() {
......@@ -23,4 +27,27 @@ class GameViewModel: ViewModel() {
Log.d("GameFragment", "GameViewModel destroyed!")
}
fun getNextWord() {
currentWord = allWordsList.random()
val tempWord = currentWord.toCharArray()
tempWord.shuffle()
while (String(tempWord).equals(currentWord, false)) {
tempWord.shuffle()
}
if (wordsList.contains(currentWord)) {
getNextWord()
} else {
_currentScrambledWord = String(tempWord)
++_currentWordCount
wordsList.add(currentWord)
}
}
fun nextWord(): Boolean {
return if (currentWordCount < MAX_NO_OF_WORDS) {
getNextWord()
true
} else false
}
}
\ 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