๐Ÿ’ป Project/Response Tester

๊ฐ„๋‹จํ•œ ์•ˆ๋“œ๋กœ์ด๋“œ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ - Response Tester [1] (์ฒซ๋ฒˆ์งธ ๊ฒŒ์ž„ ๊ตฌํ˜„)

๋นต๋ชจ๋ฃจ 2023. 10. 4. 22:17

์—ฌํƒœ ์ž‘์—…ํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

1. ์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค์—์„œ ๊นƒํ—ˆ๋ธŒ์™€ ์—ฐ๊ฒฐ

2. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ณ  ๊ฐ„๋‹จํ•œ ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌํ˜„

๊ฒŒ์ž„ ์‹คํ–‰ ์‹œ ๋งˆ์ฃผํ•˜๊ฒŒ ๋  ๋ฉ”์ธ ํ™”๋ฉด์ด๋‹ค. (์ดˆ๊ฐ„๋‹จ)

3. ์ฒซ ๋ฒˆ์งธ ๊ฒŒ์ž„์ธ Response Time Test ์•กํ‹ฐ๋น„ํ‹ฐ ์ƒ์„ฑ ๋ฐ ๊ธฐ๋ณธ ์ž‘์—…

Response Time Test ๋ฒ„ํŠผ ํ„ฐ์น˜ ์‹œ ์ด๋™ํ•  ํ™”๋ฉด์ด๋‹ค. (์ดˆ๊ฐ„๋‹จ2)

 

 

์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ

 

 

 

์ด์ œ 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๋‹จ์œ„๋กœ ๋ณด์—ฌ์คŒ

    }
}

 

LIST