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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Tetris Game by MOUSE(VIDraft-mouse1.hf.space)</title>
|
7 |
+
<style>
|
8 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
9 |
+
body {
|
10 |
+
background: #1a1a1a;
|
11 |
+
display: flex;
|
12 |
+
flex-direction: column;
|
13 |
+
align-items: center;
|
14 |
+
justify-content: center;
|
15 |
+
min-height: 100vh;
|
16 |
+
font-family: Arial, sans-serif;
|
17 |
+
padding: 20px;
|
18 |
+
}
|
19 |
+
.title {
|
20 |
+
color: #00f0f0;
|
21 |
+
font-size: 2.5rem;
|
22 |
+
margin-bottom: 0.5rem;
|
23 |
+
text-align: center;
|
24 |
+
text-shadow: 3px 3px 6px rgba(0,0,0,0.5);
|
25 |
+
}
|
26 |
+
.subtitle {
|
27 |
+
color: #f0a000;
|
28 |
+
font-size: 1rem;
|
29 |
+
text-align: center;
|
30 |
+
margin-bottom: 0.3rem;
|
31 |
+
}
|
32 |
+
.website {
|
33 |
+
color: #00f0f0;
|
34 |
+
font-size: 0.9rem;
|
35 |
+
text-align: center;
|
36 |
+
margin-bottom: 2rem;
|
37 |
+
}
|
38 |
+
|
39 |
+
.game-container {
|
40 |
+
display: flex;
|
41 |
+
gap: 20px;
|
42 |
+
}
|
43 |
+
#game-board {
|
44 |
+
border: 2px solid #333;
|
45 |
+
background: #000;
|
46 |
+
}
|
47 |
+
.side-panel {
|
48 |
+
display: flex;
|
49 |
+
flex-direction: column;
|
50 |
+
gap: 20px;
|
51 |
+
color: white;
|
52 |
+
}
|
53 |
+
.next-piece {
|
54 |
+
width: 150px;
|
55 |
+
height: 150px;
|
56 |
+
border: 2px solid #333;
|
57 |
+
background: #000;
|
58 |
+
}
|
59 |
+
.score-board, .controls, .leaderboard {
|
60 |
+
padding: 10px;
|
61 |
+
background: #333;
|
62 |
+
border-radius: 5px;
|
63 |
+
}
|
64 |
+
.controls p {
|
65 |
+
margin: 5px 0;
|
66 |
+
font-size: 14px;
|
67 |
+
}
|
68 |
+
.title strong { color: #f0a000; }
|
69 |
+
.leaderboard {
|
70 |
+
margin-top: 20px;
|
71 |
+
width: 300px;
|
72 |
+
}
|
73 |
+
.leaderboard h3 {
|
74 |
+
color: #00f0f0;
|
75 |
+
margin-bottom: 10px;
|
76 |
+
}
|
77 |
+
.leaderboard-list {
|
78 |
+
list-style: none;
|
79 |
+
}
|
80 |
+
.leaderboard-list li {
|
81 |
+
display: flex;
|
82 |
+
justify-content: space-between;
|
83 |
+
margin: 5px 0;
|
84 |
+
padding: 3px 0;
|
85 |
+
border-bottom: 1px solid #444;
|
86 |
+
}
|
87 |
+
#player-input {
|
88 |
+
position: fixed;
|
89 |
+
top: 50%;
|
90 |
+
left: 50%;
|
91 |
+
transform: translate(-50%, -50%);
|
92 |
+
background: #333;
|
93 |
+
padding: 20px;
|
94 |
+
border-radius: 10px;
|
95 |
+
display: none;
|
96 |
+
flex-direction: column;
|
97 |
+
gap: 10px;
|
98 |
+
z-index: 1000;
|
99 |
+
color: white;
|
100 |
+
}
|
101 |
+
#player-input input {
|
102 |
+
padding: 5px;
|
103 |
+
border-radius: 3px;
|
104 |
+
border: none;
|
105 |
+
}
|
106 |
+
#player-input button {
|
107 |
+
padding: 5px;
|
108 |
+
background: #00f0f0;
|
109 |
+
border: none;
|
110 |
+
border-radius: 3px;
|
111 |
+
cursor: pointer;
|
112 |
+
}
|
113 |
+
</style>
|
114 |
+
</head>
|
115 |
+
<body>
|
116 |
+
<h1 class="title">MOUSE Autonomous Tetris</h1>
|
117 |
+
<p class="subtitle">"One-minute creation by AI Coding Autonomous Agent MOUSE"</p>
|
118 |
+
<p class="website">https://VIDraft-mouse1.hf.space</p>
|
119 |
+
|
120 |
+
<div class="game-container">
|
121 |
+
<canvas id="game-board" width="300" height="600"></canvas>
|
122 |
+
<div class="side-panel">
|
123 |
+
<div class="next-piece">
|
124 |
+
<canvas id="next-piece-canvas" width="150" height="150"></canvas>
|
125 |
+
</div>
|
126 |
+
<div class="score-board">
|
127 |
+
<h3>Score: <span id="score">0</span></h3>
|
128 |
+
<h3>Lines: <span id="lines">0</span></h3>
|
129 |
+
<h3>Level: <span id="level">1</span></h3>
|
130 |
+
</div>
|
131 |
+
<div class="controls">
|
132 |
+
<h3>Controls:</h3>
|
133 |
+
<p>β β : Move Left/Right</p>
|
134 |
+
<p>β : Soft Drop</p>
|
135 |
+
<p>Space : Hard Drop</p>
|
136 |
+
<p>β : Rotate</p>
|
137 |
+
</div>
|
138 |
+
<div class="leaderboard">
|
139 |
+
<h3>Top 10 Scores</h3>
|
140 |
+
<ul class="leaderboard-list" id="leaderboard"></ul>
|
141 |
+
</div>
|
142 |
+
</div>
|
143 |
+
</div>
|
144 |
+
|
145 |
+
<div id="player-input">
|
146 |
+
<h3>New High Score!</h3>
|
147 |
+
<input type="text" id="player-name" placeholder="Enter your name" maxlength="10">
|
148 |
+
<button onclick="submitScore()">Submit</button>
|
149 |
+
</div>
|
150 |
+
|
151 |
+
<script>
|
152 |
+
// Game variables
|
153 |
+
const canvas = document.getElementById('game-board');
|
154 |
+
const ctx = canvas.getContext('2d');
|
155 |
+
const nextPieceCanvas = document.getElementById('next-piece-canvas');
|
156 |
+
const nextPieceCtx = nextPieceCanvas.getContext('2d');
|
157 |
+
|
158 |
+
const BLOCK_SIZE = 30;
|
159 |
+
const BOARD_WIDTH = 10;
|
160 |
+
const BOARD_HEIGHT = 20;
|
161 |
+
|
162 |
+
let board = Array(BOARD_HEIGHT).fill().map(() => Array(BOARD_WIDTH).fill(0));
|
163 |
+
let score = 0;
|
164 |
+
let lines = 0;
|
165 |
+
let level = 1;
|
166 |
+
let gameLoop;
|
167 |
+
let currentPiece;
|
168 |
+
let nextPiece;
|
169 |
+
|
170 |
+
const SHAPES = [
|
171 |
+
[[1, 1, 1, 1]], // I
|
172 |
+
[[1, 1], [1, 1]], // O
|
173 |
+
[[0, 1, 1], [1, 1, 0]], // S
|
174 |
+
[[1, 1, 0], [0, 1, 1]], // Z
|
175 |
+
[[1, 0, 0], [1, 1, 1]], // L
|
176 |
+
[[0, 0, 1], [1, 1, 1]], // J
|
177 |
+
[[0, 1, 0], [1, 1, 1]] // T
|
178 |
+
];
|
179 |
+
|
180 |
+
const COLORS = [
|
181 |
+
'#00f0f0', // cyan
|
182 |
+
'#f0f000', // yellow
|
183 |
+
'#00f000', // green
|
184 |
+
'#f00000', // red
|
185 |
+
'#f0a000', // orange
|
186 |
+
'#0000f0', // blue
|
187 |
+
'#a000f0' // purple
|
188 |
+
];
|
189 |
+
|
190 |
+
// Game classes
|
191 |
+
class Piece {
|
192 |
+
constructor(shape = null) {
|
193 |
+
this.shape = shape || SHAPES[Math.floor(Math.random() * SHAPES.length)];
|
194 |
+
this.color = COLORS[SHAPES.findIndex(s => s === this.shape)];
|
195 |
+
this.x = Math.floor((BOARD_WIDTH - this.shape[0].length) / 2);
|
196 |
+
this.y = 0;
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
// Drawing functions
|
201 |
+
function drawBlock(ctx, x, y, color) {
|
202 |
+
ctx.fillStyle = color;
|
203 |
+
ctx.fillRect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE - 1, BLOCK_SIZE - 1);
|
204 |
+
}
|
205 |
+
|
206 |
+
function drawBoard() {
|
207 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
208 |
+
|
209 |
+
for(let y = 0; y < BOARD_HEIGHT; y++) {
|
210 |
+
for(let x = 0; x < BOARD_WIDTH; x++) {
|
211 |
+
if(board[y][x]) {
|
212 |
+
drawBlock(ctx, x, y, board[y][x]);
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
if(currentPiece) {
|
218 |
+
for(let y = 0; y < currentPiece.shape.length; y++) {
|
219 |
+
for(let x = 0; x < currentPiece.shape[y].length; x++) {
|
220 |
+
if(currentPiece.shape[y][x]) {
|
221 |
+
drawBlock(ctx, currentPiece.x + x, currentPiece.y + y, currentPiece.color);
|
222 |
+
}
|
223 |
+
}
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
function drawNextPiece() {
|
229 |
+
nextPieceCtx.clearRect(0, 0, nextPieceCanvas.width, nextPieceCanvas.height);
|
230 |
+
|
231 |
+
const offsetX = (nextPieceCanvas.width - nextPiece.shape[0].length * BLOCK_SIZE) / 2;
|
232 |
+
const offsetY = (nextPieceCanvas.height - nextPiece.shape.length * BLOCK_SIZE) / 2;
|
233 |
+
|
234 |
+
for(let y = 0; y < nextPiece.shape.length; y++) {
|
235 |
+
for(let x = 0; x < nextPiece.shape[y].length; x++) {
|
236 |
+
if(nextPiece.shape[y][x]) {
|
237 |
+
nextPieceCtx.fillStyle = nextPiece.color;
|
238 |
+
nextPieceCtx.fillRect(
|
239 |
+
offsetX + x * BLOCK_SIZE,
|
240 |
+
offsetY + y * BLOCK_SIZE,
|
241 |
+
BLOCK_SIZE - 1,
|
242 |
+
BLOCK_SIZE - 1
|
243 |
+
);
|
244 |
+
}
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
// Game logic functions
|
250 |
+
function isValidMove(piece, offsetX, offsetY, newShape = null) {
|
251 |
+
const shape = newShape || piece.shape;
|
252 |
+
|
253 |
+
for(let y = 0; y < shape.length; y++) {
|
254 |
+
for(let x = 0; x < shape[y].length; x++) {
|
255 |
+
if(shape[y][x]) {
|
256 |
+
const newX = piece.x + x + offsetX;
|
257 |
+
const newY = piece.y + y + offsetY;
|
258 |
+
|
259 |
+
if(newX < 0 || newX >= BOARD_WIDTH || newY >= BOARD_HEIGHT) {
|
260 |
+
return false;
|
261 |
+
}
|
262 |
+
|
263 |
+
if(newY >= 0 && board[newY][newX]) {
|
264 |
+
return false;
|
265 |
+
}
|
266 |
+
}
|
267 |
+
}
|
268 |
+
}
|
269 |
+
return true;
|
270 |
+
}
|
271 |
+
|
272 |
+
function rotatePiece() {
|
273 |
+
const newShape = currentPiece.shape[0].map((_, i) =>
|
274 |
+
currentPiece.shape.map(row => row[i]).reverse()
|
275 |
+
);
|
276 |
+
|
277 |
+
if(isValidMove(currentPiece, 0, 0, newShape)) {
|
278 |
+
currentPiece.shape = newShape;
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
function mergePiece() {
|
283 |
+
for(let y = 0; y < currentPiece.shape.length; y++) {
|
284 |
+
for(let x = 0; x < currentPiece.shape[y].length; x++) {
|
285 |
+
if(currentPiece.shape[y][x]) {
|
286 |
+
board[currentPiece.y + y][currentPiece.x + x] = currentPiece.color;
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
|
292 |
+
function checkLines() {
|
293 |
+
let linesCleared = 0;
|
294 |
+
|
295 |
+
for(let y = BOARD_HEIGHT - 1; y >= 0; y--) {
|
296 |
+
if(board[y].every(cell => cell !== 0)) {
|
297 |
+
board.splice(y, 1);
|
298 |
+
board.unshift(Array(BOARD_WIDTH).fill(0));
|
299 |
+
linesCleared++;
|
300 |
+
y++;
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
if(linesCleared > 0) {
|
305 |
+
lines += linesCleared;
|
306 |
+
score += linesCleared * 100 * level;
|
307 |
+
level = Math.floor(lines / 10) + 1;
|
308 |
+
|
309 |
+
document.getElementById('score').textContent = score;
|
310 |
+
document.getElementById('lines').textContent = lines;
|
311 |
+
document.getElementById('level').textContent = level;
|
312 |
+
}
|
313 |
+
}
|
314 |
+
|
315 |
+
// Leaderboard functions
|
316 |
+
function getLeaderboard() {
|
317 |
+
const leaderboard = JSON.parse(localStorage.getItem('tetrisLeaderboard') || '[]');
|
318 |
+
return leaderboard;
|
319 |
+
}
|
320 |
+
|
321 |
+
function updateLeaderboardDisplay() {
|
322 |
+
const leaderboardElement = document.getElementById('leaderboard');
|
323 |
+
const leaderboard = getLeaderboard();
|
324 |
+
|
325 |
+
leaderboardElement.innerHTML = leaderboard
|
326 |
+
.slice(0, 10)
|
327 |
+
.map((entry, index) => `
|
328 |
+
<li>
|
329 |
+
<span>${index + 1}. ${entry.name}</span>
|
330 |
+
<span>${entry.score}</span>
|
331 |
+
</li>
|
332 |
+
`)
|
333 |
+
.join('');
|
334 |
+
}
|
335 |
+
|
336 |
+
function addScore(name, score) {
|
337 |
+
const leaderboard = getLeaderboard();
|
338 |
+
leaderboard.push({ name, score });
|
339 |
+
leaderboard.sort((a, b) => b.score - a.score);
|
340 |
+
localStorage.setItem('tetrisLeaderboard', JSON.stringify(leaderboard));
|
341 |
+
updateLeaderboardDisplay();
|
342 |
+
}
|
343 |
+
|
344 |
+
function submitScore() {
|
345 |
+
const playerName = document.getElementById('player-name').value.trim();
|
346 |
+
if (playerName) {
|
347 |
+
addScore(playerName, score);
|
348 |
+
document.getElementById('player-input').style.display = 'none';
|
349 |
+
resetGame();
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
// Game control functions
|
354 |
+
function gameOver() {
|
355 |
+
clearInterval(gameLoop);
|
356 |
+
const leaderboard = getLeaderboard();
|
357 |
+
if (leaderboard.length < 10 || score > leaderboard[9]?.score) {
|
358 |
+
document.getElementById('player-input').style.display = 'flex';
|
359 |
+
} else {
|
360 |
+
alert(`Game Over! Score: ${score}`);
|
361 |
+
resetGame();
|
362 |
+
}
|
363 |
+
}
|
364 |
+
|
365 |
+
function resetGame() {
|
366 |
+
board = Array(BOARD_HEIGHT).fill().map(() => Array(BOARD_WIDTH).fill(0));
|
367 |
+
score = 0;
|
368 |
+
lines = 0;
|
369 |
+
level = 1;
|
370 |
+
document.getElementById('score').textContent = score;
|
371 |
+
document.getElementById('lines').textContent = lines;
|
372 |
+
document.getElementById('level').textContent = level;
|
373 |
+
startGame();
|
374 |
+
}
|
375 |
+
|
376 |
+
function update() {
|
377 |
+
if(isValidMove(currentPiece, 0, 1)) {
|
378 |
+
currentPiece.y++;
|
379 |
+
} else {
|
380 |
+
mergePiece();
|
381 |
+
checkLines();
|
382 |
+
|
383 |
+
currentPiece = nextPiece;
|
384 |
+
nextPiece = new Piece();
|
385 |
+
drawNextPiece();
|
386 |
+
|
387 |
+
if(!isValidMove(currentPiece, 0, 0)) {
|
388 |
+
gameOver();
|
389 |
+
}
|
390 |
+
}
|
391 |
+
drawBoard();
|
392 |
+
}
|
393 |
+
|
394 |
+
function startGame() {
|
395 |
+
currentPiece = new Piece();
|
396 |
+
nextPiece = new Piece();
|
397 |
+
drawNextPiece();
|
398 |
+
|
399 |
+
if(gameLoop) clearInterval(gameLoop);
|
400 |
+
gameLoop = setInterval(() => {
|
401 |
+
update();
|
402 |
+
}, 1000 / level);
|
403 |
+
}
|
404 |
+
|
405 |
+
// Event listeners
|
406 |
+
document.addEventListener('keydown', (e) => {
|
407 |
+
switch(e.keyCode) {
|
408 |
+
case 37: // Left
|
409 |
+
if(isValidMove(currentPiece, -1, 0)) {
|
410 |
+
currentPiece.x--;
|
411 |
+
drawBoard();
|
412 |
+
}
|
413 |
+
break;
|
414 |
+
|
415 |
+
case 39: // Right
|
416 |
+
if(isValidMove(currentPiece, 1, 0)) {
|
417 |
+
currentPiece.x++;
|
418 |
+
drawBoard();
|
419 |
+
}
|
420 |
+
break;
|
421 |
+
|
422 |
+
case 40: // Down
|
423 |
+
if(isValidMove(currentPiece, 0, 1)) {
|
424 |
+
currentPiece.y++;
|
425 |
+
score += 1; // Add points for soft drop
|
426 |
+
document.getElementById('score').textContent = score;
|
427 |
+
drawBoard();
|
428 |
+
}
|
429 |
+
break;
|
430 |
+
|
431 |
+
case 38: // Up (Rotate)
|
432 |
+
rotatePiece();
|
433 |
+
drawBoard();
|
434 |
+
break;
|
435 |
+
|
436 |
+
case 32: // Space (Hard Drop)
|
437 |
+
while(isValidMove(currentPiece, 0, 1)) {
|
438 |
+
currentPiece.y++;
|
439 |
+
score += 2; // Add points for hard drop
|
440 |
+
}
|
441 |
+
document.getElementById('score').textContent = score;
|
442 |
+
update();
|
443 |
+
break;
|
444 |
+
}
|
445 |
+
});
|
446 |
+
|
447 |
+
// Initialize game
|
448 |
+
updateLeaderboardDisplay();
|
449 |
+
startGame();
|
450 |
+
</script>
|
451 |
+
</body>
|
452 |
+
</html>
|