-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.html
81 lines (74 loc) · 2.65 KB
/
game.html
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
<!DOCTYPE html>
<html>
<head>
<title>Typewriter Effect</title>
<style>
#text-container {
font-family: monospace;
font-size: 24px;
white-space: pre-wrap;
overflow: hidden;
border-right: .15em solid orange; /* The typewriter cursor */
animation: blink-caret .75s step-end infinite;
}
@keyframes blink-caret {
from, to { border-color: transparent }
50% { border-color: orange; }
}
</style>
</head>
<body>
<div id="text-container"></div>
<script>
var textArray = [
"Hello, world! This is a typewriter effect.",
"This is the second line.",
"And this is the third line.",
"Hello, world! This is a typewriter effect.",
"Hello, world! This is a typewriter effect.",
"This is the second line.",
"And this is the third line.",
"Hello, world! This is a typewriter effect.",
"Hello, world! This is a typewriter effect.",
"This is the second line.",
"And this is the third line.",
"Hello, world! This is a typewriter effect.",
];
var currentLineIndex = 0;
var currentText = textArray[currentLineIndex];
var typingSpeed = 120; // The speed (in milliseconds) at which characters are typed
var isTyping = true;
function typeWriter() {
if (isTyping && i < currentText.length) {
document.getElementById("text-container").innerHTML += currentText.charAt(i);
i++;
//var audio = new Audio('key_sound.mp3'); // Add path to your sound file
//audio.play();
setTimeout(typeWriter, typingSpeed);
} else {
isTyping = false;
document.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
document.getElementById("text-container").innerHTML = currentText; // Complete line
isTyping = true;
i = currentText.length; // Set i to the length of currentText to prevent further typing
setTimeout(clearTextAndNextLine, 1000); // Wait for a brief moment before clearing the text
}
});
}
}
function clearTextAndNextLine() {
document.getElementById("text-container").innerHTML = ""; // Clear the text
currentLineIndex++;
if (currentLineIndex < textArray.length) {
currentText = textArray[currentLineIndex];
i = 0; // Reset the character index
isTyping = true;
typeWriter();
}
}
var i = 0;
typeWriter();
</script>
</body>
</html>