-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3cb26a
commit dfacfb2
Showing
11 changed files
with
223 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
app/src/main/java/uz/gita/memorygame/presentation/viewmodels/GameViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
package uz.gita.memorygame.presentation.viewmodels | ||
|
||
import androidx.lifecycle.LiveData | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
|
||
interface GameViewModel { | ||
val reloadGameLiveData : LiveData<Unit> | ||
val countLiveData : LiveData<Int> | ||
|
||
fun getCardsByLevel(countX: Int, countY: Int) : List<Int> | ||
fun userWin() | ||
|
||
fun reloadGame() | ||
fun increaseCount() | ||
} |
18 changes: 16 additions & 2 deletions
18
app/src/main/java/uz/gita/memorygame/presentation/viewmodels/impl/GameViewModelImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
package uz.gita.memorygame.presentation.viewmodels.impl | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import uz.gita.memorygame.domain.AppRepository | ||
import uz.gita.memorygame.presentation.viewmodels.GameViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class GameViewModelImpl | ||
@Inject constructor( | ||
class GameViewModelImpl @Inject constructor( | ||
private val repository: AppRepository | ||
) : GameViewModel, ViewModel() { | ||
override val reloadGameLiveData = MutableLiveData<Unit>() | ||
override val countLiveData = MutableLiveData<Int>(0) | ||
|
||
override fun getCardsByLevel(countX: Int, countY: Int) = | ||
repository.getCardsByLevel(countX, countY) | ||
|
||
override fun userWin() { | ||
countLiveData.value = 0 | ||
} | ||
|
||
override fun reloadGame() { | ||
reloadGameLiveData.value = Unit | ||
countLiveData.value = 0 | ||
} | ||
|
||
override fun increaseCount() { | ||
countLiveData.value = countLiveData.value?.plus(1) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,107 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@drawable/bg_jungle" | ||
tools:context=".presentation.screens.LevelScreen"> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/safariCar" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:scaleX="0" | ||
android:scaleY="0" | ||
android:src="@drawable/car_safari" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<androidx.constraintlayout.widget.Guideline | ||
android:id="@+id/lineHor30" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
app:layout_constraintGuide_percent="0.3" /> | ||
|
||
<androidx.constraintlayout.widget.Guideline | ||
android:id="@+id/lineHor60" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
app:layout_constraintGuide_percent="0.6" /> | ||
|
||
<ImageView | ||
android:id="@+id/tableSafari" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:background="@drawable/bg5" | ||
tools:context=".presentation.screens.LevelScreen"> | ||
|
||
|
||
<ImageView | ||
android:layout_width="150dp" | ||
android:layout_height="60dp" | ||
android:src="@drawable/easy" | ||
android:id="@+id/easy" | ||
android:layout_marginTop="30dp" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintVertical_bias="0.3" | ||
/> | ||
<ImageView | ||
android:layout_width="150dp" | ||
android:layout_height="60dp" | ||
android:src="@drawable/medium" | ||
android:id="@+id/medium" | ||
android:layout_margin="8dp" | ||
app:layout_constraintTop_toBottomOf="@id/easy" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
/> | ||
<ImageView | ||
android:layout_width="150dp" | ||
android:layout_height="60dp" | ||
android:src="@drawable/hard" | ||
android:id="@+id/hard" | ||
android:layout_margin="8dp" | ||
app:layout_constraintTop_toBottomOf="@id/medium" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
android:layout_height="0dp" | ||
android:layout_marginHorizontal="12dp" | ||
android:src="@drawable/table_safari_better" | ||
app:layout_constraintBottom_toTopOf="@id/lineHor30" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<ImageView | ||
android:id="@+id/mapSafari" | ||
android:layout_width="60dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="12dp" | ||
android:src="@drawable/map_safari" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintHorizontal_bias="1" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/lineHor60" /> | ||
|
||
<ImageView | ||
android:id="@+id/treeSafari" | ||
android:layout_width="0dp" | ||
android:src="@drawable/tree_safari" | ||
android:layout_height="100dp" | ||
app:layout_constraintTop_toTopOf="@id/lineHor60" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" /> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/easy" | ||
android:layout_width="150dp" | ||
android:layout_height="60dp" | ||
android:layout_marginTop="30dp" | ||
android:src="@drawable/easy" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.3" /> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/medium" | ||
android:layout_width="150dp" | ||
android:layout_height="60dp" | ||
android:layout_margin="8dp" | ||
android:src="@drawable/medium" | ||
android:visibility="gone" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/easy" /> | ||
|
||
<ImageView | ||
android:id="@+id/hard" | ||
android:layout_width="150dp" | ||
android:layout_height="60dp" | ||
android:layout_margin="8dp" | ||
android:src="@drawable/hard" | ||
android:visibility="gone" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/medium" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|