-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0de275
commit 5f26629
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>反应力测试</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="game-container"></div> | ||
<button id="start-button">开始测试</button> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
document.getElementById('start-button').addEventListener('click', startGame); | ||
|
||
let startTime; | ||
let reactionTimes = []; | ||
|
||
function startGame() { | ||
document.getElementById('start-button').classList.add('hidden'); | ||
showRandomShape(); | ||
} | ||
|
||
function showRandomShape() { | ||
const shape = document.createElement('div'); | ||
shape.classList.add('shape'); | ||
shape.style.top = `${Math.random() * (window.innerHeight - 50)}px`; | ||
shape.style.left = `${Math.random() * (window.innerWidth - 50)}px`; | ||
shape.style.backgroundColor = getRandomColor(); | ||
shape.onclick = shapeClicked; | ||
|
||
document.body.appendChild(shape); | ||
startTime = new Date(); | ||
} | ||
|
||
function shapeClicked() { | ||
const endTime = new Date(); | ||
const reactionTime = (endTime - startTime) / 1000; | ||
reactionTimes.push(reactionTime); | ||
this.remove(); | ||
|
||
if (reactionTimes.length < 10) { | ||
setTimeout(showRandomShape, Math.random() * 2000); | ||
} else { | ||
endGame(); | ||
} | ||
} | ||
|
||
function getRandomColor() { | ||
const colors = ['red', 'blue', 'green', 'yellow', 'purple']; | ||
return colors[Math.floor(Math.random() * colors.length)]; | ||
} | ||
|
||
function endGame() { | ||
const average = reactionTimes.reduce((a, b) => a + b, 0) / reactionTimes.length; | ||
alert(`测试完成!\n平均反应时间:${average.toFixed(2)} 秒`); | ||
document.getElementById('start-button').classList.remove('hidden'); | ||
reactionTimes = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: Arial, sans-serif; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#start-button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
color: white; | ||
background-color: #007bff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.3s, transform 0.2s; | ||
outline: none; | ||
} | ||
|
||
#start-button:hover { | ||
background-color: #0056b3; | ||
transform: scale(1.05); | ||
} | ||
|
||
#start-button:active { | ||
transform: scale(0.95); | ||
} | ||
|
||
.shape { | ||
width: 50px; | ||
height: 50px; | ||
position: fixed; | ||
cursor: pointer; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
} |