-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
WordGuessingGame.html
237 lines (210 loc) · 7.17 KB
/
WordGuessingGame.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chaotic Word Guessing Game</title>
<style>
body {
background: linear-gradient(135deg, #000428, #004e92);
margin: 0;
font-family: 'Arial', sans-serif;
color: #00FFFF;
text-align: center;
overflow: hidden;
transition: background-color 1s ease;
}
.game-container {
padding: 20px;
border-radius: 10px;
position: relative;
}
h1 {
font-size: 120px;
margin: 0;
color: #00FFFF;
text-shadow:
0 1px 3px #fff,
0 0 10px rgba(0, 255, 255, 0.8);
animation: move 1s linear infinite;
}
.title {
font-size: 50px;
margin-bottom: 20px;
color: #00FFFF;
text-shadow:
0 1px 3px #fff,
0 0 10px rgba(0, 255, 255, 0.8);
animation: move 1s linear infinite;
}
@keyframes move {
0% { transform: translateY(0); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0); }
}
input[type="text"] {
padding: 10px;
font-size: 20px;
margin-top: 20px;
}
button {
padding: 10px 20px;
margin-top: 10px;
background-color: #ff4500;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #ff6347;
}
.scoreboard {
margin-top: 20px;
font-size: 24px;
}
.floating-keyboard {
position: absolute;
width: 100%;
height: 100%;
}
.key {
position: absolute;
width: 40px;
height: 40px;
background-color: rgba(255, 255, 255, 0.7);
border: 1px solid #00FFFF;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
color: #000;
pointer-events: auto;
transition: transform 0.5s ease, top 0.5s ease, left 0.5s ease;
animation: rotate 5s linear infinite;
}
@keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="game-container">
<div class="title">Word Guessing Game</div>
<h1 id="word-display">CHAOS</h1>
<input type="text" id="guess-input" placeholder="Type your guess...">
<button id="submit-btn">Guess</button>
<div class="scoreboard">Score: <span id="score">0</span></div>
<div class="floating-keyboard"></div>
</div>
<script>
const wordDisplay = document.getElementById('word-display');
const guessInput = document.getElementById('guess-input');
const submitBtn = document.getElementById('submit-btn');
const scoreDisplay = document.getElementById('score');
const floatingKeyboard = document.querySelector('.floating-keyboard');
let score = 0;
let targetWord = "CHAOS";
let chaosTimer;
function startGame() {
guessInput.value = '';
score = 0;
updateScore();
startChaos();
startFloatingKeyboard();
startTimer();
}
function updateScore() {
scoreDisplay.textContent = score;
}
function randomizeWord() {
const wordArray = targetWord.split('');
for (let i = 0; i < wordArray.length; i++) {
if (Math.random() < 0.5) {
wordArray[i] = String.fromCharCode(65 + Math.floor(Math.random() * 26));
}
}
wordDisplay.textContent = wordArray.join('');
changeBackgroundColor();
changeFontSize();
}
function changeBackgroundColor() {
const colors = ['#000428', '#004e92', '#ff4500', '#ff6347', '#00FFFF', '#00FF7F'];
document.body.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
}
function changeFontSize() {
const randomSize = Math.floor(Math.random() * 100 + 80);
wordDisplay.style.fontSize = `${randomSize}px`;
document.querySelector('.title').style.fontSize = `${randomSize / 2}px`;
}
function startChaos() {
clearInterval(chaosTimer);
chaosTimer = setInterval(() => {
randomizeWord();
}, 300);
}
function startFloatingKeyboard() {
floatingKeyboard.innerHTML = '';
const keys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
keys.forEach(key => {
const keyElement = document.createElement('div');
keyElement.className = 'key';
keyElement.textContent = key;
floatingKeyboard.appendChild(keyElement);
setRandomPosition(keyElement);
keyElement.addEventListener('click', () => handleKeyClick(key));
});
floatKeys();
}
function setRandomPosition(element) {
element.style.top = Math.random() * 100 + 'vh';
element.style.left = Math.random() * 100 + 'vw';
}
function floatKeys() {
const keys = document.querySelectorAll('.key');
keys.forEach(key => {
const randomX = (Math.random() - 0.5) * 200;
const randomY = (Math.random() - 0.5) * 200;
key.style.transform = `translate(${randomX}px, ${randomY}px)`;
setTimeout(() => setRandomPosition(key), 1000);
});
setTimeout(floatKeys, 2000);
}
function startTimer() {
let timeLimit = 20000;
const timerInterval = setInterval(() => {
if (timeLimit <= 0) {
clearInterval(timerInterval);
alert("Time's up! Your score: " + score);
startGame();
return;
}
timeLimit -= Math.floor(Math.random() * 1000) + 500;
}, 1000);
}
submitBtn.addEventListener('click', () => {
const guess = guessInput.value.toUpperCase();
if (guess === targetWord) {
score += 1;
updateScore();
resetGame();
} else {
alert("Wrong guess! Try again.");
}
guessInput.value = '';
});
function handleKeyClick(key) {
guessInput.value += key;
}
function resetGame() {
guessInput.value = '';
targetWord = "CHAOS";
randomizeWord();
}
startGame();
</script>
</body>
</html>