-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaction_game.html
More file actions
100 lines (94 loc) · 3.12 KB
/
reaction_game.html
File metadata and controls
100 lines (94 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>반응 속도 테스트</title>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 40px auto; text-align: center; }
h1 { color: #333; }
.game-description { font-size: 1.1em; color: #555; }
#reaction-box {
width: 200px;
height: 200px;
margin: 20px auto;
display: flex;
align-items: center;
justify-content: center;
background-color: red;
cursor: pointer;
color: #fff;
font-size: 1.5rem;
font-weight: bold;
user-select: none;
border-radius: 10px;
transition: background-color 0.3s;
}
#reaction-result { font-size: 1.2rem; font-weight: bold; margin-top: 10px; }
.back-button { margin-top: 20px; padding: 10px 20px; background-color: #555; color: white; text-decoration: none; border-radius: 5px; }
.back-button:hover { background-color: #333; }
</style>
<a href="index.html">메인으로 돌아가기</a>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8993912829492684"
crossorigin="anonymous">
</script>
</head>
<body>
<h1>반응 속도 테스트</h1>
<p class="game-description">상자가 초록색으로 변하는 순간 클릭하세요.</p>
<div id="reaction-box">시작</div>
<p id="reaction-result"></p>
<a href="index.html" class="back-button">메인으로 돌아가기</a>
<script>
let reactionStart = 0;
let reactionTimeout;
let state = 'ready';
const box = document.getElementById('reaction-box');
function evaluate(time) {
if (time <= 70) {
return `대단해요! ${time} ms`;
} else if (time <= 100) {
return `훌륭해요! ${time} ms`;
} else if (time <= 150) {
return `좋아요! ${time} ms`;
} else if (time <= 200) {
return `나쁘지 않네요. ${time} ms`;
} else if (time <= 250) {
return `느려요! ${time} ms`;
}
return `너무 느려요! ${time} ms`;
}
function startWaiting() {
document.getElementById('reaction-result').textContent = '';
box.textContent = '';
const delay = Math.random() * 2000 + 1000; // 1-3 seconds
reactionTimeout = setTimeout(() => {
state = 'active';
box.style.backgroundColor = 'green';
reactionStart = Date.now();
}, delay);
}
box.addEventListener('click', () => {
if (state === 'ready') {
state = 'waiting';
box.textContent = '기다리는 중...';
startWaiting();
} else if (state === 'waiting') {
clearTimeout(reactionTimeout);
document.getElementById('reaction-result').textContent = '너무 일찍 클릭했어요!';
state = 'ready';
box.style.backgroundColor = 'red';
box.textContent = '시작';
} else if (state === 'active') {
const reactionTime = Date.now() - reactionStart;
document.getElementById('reaction-result').textContent = evaluate(reactionTime);
state = 'ready';
box.style.backgroundColor = 'red';
box.textContent = '시작';
clearTimeout(reactionTimeout);
reactionStart = 0;
}
});
</script>
</body>
</html>