Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Unscramble
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
Unscramble
Commits
a35c97e6
Commit
a35c97e6
authored
2 years ago
by
62160052
Browse files
Options
Downloads
Patches
Plain Diff
Populate ViewModel
parent
652f79b4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/example/android/unscramble/ui/game/GameViewModel.kt
+28
-1
28 additions, 1 deletion
...a/com/example/android/unscramble/ui/game/GameViewModel.kt
with
28 additions
and
1 deletion
app/src/main/java/com/example/android/unscramble/ui/game/GameViewModel.kt
+
28
−
1
View file @
a35c97e6
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment