์ฌํ ์์ ํ ๋ด์ฉ์ ์๋์ ๊ฐ๋ค.
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๋จ์๋ก ๋ณด์ฌ์ค
}
}