κ°λ¨ν μλλ‘μ΄λ κ²μ κ°λ° - Response Tester [1] (첫λ²μ§Έ κ²μ ꡬν)
μ¬ν μμ ν λ΄μ©μ μλμ κ°λ€.
1. μλλ‘μ΄λ μ€νλμ€μμ κΉνλΈμ μ°κ²°
2. νλ‘μ νΈ μμ±νκ³ κ°λ¨ν μΈν°νμ΄μ€ ꡬν
3. 첫 λ²μ§Έ κ²μμΈ Response Time Test μ‘ν°λΉν° μμ± λ° κΈ°λ³Έ μμ
μ΄μ Response Time Test μ‘ν°λΉν°μμ ν΄μΌ ν μΌμ μλμ κ°λ€.
1. Wait for Green... μΆλ ₯ μ¦μ 2~5μ΄ μ¬μ΄ λλ€ν μκ°μ μ΄λ‘μ νλ©΄ μΆλ ₯νκΈ°
2. μ΄λ‘μ νλ©΄ μΆλ ₯νμλ§μ μκ°μ msλ¨μλ‘ μΈκΈ° μμνμ¬ μ¬μ©μκ° ν°μΉνλ©΄ μμμκ° λ³΄μ¬μ£ΌκΈ°
μ΄μΈμλ ν μΌμ λ§κ² μ§λ§ μ°μ μμ λ κΈ°λ₯λΆν° ꡬνν΄λ³΄λ € νλ€.
.
.
.
10.04 μ κ²°κ³Όλ¬Ό
첫λ²μ§Έ κ²μμΈ λ°μμλ ν μ€νΈλ§ λκ° λ§λ€μ΄λμλ€.
μμΌλ‘ ν΄μΌ ν μΌμ μλμ κ°λ€.
1. λνΉ μμ€ν λμ
2. λλ¨Έμ§ κ²μ μΈκ° λͺ¨λ λ§λ€κΈ°
3. μΈν°νμ΄μ€ μ’λ λ©μκ² λ§λ€κΈ°
κ·Έλ¬λ μ€κ°κ³ μ¬κ° μ¨ν΅μ μ‘°μ¬μ€κ³ μκΈ° λλ¬Έμ, μ§κΈ μνλ‘ νλ μ΄μ€ν μ΄μ λ°°ν¬λ§ ν΄λκ³ λμ€μ μ²μ²ν μ λ°μ΄νΈ ν μμ μ΄λ€.
μ¬κΈ°κΉμ§ κ±Έλ¦° μκ°μ λκ° 4μκ°μ λ κ±Έλ¦° λ―
μ½λλ μλμ κ°μλ° λ§€μ° ννΈμμ
/**********************************
* Name : ResponseTime.kt
* Author : HaeChan Gho
* Introduction : Page for Response Time Test.
********************************** */
package com.ghochobo.study
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.Button
import kotlinx.android.synthetic.main.activity_response_time.*
import java.util.concurrent.ThreadLocalRandom
import android.widget.TextView
import kotlin.properties.Delegates
class ResponseTime : AppCompatActivity() {
lateinit var timerTextView: TextView
var startTime by Delegates.notNull<Long>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_response_time)
timerTextView = findViewById(R.id.timerTextView) // timerTextView μ΄κΈ°ν
startGame()
}
fun startGame() {
val button = findViewById<Button>(R.id.touchbtn)
val view = findViewById<View>(R.id.view)
val waitText = findViewById<View>(R.id.waitText)
val green = findViewById<View>(R.id.Green)
val timerTextView = findViewById<View>(R.id.timerTextView)
view.visibility = View.GONE
timerTextView.visibility = View.GONE
Green.visibility = View.GONE
waitText.visibility = View.GONE
button.setOnClickListener{
// λ²νΌ ν΄λ¦ μ λ²νΌμ΄ μ¬λΌμ§κ³ λΆμμ νλ©΄κ³Ό Wait for Green ν
μ€νΈ 보μ΄κ² ν¨
touchbtn.visibility = View.GONE
view.visibility = View.VISIBLE
waitText.visibility = View.VISIBLE
greenTime()
}
}
// νλ©΄μ λ
ΉμμΌλ‘ λ°κΎΈλ©° μκ°μ μ¬λ ν¨μ
fun greenTime() {
// 2~ 5μ΄ μ¬μ΄ λλ€ν μκ°μ νλ©΄μ μμμ΄ λ°λκ³
// λ°λ μκ°λΆν° μκ°μ 체ν¬νμ¬ μ¬μ©μκ° ν°μΉνκΈ°κΉμ§λ₯Ό 체ν¬ν¨
// μ¬μ©μκ° ν°μΉνλ©΄ ν°μΉνκΈ°κΉμ§ κ±Έλ¦° μκ°μ msλ¨μλ‘ λνλ΄ μ€
val randtime = (2..5).random() // 1. 2μ΄~5 μ¬μ΄ λλ€κ° κ°μ Έμ€κΈ°
Handler(Looper.getMainLooper()).postDelayed({ // 2. λλ€κ°λ§νΌ λλ μ΄ κ±΄ νμ λ
Ήμ μΆλ ₯
startTime = System.currentTimeMillis() // μ΄λ‘ νλ©΄μ΄ λ³΄μ΄λ μκ°μ startTime μ΄κΈ°ν
Green.visibility = View.VISIBLE
}, (randtime.toLong() * 1000)) // λ°λ¦¬μ΄λ¨μλ‘ λμ€κΈ°λλ¬Έμ * 1000 ν΄μ€
Green.setOnClickListener {
val endTime = System.currentTimeMillis()
val elapsedTime = endTime - startTime
timerTextView.text = "ν°μΉκΉμ§ κ±Έλ¦° μκ°: ${elapsedTime}ms"
Green.visibility = View.GONE
timerTextView.visibility = View.VISIBLE
view.visibility = View.GONE
waitText.visibility = View.GONE
}
// 3. μΆλ ₯κ³Ό λμμ μκ°μ²΄ν¬ (timer ν¨μ λ§λ€κΈ°?)
// 4. μ¬μ©μκ° ν°μΉμ νμ΄λ¨Έ μ μ§νκ³ κ²°κ³Όλ₯Ό msλ¨μλ‘ λ³΄μ¬μ€
}
}