Skip to content

Commit

Permalink
Fix bug related to multiple clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
ArditNimanaj committed Aug 4, 2022
1 parent 73115e4 commit 7d2a66c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions app/src/main/java/com/mojo/myapplication/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlin.random.Random

class MainActivity : AppCompatActivity() {
private val colors = listOf(
Ngjyra("NgjyraDiqka", Color.parseColor("#00ff00")),
Ngjyra("Black", Color.parseColor("#000000")),
Ngjyra("Red", Color.RED),
Ngjyra("BLUE", Color.BLUE),
Expand All @@ -28,6 +27,7 @@ class MainActivity : AppCompatActivity() {
lateinit var scoreText: TextView
var score = 0


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -42,6 +42,11 @@ class MainActivity : AppCompatActivity() {
}

fun nextRound() {
var clicked1=false
var clicked2=false
var clicked3=false
var clicked4=false

scoreText.text = "Score: $score"
val someColors = colors.toMutableList()

Expand All @@ -68,6 +73,7 @@ class MainActivity : AppCompatActivity() {
var count = 0

view1.setOnClickListener {
if(clicked1==false){
if (firstColor == winningColor) {
score--
nextRound()
Expand All @@ -78,10 +84,12 @@ class MainActivity : AppCompatActivity() {
score++
nextRound()
}
}
}}
clicked1=true
}

view2.setOnClickListener {
if(clicked2==false){
if (secondColor == winningColor) {
score--
nextRound()
Expand All @@ -93,9 +101,12 @@ class MainActivity : AppCompatActivity() {
nextRound()
}
}
}
clicked2=true
}

view3.setOnClickListener {
if(clicked3==false){
if (thirdColor == winningColor) {
score--
nextRound()
Expand All @@ -108,8 +119,11 @@ class MainActivity : AppCompatActivity() {
}
}
}
clicked3=true
}

view4.setOnClickListener {
if(clicked4==false){
if (fourthColor == winningColor) {
score--
nextRound()
Expand All @@ -122,6 +136,8 @@ class MainActivity : AppCompatActivity() {
}
}
}
clicked4=true
}
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
android:textSize="30sp"
android:textColor="#000"
android:background="#fff"
android:clickable="true"
android:padding="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

Expand Down

0 comments on commit 7d2a66c

Please sign in to comment.