APmanageur Wi-Fi V1.0
This commit is contained in:
1 parent
95641a8ac8
commit
1f8f295950
9 files changed
+2445
-292
No files matched your search
+587
@@ -0,0 +1,587 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<title>T-Rex Dino Runner - AP Manageur</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
|
||||
body {
|
||||
background: #071326;
|
||||
color: #eef4ff;
|
||||
font-family: "Courier New", Courier, monospace, -apple-system, sans-serif;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
overflow: hidden;
|
||||
padding: 10px;
|
||||
}
|
||||
.game-card {
|
||||
background: #0d1d36;
|
||||
border: 1px solid #223c68;
|
||||
border-radius: 14px;
|
||||
padding: 16px;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(92, 167, 255, 0.15);
|
||||
position: relative;
|
||||
max-width: 700px;
|
||||
width: 100%;
|
||||
}
|
||||
.header-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
color: #9aa8c5;
|
||||
}
|
||||
.scores {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 2px;
|
||||
color: #5ca7ff;
|
||||
}
|
||||
.scores .hi {
|
||||
color: #9aa8c5;
|
||||
margin-right: 12px;
|
||||
}
|
||||
.canvas-wrap {
|
||||
position: relative;
|
||||
background: #f7f7f7;
|
||||
border: 2px solid #223c68;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
transition: background 0.6s ease;
|
||||
}
|
||||
body.night-mode .canvas-wrap {
|
||||
background: #111827;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 220px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.controls-hint {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 12px;
|
||||
font-size: 12px;
|
||||
color: #9aa8c5;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.controls-hint kbd {
|
||||
background: #132746;
|
||||
border: 1px solid #223c68;
|
||||
color: #fff;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.overlay-message {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(7, 19, 38, 0.85);
|
||||
backdrop-filter: blur(2px);
|
||||
z-index: 10;
|
||||
gap: 12px;
|
||||
}
|
||||
.overlay-message h2 {
|
||||
font-size: 22px;
|
||||
color: #ff6b6b;
|
||||
letter-spacing: 3px;
|
||||
}
|
||||
.restart-btn {
|
||||
background: #5ca7ff;
|
||||
color: #071326;
|
||||
border: 0;
|
||||
padding: 8px 20px;
|
||||
border-radius: 6px;
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.restart-btn:hover { background: #7ab7ff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="game-card">
|
||||
<div class="header-bar">
|
||||
<div>🦖 <strong>Chrome T-Rex Runner</strong></div>
|
||||
<div class="scores">
|
||||
<span class="hi">HI <span id="hiScore">00000</span></span>
|
||||
<span id="currentScore">00000</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="canvas-wrap" id="canvasWrap">
|
||||
<canvas id="dinoCanvas" width="640" height="220"></canvas>
|
||||
<div id="gameOverlay" class="overlay-message" style="display:none">
|
||||
<h2>G A M E O V E R</h2>
|
||||
<button class="restart-btn" onclick="resetGame()">🔄 REJOUER (Espace)</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="controls-hint">
|
||||
<div><kbd>Espace</kbd> ou <kbd>⬆️</kbd> : Sauter</div>
|
||||
<div><kbd>⬇️</kbd> : Se baisser / descente rapide</div>
|
||||
<div>Toucher l'écran pour sauter</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Audio synthesizer
|
||||
let audioCtx = null;
|
||||
function playTone(type) {
|
||||
try {
|
||||
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||
const osc = audioCtx.createOscillator();
|
||||
const gain = audioCtx.createGain();
|
||||
osc.connect(gain);
|
||||
gain.connect(audioCtx.destination);
|
||||
const now = audioCtx.currentTime;
|
||||
|
||||
if (type === 'jump') {
|
||||
osc.type = 'square';
|
||||
osc.frequency.setValueAtTime(450, now);
|
||||
osc.frequency.exponentialRampToValueAtTime(700, now + 0.08);
|
||||
gain.gain.setValueAtTime(0.04, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.08);
|
||||
osc.start(now); osc.stop(now + 0.08);
|
||||
} else if (type === 'hit') {
|
||||
osc.type = 'sawtooth';
|
||||
osc.frequency.setValueAtTime(140, now);
|
||||
osc.frequency.linearRampToValueAtTime(60, now + 0.25);
|
||||
gain.gain.setValueAtTime(0.08, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.25);
|
||||
osc.start(now); osc.stop(now + 0.25);
|
||||
} else if (type === 'score') {
|
||||
osc.type = 'sine';
|
||||
osc.frequency.setValueAtTime(587.33, now);
|
||||
osc.frequency.setValueAtTime(880, now + 0.08);
|
||||
gain.gain.setValueAtTime(0.06, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.18);
|
||||
osc.start(now); osc.stop(now + 0.18);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
const canvas = document.getElementById('dinoCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const hiScoreEl = document.getElementById('hiScore');
|
||||
const currentScoreEl = document.getElementById('currentScore');
|
||||
const overlay = document.getElementById('gameOverlay');
|
||||
const canvasWrap = document.getElementById('canvasWrap');
|
||||
|
||||
const GROUND_Y = 180;
|
||||
let highScore = parseInt(localStorage.getItem('ap_dino_hi') || '0', 10);
|
||||
hiScoreEl.textContent = String(highScore).padStart(5, '0');
|
||||
|
||||
let gameStarted = false;
|
||||
let gameOver = false;
|
||||
let score = 0;
|
||||
let gameSpeed = 6;
|
||||
let nextObstacleTimer = 0;
|
||||
let isNight = false;
|
||||
|
||||
// Dinosaur
|
||||
const dino = {
|
||||
x: 40,
|
||||
y: GROUND_Y - 44,
|
||||
width: 44,
|
||||
height: 44,
|
||||
vy: 0,
|
||||
gravity: 0.72,
|
||||
jumpStrength: -11.5,
|
||||
isGrounded: true,
|
||||
isDucking: false,
|
||||
legFrame: 0,
|
||||
legTimer: 0
|
||||
};
|
||||
|
||||
let obstacles = [];
|
||||
let clouds = [];
|
||||
let stars = [];
|
||||
|
||||
// Init clouds
|
||||
for (let i = 0; i < 4; i++) {
|
||||
clouds.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: 20 + Math.random() * 60,
|
||||
speed: 0.5 + Math.random() * 0.8
|
||||
});
|
||||
}
|
||||
// Init stars for night mode
|
||||
for (let i = 0; i < 20; i++) {
|
||||
stars.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * 120,
|
||||
r: Math.random() * 1.5 + 0.5
|
||||
});
|
||||
}
|
||||
|
||||
// Ground bumps
|
||||
let groundOffset = 0;
|
||||
|
||||
function jump() {
|
||||
if (!gameStarted) {
|
||||
gameStarted = true;
|
||||
}
|
||||
if (gameOver) {
|
||||
resetGame();
|
||||
return;
|
||||
}
|
||||
if (dino.isGrounded) {
|
||||
dino.vy = dino.jumpStrength;
|
||||
dino.isGrounded = false;
|
||||
playTone('jump');
|
||||
}
|
||||
}
|
||||
|
||||
function duck(down) {
|
||||
if (!gameStarted || gameOver) return;
|
||||
dino.isDucking = down;
|
||||
if (down && !dino.isGrounded) {
|
||||
dino.vy += 4.5; // Fast drop
|
||||
}
|
||||
}
|
||||
|
||||
function resetGame() {
|
||||
score = 0;
|
||||
gameSpeed = 6;
|
||||
nextObstacleTimer = 50;
|
||||
obstacles = [];
|
||||
dino.y = GROUND_Y - 44;
|
||||
dino.vy = 0;
|
||||
dino.isGrounded = true;
|
||||
dino.isDucking = false;
|
||||
gameOver = false;
|
||||
gameStarted = true;
|
||||
isNight = false;
|
||||
document.body.classList.remove('night-mode');
|
||||
overlay.style.display = 'none';
|
||||
}
|
||||
|
||||
function spawnObstacle() {
|
||||
const isPterodactyl = score > 250 && Math.random() < 0.35;
|
||||
if (isPterodactyl) {
|
||||
const flyHeights = [GROUND_Y - 26, GROUND_Y - 50, GROUND_Y - 72];
|
||||
const flyY = flyHeights[Math.floor(Math.random() * flyHeights.length)];
|
||||
obstacles.push({
|
||||
type: 'ptero',
|
||||
x: canvas.width + 20,
|
||||
y: flyY,
|
||||
width: 36,
|
||||
height: 26,
|
||||
frame: 0,
|
||||
frameTimer: 0
|
||||
});
|
||||
} else {
|
||||
const kinds = [
|
||||
{ width: 16, height: 35 },
|
||||
{ width: 32, height: 35 },
|
||||
{ width: 48, height: 35 },
|
||||
{ width: 22, height: 46 } // Tall
|
||||
];
|
||||
const kind = kinds[Math.floor(Math.random() * kinds.length)];
|
||||
obstacles.push({
|
||||
type: 'cactus',
|
||||
x: canvas.width + 20,
|
||||
y: GROUND_Y - kind.height,
|
||||
width: kind.width,
|
||||
height: kind.height
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function checkCollision(r1, r2) {
|
||||
// Small margin of forgiveness (hitbox padding)
|
||||
const p = 4;
|
||||
return (
|
||||
r1.x + p < r2.x + r2.width &&
|
||||
r1.x + r1.width - p > r2.x &&
|
||||
r1.y + p < r2.y + r2.height &&
|
||||
r1.y + r1.height - p > r2.y
|
||||
);
|
||||
}
|
||||
|
||||
function drawPixelDino(x, y, w, h, isDucking, legFrame, isDead) {
|
||||
ctx.fillStyle = isNight ? '#e5e7eb' : '#535353';
|
||||
|
||||
if (isDucking && dino.isGrounded) {
|
||||
// Ducking body
|
||||
ctx.fillRect(x, y + 18, 54, 22);
|
||||
// Head low
|
||||
ctx.fillRect(x + 40, y + 10, 18, 14);
|
||||
// Eye
|
||||
ctx.fillStyle = isNight ? '#111827' : '#f7f7f7';
|
||||
ctx.fillRect(x + 48, y + 12, 3, 3);
|
||||
ctx.fillStyle = isNight ? '#e5e7eb' : '#535353';
|
||||
// Legs
|
||||
if (legFrame === 0) {
|
||||
ctx.fillRect(x + 10, y + 36, 4, 8);
|
||||
ctx.fillRect(x + 24, y + 36, 4, 8);
|
||||
} else {
|
||||
ctx.fillRect(x + 14, y + 36, 4, 8);
|
||||
ctx.fillRect(x + 28, y + 36, 4, 8);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal standing / running dino
|
||||
// Head
|
||||
ctx.fillRect(x + 22, y, 22, 16);
|
||||
ctx.fillRect(x + 18, y + 6, 6, 10);
|
||||
// Eye
|
||||
ctx.fillStyle = isNight ? '#111827' : '#f7f7f7';
|
||||
ctx.fillRect(x + 26, y + 3, isDead ? 5 : 3, 3);
|
||||
if (isDead) {
|
||||
// X eye
|
||||
ctx.fillRect(x + 28, y + 2, 2, 5);
|
||||
}
|
||||
ctx.fillStyle = isNight ? '#e5e7eb' : '#535353';
|
||||
|
||||
// Snout / mouth
|
||||
ctx.fillRect(x + 36, y + 8, 8, 6);
|
||||
|
||||
// Body
|
||||
ctx.fillRect(x + 10, y + 16, 22, 20);
|
||||
ctx.fillRect(x + 6, y + 20, 6, 12);
|
||||
ctx.fillRect(x, y + 22, 6, 8); // Tail
|
||||
|
||||
// Arm
|
||||
ctx.fillRect(x + 28, y + 22, 8, 3);
|
||||
ctx.fillRect(x + 33, y + 24, 3, 4);
|
||||
|
||||
// Legs
|
||||
if (!dino.isGrounded) {
|
||||
ctx.fillRect(x + 12, y + 36, 4, 8);
|
||||
ctx.fillRect(x + 22, y + 36, 4, 8);
|
||||
} else if (legFrame === 0) {
|
||||
ctx.fillRect(x + 12, y + 36, 4, 8);
|
||||
ctx.fillRect(x + 22, y + 36, 4, 4);
|
||||
} else {
|
||||
ctx.fillRect(x + 12, y + 36, 4, 4);
|
||||
ctx.fillRect(x + 22, y + 36, 4, 8);
|
||||
}
|
||||
}
|
||||
|
||||
function drawCactus(x, y, w, h) {
|
||||
ctx.fillStyle = isNight ? '#34d399' : '#10b981';
|
||||
// Main stem
|
||||
ctx.fillRect(x + w * 0.35, y, w * 0.3, h);
|
||||
// Branches
|
||||
if (w > 20) {
|
||||
ctx.fillRect(x, y + h * 0.25, w * 0.35, h * 0.15);
|
||||
ctx.fillRect(x, y + h * 0.1, w * 0.15, h * 0.25);
|
||||
ctx.fillRect(x + w * 0.65, y + h * 0.4, w * 0.35, h * 0.15);
|
||||
ctx.fillRect(x + w * 0.85, y + h * 0.25, w * 0.15, h * 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
function drawPterodactyl(p) {
|
||||
ctx.fillStyle = isNight ? '#f87171' : '#ef4444';
|
||||
const x = p.x, y = p.y;
|
||||
// Body
|
||||
ctx.fillRect(x + 10, y + 8, 16, 8);
|
||||
// Head & Beak
|
||||
ctx.fillRect(x, y + 10, 10, 4);
|
||||
ctx.fillRect(x + 4, y + 6, 6, 8);
|
||||
// Wings
|
||||
if (p.frame === 0) {
|
||||
ctx.fillRect(x + 14, y, 6, 8); // Up wing
|
||||
} else {
|
||||
ctx.fillRect(x + 14, y + 16, 6, 10); // Down wing
|
||||
}
|
||||
}
|
||||
|
||||
function drawCloud(c) {
|
||||
ctx.fillStyle = isNight ? '#374151' : '#d1d5db';
|
||||
ctx.beginPath();
|
||||
ctx.arc(c.x, c.y, 10, 0, Math.PI * 2);
|
||||
ctx.arc(c.x + 10, c.y - 6, 12, 0, Math.PI * 2);
|
||||
ctx.arc(c.x + 22, c.y, 10, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (gameStarted && !gameOver) {
|
||||
// Increase speed slowly
|
||||
gameSpeed += 0.0018;
|
||||
score += 0.2;
|
||||
const currentIntScore = Math.floor(score);
|
||||
currentScoreEl.textContent = String(currentIntScore).padStart(5, '0');
|
||||
|
||||
// Milestone chime
|
||||
if (currentIntScore > 0 && currentIntScore % 100 === 0 && Math.floor(score - 0.2) % 100 !== 0) {
|
||||
playTone('score');
|
||||
}
|
||||
|
||||
// Day/night shift
|
||||
const nightPeriod = Math.floor(currentIntScore / 500) % 2 === 1;
|
||||
if (nightPeriod !== isNight) {
|
||||
isNight = nightPeriod;
|
||||
if (isNight) document.body.classList.add('night-mode');
|
||||
else document.body.classList.remove('night-mode');
|
||||
}
|
||||
|
||||
// Dino physics
|
||||
dino.vy += dino.gravity;
|
||||
dino.y += dino.vy;
|
||||
const effectiveH = dino.isDucking ? 26 : 44;
|
||||
if (dino.y >= GROUND_Y - effectiveH) {
|
||||
dino.y = GROUND_Y - effectiveH;
|
||||
dino.vy = 0;
|
||||
dino.isGrounded = true;
|
||||
}
|
||||
|
||||
// Leg animation
|
||||
dino.legTimer += gameSpeed;
|
||||
if (dino.legTimer > 40) {
|
||||
dino.legTimer = 0;
|
||||
dino.legFrame = dino.legFrame === 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
// Spawn obstacles
|
||||
nextObstacleTimer -= 1;
|
||||
if (nextObstacleTimer <= 0) {
|
||||
spawnObstacle();
|
||||
nextObstacleTimer = Math.max(45, Math.floor(65 + Math.random() * 85 - (gameSpeed * 2)));
|
||||
}
|
||||
|
||||
// Update obstacles
|
||||
for (let i = obstacles.length - 1; i >= 0; i--) {
|
||||
const obs = obstacles[i];
|
||||
obs.x -= gameSpeed;
|
||||
|
||||
if (obs.type === 'ptero') {
|
||||
obs.frameTimer += 1;
|
||||
if (obs.frameTimer > 10) {
|
||||
obs.frameTimer = 0;
|
||||
obs.frame = obs.frame === 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Collision check
|
||||
const dinoBox = {
|
||||
x: dino.x,
|
||||
y: dino.y,
|
||||
width: dino.isDucking ? 54 : dino.width,
|
||||
height: dino.isDucking ? 26 : dino.height
|
||||
};
|
||||
if (checkCollision(dinoBox, obs)) {
|
||||
gameOver = true;
|
||||
playTone('hit');
|
||||
overlay.style.display = 'flex';
|
||||
if (currentIntScore > highScore) {
|
||||
highScore = currentIntScore;
|
||||
localStorage.setItem('ap_dino_hi', highScore);
|
||||
hiScoreEl.textContent = String(highScore).padStart(5, '0');
|
||||
}
|
||||
}
|
||||
|
||||
if (obs.x + obs.width < -30) {
|
||||
obstacles.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Move clouds
|
||||
clouds.forEach(c => {
|
||||
c.x -= c.speed;
|
||||
if (c.x < -40) c.x = canvas.width + 20;
|
||||
});
|
||||
|
||||
// Ground scroll
|
||||
groundOffset = (groundOffset + gameSpeed) % 40;
|
||||
}
|
||||
|
||||
// DRAW
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Stars in night mode
|
||||
if (isNight) {
|
||||
ctx.fillStyle = '#f9fafb';
|
||||
stars.forEach(s => {
|
||||
ctx.beginPath();
|
||||
ctx.arc(s.x, s.y, s.r, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
});
|
||||
// Moon
|
||||
ctx.fillStyle = '#f3f4f6';
|
||||
ctx.beginPath();
|
||||
ctx.arc(560, 40, 16, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = '#111827';
|
||||
ctx.beginPath();
|
||||
ctx.arc(553, 37, 13, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// Clouds
|
||||
clouds.forEach(drawCloud);
|
||||
|
||||
// Ground Line
|
||||
ctx.strokeStyle = isNight ? '#4b5563' : '#737373';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, GROUND_Y);
|
||||
ctx.lineTo(canvas.width, GROUND_Y);
|
||||
ctx.stroke();
|
||||
|
||||
// Ground texture bumps
|
||||
ctx.fillStyle = isNight ? '#4b5563' : '#737373';
|
||||
for (let x = -groundOffset; x < canvas.width; x += 30) {
|
||||
ctx.fillRect(x + 5, GROUND_Y + 4, 8, 2);
|
||||
ctx.fillRect(x + 18, GROUND_Y + 9, 4, 1.5);
|
||||
}
|
||||
|
||||
// Obstacles
|
||||
obstacles.forEach(obs => {
|
||||
if (obs.type === 'cactus') drawCactus(obs.x, obs.y, obs.width, obs.height);
|
||||
else if (obs.type === 'ptero') drawPterodactyl(obs);
|
||||
});
|
||||
|
||||
// Dino
|
||||
drawPixelDino(dino.x, dino.y, dino.width, dino.height, dino.isDucking, dino.legFrame, gameOver);
|
||||
|
||||
requestAnimationFrame(update);
|
||||
}
|
||||
|
||||
// Input handlers
|
||||
window.addEventListener('keydown', e => {
|
||||
if ([' ', 'ArrowUp'].includes(e.key)) {
|
||||
e.preventDefault();
|
||||
jump();
|
||||
} else if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
duck(true);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('keyup', e => {
|
||||
if (e.key === 'ArrowDown') {
|
||||
duck(false);
|
||||
}
|
||||
});
|
||||
|
||||
canvas.addEventListener('pointerdown', e => {
|
||||
e.preventDefault();
|
||||
jump();
|
||||
});
|
||||
|
||||
update();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,664 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<title>Tetris - AP Manageur Arcade</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
|
||||
body {
|
||||
background: #071326;
|
||||
color: #eef4ff;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
overflow: hidden;
|
||||
padding: 10px;
|
||||
}
|
||||
.arcade-wrap {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
background: #0d1d36;
|
||||
border: 1px solid #223c68;
|
||||
border-radius: 14px;
|
||||
padding: 16px;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(92, 167, 255, 0.15);
|
||||
position: relative;
|
||||
}
|
||||
.canvas-container {
|
||||
position: relative;
|
||||
background: #050d1a;
|
||||
border: 2px solid #223c68;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
.sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
width: 140px;
|
||||
}
|
||||
.panel-box {
|
||||
background: #132746;
|
||||
border: 1px solid #223c68;
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
.panel-box h3 {
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
color: #9aa8c5;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.panel-box .value {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: #5ca7ff;
|
||||
font-family: "Courier New", Courier, monospace;
|
||||
}
|
||||
.preview-canvas {
|
||||
background: #050d1a;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #223c68;
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
.btn {
|
||||
background: #5ca7ff;
|
||||
color: #071326;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
padding: 8px 12px;
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all .15s ease;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
.btn:hover { background: #7ab7ff; transform: translateY(-1px); }
|
||||
.btn.secondary {
|
||||
background: #132746;
|
||||
color: #eef4ff;
|
||||
border: 1px solid #223c68;
|
||||
}
|
||||
.btn.secondary:hover { background: #1c3863; }
|
||||
.controls-help {
|
||||
font-size: 11px;
|
||||
color: #9aa8c5;
|
||||
line-height: 1.5;
|
||||
background: rgba(0,0,0,0.2);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
border: 1px solid rgba(255,255,255,0.05);
|
||||
}
|
||||
.controls-help kbd {
|
||||
background: #223c68;
|
||||
color: #fff;
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
font-size: 10px;
|
||||
font-family: monospace;
|
||||
}
|
||||
/* Touch controls for mobile */
|
||||
.touch-controls {
|
||||
display: none;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
}
|
||||
.touch-btn {
|
||||
background: #132746;
|
||||
border: 1px solid #223c68;
|
||||
color: #eef4ff;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
.touch-btn:active { background: #5ca7ff; color: #071326; }
|
||||
@media (max-width: 600px) {
|
||||
.arcade-wrap { flex-direction: column; align-items: center; padding: 10px; }
|
||||
.sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; justify-content: space-between; }
|
||||
.sidebar .panel-box { flex: 1; min-width: 80px; }
|
||||
.touch-controls { display: grid; }
|
||||
}
|
||||
/* Overlay message */
|
||||
.overlay-msg {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(7, 19, 38, 0.88);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
z-index: 10;
|
||||
backdrop-filter: blur(3px);
|
||||
}
|
||||
.overlay-msg h2 {
|
||||
font-size: 24px;
|
||||
color: #ff6b6b;
|
||||
letter-spacing: 1px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="arcade-wrap">
|
||||
<div class="canvas-container">
|
||||
<canvas id="tetris" width="240" height="480"></canvas>
|
||||
<div id="gameOverlay" class="overlay-msg" style="display:none">
|
||||
<h2 id="overlayTitle">GAME OVER</h2>
|
||||
<div id="overlayScore" style="color:#5ca7ff;font-size:16px;font-weight:700">Score: 0</div>
|
||||
<button class="btn" style="width:auto;padding:8px 24px" onclick="startGame()">REJOUER</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sidebar">
|
||||
<div class="panel-box">
|
||||
<h3>Prochaine</h3>
|
||||
<canvas id="next" class="preview-canvas" width="80" height="80"></canvas>
|
||||
</div>
|
||||
<div class="panel-box">
|
||||
<h3>Score</h3>
|
||||
<div id="score" class="value">0</div>
|
||||
</div>
|
||||
<div class="panel-box">
|
||||
<h3>Lignes</h3>
|
||||
<div id="lines" class="value">0</div>
|
||||
</div>
|
||||
<div class="panel-box">
|
||||
<h3>Niveau</h3>
|
||||
<div id="level" class="value">1</div>
|
||||
</div>
|
||||
<button id="pauseBtn" class="btn secondary" onclick="togglePause()">PAUSE (P)</button>
|
||||
<button class="btn" onclick="startGame()">NOUVEAU</button>
|
||||
|
||||
<div class="controls-help">
|
||||
<div><kbd>⬅️</kbd> <kbd>➡️</kbd> : Gauche / Droite</div>
|
||||
<div><kbd>⬆️</kbd> : Pivoter</div>
|
||||
<div><kbd>⬇️</kbd> : Chute rapide</div>
|
||||
<div><kbd>Espace</kbd> : Drop direct</div>
|
||||
<div><kbd>C</kbd> : Garder en réserve</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="touch-controls">
|
||||
<div class="touch-btn" onclick="moveLeft()">◀</div>
|
||||
<div class="touch-btn" onclick="rotate()">🔄</div>
|
||||
<div class="touch-btn" onclick="moveRight()">▶</div>
|
||||
<div class="touch-btn" onclick="softDrop()">🔽</div>
|
||||
<div class="touch-btn" onclick="hardDrop()" style="grid-column:span 2;background:#5ca7ff;color:#071326;font-weight:700">⬇️ DROP</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Audio synthesizer with Web Audio API
|
||||
let audioCtx = null;
|
||||
function playSound(type) {
|
||||
try {
|
||||
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||
const osc = audioCtx.createOscillator();
|
||||
const gain = audioCtx.createGain();
|
||||
osc.connect(gain);
|
||||
gain.connect(audioCtx.destination);
|
||||
const now = audioCtx.currentTime;
|
||||
|
||||
if (type === 'move') {
|
||||
osc.type = 'triangle';
|
||||
osc.frequency.setValueAtTime(220, now);
|
||||
gain.gain.setValueAtTime(0.04, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.05);
|
||||
osc.start(now); osc.stop(now + 0.05);
|
||||
} else if (type === 'rotate') {
|
||||
osc.type = 'sine';
|
||||
osc.frequency.setValueAtTime(350, now);
|
||||
osc.frequency.exponentialRampToValueAtTime(500, now + 0.08);
|
||||
gain.gain.setValueAtTime(0.06, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.08);
|
||||
osc.start(now); osc.stop(now + 0.08);
|
||||
} else if (type === 'drop') {
|
||||
osc.type = 'sine';
|
||||
osc.frequency.setValueAtTime(150, now);
|
||||
gain.gain.setValueAtTime(0.08, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.1);
|
||||
osc.start(now); osc.stop(now + 0.1);
|
||||
} else if (type === 'clear') {
|
||||
osc.type = 'square';
|
||||
osc.frequency.setValueAtTime(523.25, now);
|
||||
osc.frequency.setValueAtTime(659.25, now + 0.08);
|
||||
osc.frequency.setValueAtTime(783.99, now + 0.16);
|
||||
gain.gain.setValueAtTime(0.08, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.28);
|
||||
osc.start(now); osc.stop(now + 0.28);
|
||||
} else if (type === 'gameover') {
|
||||
osc.type = 'sawtooth';
|
||||
osc.frequency.setValueAtTime(300, now);
|
||||
osc.frequency.linearRampToValueAtTime(100, now + 0.4);
|
||||
gain.gain.setValueAtTime(0.12, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.4);
|
||||
osc.start(now); osc.stop(now + 0.4);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
const canvas = document.getElementById('tetris');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const nextCanvas = document.getElementById('next');
|
||||
const nextCtx = nextCanvas.getContext('2d');
|
||||
|
||||
const COLS = 10;
|
||||
const ROWS = 20;
|
||||
const BLOCK = 24;
|
||||
|
||||
const COLORS = [
|
||||
null,
|
||||
'#00f0ff', // I - Cyan
|
||||
'#2979ff', // J - Blue
|
||||
'#ff9100', // L - Orange
|
||||
'#ffd600', // O - Yellow
|
||||
'#00e676', // S - Green
|
||||
'#d500f9', // T - Purple
|
||||
'#ff1744' // Z - Red
|
||||
];
|
||||
|
||||
const PIECES = 'ILJOTSZ';
|
||||
function createPiece(type) {
|
||||
if (type === 'I') {
|
||||
return [
|
||||
[0, 1, 0, 0],
|
||||
[0, 1, 0, 0],
|
||||
[0, 1, 0, 0],
|
||||
[0, 1, 0, 0],
|
||||
];
|
||||
} else if (type === 'J') {
|
||||
return [
|
||||
[0, 2, 0],
|
||||
[0, 2, 0],
|
||||
[2, 2, 0],
|
||||
];
|
||||
} else if (type === 'L') {
|
||||
return [
|
||||
[0, 3, 0],
|
||||
[0, 3, 0],
|
||||
[0, 3, 3],
|
||||
];
|
||||
} else if (type === 'O') {
|
||||
return [
|
||||
[4, 4],
|
||||
[4, 4],
|
||||
];
|
||||
} else if (type === 'S') {
|
||||
return [
|
||||
[0, 5, 5],
|
||||
[5, 5, 0],
|
||||
[0, 0, 0],
|
||||
];
|
||||
} else if (type === 'T') {
|
||||
return [
|
||||
[0, 6, 0],
|
||||
[6, 6, 6],
|
||||
[0, 0, 0],
|
||||
];
|
||||
} else if (type === 'Z') {
|
||||
return [
|
||||
[7, 7, 0],
|
||||
[0, 7, 7],
|
||||
[0, 0, 0],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
let board = createMatrix(COLS, ROWS);
|
||||
let player = {
|
||||
pos: { x: 0, y: 0 },
|
||||
matrix: null,
|
||||
score: 0,
|
||||
lines: 0,
|
||||
level: 1
|
||||
};
|
||||
let nextPiece = null;
|
||||
let isPaused = false;
|
||||
let isGameOver = false;
|
||||
let dropCounter = 0;
|
||||
let dropInterval = 1000;
|
||||
let lastTime = 0;
|
||||
|
||||
function createMatrix(w, h) {
|
||||
const m = [];
|
||||
while (h--) m.push(new Array(w).fill(0));
|
||||
return m;
|
||||
}
|
||||
|
||||
function collide(b, p) {
|
||||
const [m, o] = [p.matrix, p.pos];
|
||||
for (let y = 0; y < m.length; ++y) {
|
||||
for (let x = 0; x < m[y].length; ++x) {
|
||||
if (m[y][x] !== 0 && (b[y + o.y] && b[y + o.y][x + o.x]) !== 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function merge(b, p) {
|
||||
p.matrix.forEach((row, y) => {
|
||||
row.forEach((value, x) => {
|
||||
if (value !== 0) {
|
||||
b[y + p.pos.y][x + p.pos.x] = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function rotateMatrix(matrix, dir) {
|
||||
for (let y = 0; y < matrix.length; ++y) {
|
||||
for (let x = 0; x < y; ++x) {
|
||||
[matrix[x][y], matrix[y][x]] = [matrix[y][x], matrix[x][y]];
|
||||
}
|
||||
}
|
||||
if (dir > 0) matrix.forEach(row => row.reverse());
|
||||
else matrix.reverse();
|
||||
}
|
||||
|
||||
function playerRotate(dir) {
|
||||
const pos = player.pos.x;
|
||||
let offset = 1;
|
||||
rotateMatrix(player.matrix, dir);
|
||||
while (collide(board, player)) {
|
||||
player.pos.x += offset;
|
||||
offset = -(offset + (offset > 0 ? 1 : -1));
|
||||
if (offset > player.matrix[0].length) {
|
||||
rotateMatrix(player.matrix, -dir);
|
||||
player.pos.x = pos;
|
||||
return;
|
||||
}
|
||||
}
|
||||
playSound('rotate');
|
||||
}
|
||||
|
||||
function playerReset() {
|
||||
if (!nextPiece) nextPiece = createPiece(PIECES[Math.floor(Math.random() * PIECES.length)]);
|
||||
player.matrix = nextPiece;
|
||||
nextPiece = createPiece(PIECES[Math.floor(Math.random() * PIECES.length)]);
|
||||
player.pos.y = 0;
|
||||
player.pos.x = (board[0].length / 2 | 0) - (player.matrix[0].length / 2 | 0);
|
||||
drawNext();
|
||||
|
||||
if (collide(board, player)) {
|
||||
isGameOver = true;
|
||||
playSound('gameover');
|
||||
document.getElementById('gameOverlay').style.display = 'flex';
|
||||
document.getElementById('overlayTitle').textContent = 'GAME OVER';
|
||||
document.getElementById('overlayScore').textContent = 'Score final : ' + player.score;
|
||||
}
|
||||
}
|
||||
|
||||
function arenaSweep() {
|
||||
let rowCount = 0;
|
||||
outer: for (let y = board.length - 1; y >= 0; --y) {
|
||||
for (let x = 0; x < board[y].length; ++x) {
|
||||
if (board[y][x] === 0) continue outer;
|
||||
}
|
||||
const row = board.splice(y, 1)[0].fill(0);
|
||||
board.unshift(row);
|
||||
++y;
|
||||
rowCount++;
|
||||
}
|
||||
|
||||
if (rowCount > 0) {
|
||||
playSound('clear');
|
||||
const points = [0, 100, 300, 500, 800];
|
||||
player.score += (points[rowCount] || 100) * player.level;
|
||||
player.lines += rowCount;
|
||||
player.level = Math.floor(player.lines / 10) + 1;
|
||||
dropInterval = Math.max(120, 1000 - (player.level - 1) * 90);
|
||||
updateScore();
|
||||
}
|
||||
}
|
||||
|
||||
function updateScore() {
|
||||
document.getElementById('score').textContent = player.score;
|
||||
document.getElementById('lines').textContent = player.lines;
|
||||
document.getElementById('level').textContent = player.level;
|
||||
}
|
||||
|
||||
function playerDrop() {
|
||||
player.pos.y++;
|
||||
if (collide(board, player)) {
|
||||
player.pos.y--;
|
||||
merge(board, player);
|
||||
arenaSweep();
|
||||
playerReset();
|
||||
}
|
||||
dropCounter = 0;
|
||||
}
|
||||
|
||||
function hardDrop() {
|
||||
if (isPaused || isGameOver) return;
|
||||
while (!collide(board, player)) {
|
||||
player.pos.y++;
|
||||
}
|
||||
player.pos.y--;
|
||||
merge(board, player);
|
||||
playSound('drop');
|
||||
arenaSweep();
|
||||
playerReset();
|
||||
dropCounter = 0;
|
||||
}
|
||||
|
||||
function moveLeft() {
|
||||
if (isPaused || isGameOver) return;
|
||||
player.pos.x--;
|
||||
if (collide(board, player)) player.pos.x++;
|
||||
else playSound('move');
|
||||
}
|
||||
|
||||
function moveRight() {
|
||||
if (isPaused || isGameOver) return;
|
||||
player.pos.x++;
|
||||
if (collide(board, player)) player.pos.x--;
|
||||
else playSound('move');
|
||||
}
|
||||
|
||||
function softDrop() {
|
||||
if (isPaused || isGameOver) return;
|
||||
playerDrop();
|
||||
}
|
||||
|
||||
function rotate() {
|
||||
if (isPaused || isGameOver) return;
|
||||
playerRotate(1);
|
||||
}
|
||||
|
||||
function togglePause() {
|
||||
if (isGameOver) return;
|
||||
isPaused = !isPaused;
|
||||
document.getElementById('pauseBtn').textContent = isPaused ? 'REPRENDRE' : 'PAUSE (P)';
|
||||
const ov = document.getElementById('gameOverlay');
|
||||
if (isPaused) {
|
||||
ov.style.display = 'flex';
|
||||
document.getElementById('overlayTitle').textContent = 'PAUSE';
|
||||
document.getElementById('overlayScore').textContent = 'Score: ' + player.score;
|
||||
} else {
|
||||
ov.style.display = 'none';
|
||||
lastTime = performance.now();
|
||||
}
|
||||
}
|
||||
|
||||
function drawBlock(c, x, y, colorId, isGhost = false) {
|
||||
const color = COLORS[colorId];
|
||||
if (!color) return;
|
||||
const px = x * BLOCK;
|
||||
const py = y * BLOCK;
|
||||
|
||||
if (isGhost) {
|
||||
c.strokeStyle = color;
|
||||
c.lineWidth = 1.5;
|
||||
c.strokeRect(px + 1, py + 1, BLOCK - 2, BLOCK - 2);
|
||||
c.fillStyle = color + '22';
|
||||
c.fillRect(px + 1, py + 1, BLOCK - 2, BLOCK - 2);
|
||||
return;
|
||||
}
|
||||
|
||||
c.fillStyle = color;
|
||||
c.fillRect(px, py, BLOCK, BLOCK);
|
||||
|
||||
// Light highlight bevel
|
||||
c.fillStyle = 'rgba(255, 255, 255, 0.28)';
|
||||
c.fillRect(px, py, BLOCK, 3);
|
||||
c.fillRect(px, py, 3, BLOCK);
|
||||
|
||||
// Dark shadow bevel
|
||||
c.fillStyle = 'rgba(0, 0, 0, 0.35)';
|
||||
c.fillRect(px + BLOCK - 3, py, 3, BLOCK);
|
||||
c.fillRect(px, py + BLOCK - 3, BLOCK, 3);
|
||||
|
||||
c.strokeStyle = 'rgba(0,0,0,0.4)';
|
||||
c.strokeRect(px, py, BLOCK, BLOCK);
|
||||
}
|
||||
|
||||
function drawGhost() {
|
||||
let ghost = {
|
||||
pos: { x: player.pos.x, y: player.pos.y },
|
||||
matrix: player.matrix
|
||||
};
|
||||
while (!collide(board, ghost)) {
|
||||
ghost.pos.y++;
|
||||
}
|
||||
ghost.pos.y--;
|
||||
ghost.matrix.forEach((row, y) => {
|
||||
row.forEach((value, x) => {
|
||||
if (value !== 0) {
|
||||
drawBlock(ctx, x + ghost.pos.x, y + ghost.pos.y, value, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function draw() {
|
||||
// Background grid
|
||||
ctx.fillStyle = '#050d1a';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.strokeStyle = '#0e203c';
|
||||
ctx.lineWidth = 0.5;
|
||||
for (let x = 0; x <= COLS; x++) {
|
||||
ctx.beginPath(); ctx.moveTo(x * BLOCK, 0); ctx.lineTo(x * BLOCK, ROWS * BLOCK); ctx.stroke();
|
||||
}
|
||||
for (let y = 0; y <= ROWS; y++) {
|
||||
ctx.beginPath(); ctx.moveTo(0, y * BLOCK); ctx.lineTo(COLS * BLOCK, y * BLOCK); ctx.stroke();
|
||||
}
|
||||
|
||||
// Board blocks
|
||||
board.forEach((row, y) => {
|
||||
row.forEach((value, x) => {
|
||||
if (value !== 0) drawBlock(ctx, x, y, value);
|
||||
});
|
||||
});
|
||||
|
||||
// Player piece + Ghost
|
||||
if (player.matrix) {
|
||||
drawGhost();
|
||||
player.matrix.forEach((row, y) => {
|
||||
row.forEach((value, x) => {
|
||||
if (value !== 0) drawBlock(ctx, x + player.pos.x, y + player.pos.y, value);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function drawNext() {
|
||||
nextCtx.fillStyle = '#050d1a';
|
||||
nextCtx.fillRect(0, 0, nextCanvas.width, nextCanvas.height);
|
||||
if (!nextPiece) return;
|
||||
const bSize = 16;
|
||||
const offX = (nextCanvas.width - nextPiece[0].length * bSize) / 2;
|
||||
const offY = (nextCanvas.height - nextPiece.length * bSize) / 2;
|
||||
|
||||
nextPiece.forEach((row, y) => {
|
||||
row.forEach((value, x) => {
|
||||
if (value !== 0) {
|
||||
const px = offX + x * bSize;
|
||||
const py = offY + y * bSize;
|
||||
nextCtx.fillStyle = COLORS[value];
|
||||
nextCtx.fillRect(px, py, bSize, bSize);
|
||||
nextCtx.strokeStyle = 'rgba(0,0,0,0.4)';
|
||||
nextCtx.strokeRect(px, py, bSize, bSize);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function update(time = 0) {
|
||||
if (!isPaused && !isGameOver) {
|
||||
const deltaTime = time - lastTime;
|
||||
lastTime = time;
|
||||
dropCounter += deltaTime;
|
||||
if (dropCounter > dropInterval) {
|
||||
playerDrop();
|
||||
}
|
||||
draw();
|
||||
}
|
||||
requestAnimationFrame(update);
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
board = createMatrix(COLS, ROWS);
|
||||
player.score = 0;
|
||||
player.lines = 0;
|
||||
player.level = 1;
|
||||
dropInterval = 1000;
|
||||
isGameOver = false;
|
||||
isPaused = false;
|
||||
document.getElementById('gameOverlay').style.display = 'none';
|
||||
document.getElementById('pauseBtn').textContent = 'PAUSE (P)';
|
||||
updateScore();
|
||||
nextPiece = null;
|
||||
playerReset();
|
||||
lastTime = performance.now();
|
||||
}
|
||||
|
||||
// Keyboard controls
|
||||
window.addEventListener('keydown', e => {
|
||||
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '].includes(e.key)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
if (e.key === 'p' || e.key === 'P') {
|
||||
togglePause();
|
||||
return;
|
||||
}
|
||||
if (isPaused || isGameOver) return;
|
||||
|
||||
if (e.key === 'ArrowLeft') moveLeft();
|
||||
else if (e.key === 'ArrowRight') moveRight();
|
||||
else if (e.key === 'ArrowDown') softDrop();
|
||||
else if (e.key === 'ArrowUp' || e.key === 'x' || e.key === 'X') rotate();
|
||||
else if (e.key === ' ') hardDrop();
|
||||
});
|
||||
|
||||
startGame();
|
||||
update();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,762 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<title>Zip (LinkedIn) - AP Manageur</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
|
||||
body {
|
||||
background: #071326;
|
||||
color: #eef4ff;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
overflow-x: hidden;
|
||||
padding: 10px;
|
||||
}
|
||||
.game-container {
|
||||
background: #0d1d36;
|
||||
border: 1px solid #223c68;
|
||||
border-radius: 14px;
|
||||
padding: 16px 20px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 20px rgba(92,167,255,0.15);
|
||||
max-width: 540px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
}
|
||||
.top-bar {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.title-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-weight: 700;
|
||||
color: #5ca7ff;
|
||||
font-size: 16px;
|
||||
}
|
||||
.level-selector select {
|
||||
background: #132746;
|
||||
color: #eef4ff;
|
||||
border: 1px solid #223c68;
|
||||
padding: 5px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.stats-bar {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #132746;
|
||||
padding: 8px 14px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #223c68;
|
||||
margin-bottom: 14px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.stats-bar strong {
|
||||
color: #5ca7ff;
|
||||
}
|
||||
.progress-bar-wrap {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
background: #050d1a;
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 14px;
|
||||
border: 1px solid #223c68;
|
||||
}
|
||||
.progress-bar-fill {
|
||||
height: 100%;
|
||||
width: 0%;
|
||||
background: linear-gradient(90deg, #5ca7ff, #32d583);
|
||||
transition: width 0.2s ease;
|
||||
}
|
||||
.board-container {
|
||||
position: relative;
|
||||
background: #050d1a;
|
||||
border: 3px solid #223c68;
|
||||
border-radius: 12px;
|
||||
padding: 8px;
|
||||
box-shadow: inset 0 0 20px rgba(0,0,0,0.6);
|
||||
touch-action: none;
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
position: relative;
|
||||
}
|
||||
.cell {
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
background: #0d1d36;
|
||||
border: 1px solid #1a345e;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
font-weight: 800;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
transition: background 0.15s ease, transform 0.1s ease;
|
||||
}
|
||||
.cell:hover {
|
||||
background: #16315c;
|
||||
}
|
||||
.cell.visited {
|
||||
background: rgba(92, 167, 255, 0.28);
|
||||
border-color: #5ca7ff;
|
||||
}
|
||||
.cell.current {
|
||||
background: #5ca7ff;
|
||||
color: #071326;
|
||||
box-shadow: 0 0 14px #5ca7ff;
|
||||
transform: scale(1.04);
|
||||
}
|
||||
.cell.number-node {
|
||||
color: #ffffff;
|
||||
font-family: monospace;
|
||||
font-size: 22px;
|
||||
text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
.cell.number-node::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 4px;
|
||||
border: 2px dashed rgba(255, 255, 255, 0.3);
|
||||
border-radius: 6px;
|
||||
pointer-events: none;
|
||||
}
|
||||
.cell.number-node.visited-num {
|
||||
color: #32d583;
|
||||
text-shadow: 0 0 10px rgba(50, 213, 131, 0.8);
|
||||
}
|
||||
.cell.wall-right { border-right: 4px solid #ff6b6b !important; }
|
||||
.cell.wall-bottom { border-bottom: 4px solid #ff6b6b !important; }
|
||||
|
||||
/* SVG overlay for path */
|
||||
.path-svg {
|
||||
position: absolute;
|
||||
inset: 8px;
|
||||
pointer-events: none;
|
||||
z-index: 5;
|
||||
}
|
||||
.path-line {
|
||||
fill: none;
|
||||
stroke: #5ca7ff;
|
||||
stroke-width: 6;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
filter: drop-shadow(0 0 6px #5ca7ff);
|
||||
}
|
||||
|
||||
.bottom-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
width: 100%;
|
||||
}
|
||||
.btn {
|
||||
flex: 1;
|
||||
padding: 9px 12px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
border: 1px solid #223c68;
|
||||
background: #132746;
|
||||
color: #eef4ff;
|
||||
transition: all 0.15s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.btn:hover { background: #1c3863; border-color: #5ca7ff; }
|
||||
.btn.primary {
|
||||
background: #5ca7ff;
|
||||
color: #071326;
|
||||
border-color: #5ca7ff;
|
||||
font-weight: 700;
|
||||
}
|
||||
.btn.primary:hover { background: #7ab7ff; }
|
||||
|
||||
.instructions {
|
||||
margin-top: 12px;
|
||||
font-size: 11px;
|
||||
color: #9aa8c5;
|
||||
text-align: center;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* Win overlay */
|
||||
.win-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(7, 19, 38, 0.92);
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
z-index: 20;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
.win-overlay h2 {
|
||||
color: #32d583;
|
||||
font-size: 26px;
|
||||
letter-spacing: 1px;
|
||||
animation: pop 0.4s ease;
|
||||
}
|
||||
@keyframes pop {
|
||||
0% { transform: scale(0.6); opacity: 0; }
|
||||
80% { transform: scale(1.1); }
|
||||
100% { transform: scale(1); opacity: 1; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="game-container">
|
||||
<div class="top-bar">
|
||||
<div class="title-badge">⚡ <span>Zip</span> <span style="font-size:11px;color:#9aa8c5;font-weight:normal">(LinkedIn)</span></div>
|
||||
<div class="level-selector">
|
||||
<select id="levelSelect" onchange="loadSelectedLevel()">
|
||||
<option value="1">Niveau 1 (5×5 Facile)</option>
|
||||
<option value="2">Niveau 2 (5×5 Intermédiaire)</option>
|
||||
<option value="3">Niveau 3 (6×6 Expert)</option>
|
||||
<option value="random">Générateur infini 🎲</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stats-bar">
|
||||
<div>Cases : <strong id="cellCount">1 / 25</strong></div>
|
||||
<div>Objectif : <strong id="nextTargetNum">Atteindre le 2</strong></div>
|
||||
<div>⏱️ <strong id="timerDisplay">00:00</strong></div>
|
||||
</div>
|
||||
|
||||
<div class="progress-bar-wrap">
|
||||
<div id="progressBar" class="progress-bar-fill"></div>
|
||||
</div>
|
||||
|
||||
<div class="board-container" id="boardContainer">
|
||||
<svg id="pathSvg" class="path-svg"></svg>
|
||||
<div id="gridEl" class="grid"></div>
|
||||
|
||||
<div id="winOverlay" class="win-overlay" style="display:none">
|
||||
<h2>🎉 FÉLICITATIONS !</h2>
|
||||
<p style="color:#eef4ff;font-size:14px">Grille entièrement résolue !</p>
|
||||
<p id="winTime" style="color:#5ca7ff;font-size:13px;font-weight:bold"></p>
|
||||
<button class="btn primary" onclick="nextLevelOrReplay()" style="margin-top:8px;padding:8px 24px">Niveau suivant ➡️</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bottom-actions">
|
||||
<button class="btn" onclick="undoMove()">↩️ Annuler</button>
|
||||
<button class="btn" onclick="resetCurrentLevel()">🔄 Recommencer</button>
|
||||
<button class="btn primary" onclick="generateRandomLevel()">🎲 Nouveau défi</button>
|
||||
</div>
|
||||
|
||||
<div class="instructions">
|
||||
Reliez tous les chiffres dans l'ordre (1 ➔ 2 ➔ 3...) en passant par <strong>TOUTES les cases</strong> de la grille exactement une fois, sans croiser les murs rouges ! (Glissez ou cliquez)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Audio synthesizer
|
||||
let audioCtx = null;
|
||||
function playBeep(type) {
|
||||
try {
|
||||
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||
const osc = audioCtx.createOscillator();
|
||||
const gain = audioCtx.createGain();
|
||||
osc.connect(gain);
|
||||
gain.connect(audioCtx.destination);
|
||||
const now = audioCtx.currentTime;
|
||||
|
||||
if (type === 'step') {
|
||||
osc.type = 'sine';
|
||||
osc.frequency.setValueAtTime(440, now);
|
||||
gain.gain.setValueAtTime(0.04, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.05);
|
||||
osc.start(now); osc.stop(now + 0.05);
|
||||
} else if (type === 'checkpoint') {
|
||||
osc.type = 'triangle';
|
||||
osc.frequency.setValueAtTime(587.33, now);
|
||||
osc.frequency.setValueAtTime(880, now + 0.08);
|
||||
gain.gain.setValueAtTime(0.08, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.2);
|
||||
osc.start(now); osc.stop(now + 0.2);
|
||||
} else if (type === 'undo') {
|
||||
osc.type = 'sawtooth';
|
||||
osc.frequency.setValueAtTime(300, now);
|
||||
osc.frequency.linearRampToValueAtTime(200, now + 0.05);
|
||||
gain.gain.setValueAtTime(0.04, now);
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.05);
|
||||
osc.start(now); osc.stop(now + 0.05);
|
||||
} else if (type === 'win') {
|
||||
osc.type = 'triangle';
|
||||
[523.25, 659.25, 783.99, 1046.5].forEach((freq, i) => {
|
||||
const o = audioCtx.createOscillator();
|
||||
const g = audioCtx.createGain();
|
||||
o.connect(g); g.connect(audioCtx.destination);
|
||||
o.frequency.setValueAtTime(freq, now + i * 0.1);
|
||||
g.gain.setValueAtTime(0.08, now + i * 0.1);
|
||||
g.gain.exponentialRampToValueAtTime(0.001, now + i * 0.1 + 0.3);
|
||||
o.start(now + i * 0.1); o.stop(now + i * 0.1 + 0.3);
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// Curated Levels
|
||||
const LEVELS = {
|
||||
1: {
|
||||
width: 5,
|
||||
height: 5,
|
||||
numbers: { '0,0': 1, '4,0': 2, '4,4': 3, '0,4': 4, '2,2': 5 },
|
||||
vWalls: new Set(['1,1', '3,2']),
|
||||
hWalls: new Set(['2,1', '1,3'])
|
||||
},
|
||||
2: {
|
||||
width: 5,
|
||||
height: 5,
|
||||
numbers: { '0,2': 1, '2,0': 2, '4,2': 3, '2,4': 4, '2,2': 5 },
|
||||
vWalls: new Set(['0,1', '3,3']),
|
||||
hWalls: new Set(['1,1', '3,1'])
|
||||
},
|
||||
3: {
|
||||
width: 6,
|
||||
height: 6,
|
||||
numbers: { '0,0': 1, '5,0': 2, '0,5': 3, '5,5': 4, '2,2': 5, '3,3': 6 },
|
||||
vWalls: new Set(['1,1', '3,2', '4,4']),
|
||||
hWalls: new Set(['2,1', '1,4', '3,3'])
|
||||
}
|
||||
};
|
||||
|
||||
let currentConfig = null;
|
||||
let path = [];
|
||||
let isDrawing = false;
|
||||
let timerInterval = null;
|
||||
let secondsElapsed = 0;
|
||||
let maxNumber = 1;
|
||||
|
||||
function startTimer() {
|
||||
if (timerInterval) clearInterval(timerInterval);
|
||||
secondsElapsed = 0;
|
||||
updateTimerDisplay();
|
||||
timerInterval = setInterval(() => {
|
||||
secondsElapsed++;
|
||||
updateTimerDisplay();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function updateTimerDisplay() {
|
||||
const m = String(Math.floor(secondsElapsed / 60)).padStart(2, '0');
|
||||
const s = String(secondsElapsed % 60).padStart(2, '0');
|
||||
document.getElementById('timerDisplay').textContent = `${m}:${s}`;
|
||||
}
|
||||
|
||||
function initLevel(config) {
|
||||
currentConfig = config;
|
||||
path = [];
|
||||
document.getElementById('winOverlay').style.display = 'none';
|
||||
|
||||
// Find highest number in numbers
|
||||
maxNumber = Math.max(...Object.values(config.numbers));
|
||||
|
||||
// Find cell with '1' and make it start
|
||||
let startKey = null;
|
||||
for (const [k, v] of Object.entries(config.numbers)) {
|
||||
if (v === 1) startKey = k;
|
||||
}
|
||||
if (startKey) {
|
||||
const [x, y] = startKey.split(',').map(Number);
|
||||
path.push({ x, y });
|
||||
}
|
||||
|
||||
renderGrid();
|
||||
renderPath();
|
||||
updateStats();
|
||||
startTimer();
|
||||
}
|
||||
|
||||
function renderGrid() {
|
||||
const grid = document.getElementById('gridEl');
|
||||
const { width, height, numbers, vWalls, hWalls } = currentConfig;
|
||||
|
||||
grid.style.gridTemplateColumns = `repeat(${width}, 1fr)`;
|
||||
grid.innerHTML = '';
|
||||
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
const cell = document.createElement('div');
|
||||
cell.className = 'cell';
|
||||
cell.dataset.x = x;
|
||||
cell.dataset.y = y;
|
||||
|
||||
const key = `${x},${y}`;
|
||||
if (numbers[key] !== undefined) {
|
||||
cell.classList.add('number-node');
|
||||
cell.textContent = numbers[key];
|
||||
}
|
||||
|
||||
if (vWalls && vWalls.has(key)) cell.classList.add('wall-right');
|
||||
if (hWalls && hWalls.has(key)) cell.classList.add('wall-bottom');
|
||||
|
||||
// Events
|
||||
cell.addEventListener('pointerdown', (e) => onPointerDown(x, y, e));
|
||||
cell.addEventListener('pointerenter', (e) => onPointerEnter(x, y, e));
|
||||
|
||||
grid.appendChild(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateStats() {
|
||||
const total = currentConfig.width * currentConfig.height;
|
||||
const count = path.length;
|
||||
document.getElementById('cellCount').textContent = `${count} / ${total}`;
|
||||
|
||||
const pct = Math.round((count / total) * 100);
|
||||
document.getElementById('progressBar').style.width = `${pct}%`;
|
||||
|
||||
// Next expected number
|
||||
let nextExpected = 2;
|
||||
for (const p of path) {
|
||||
const key = `${p.x},${p.y}`;
|
||||
const num = currentConfig.numbers[key];
|
||||
if (num && num === nextExpected) {
|
||||
nextExpected++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nextExpected <= maxNumber) {
|
||||
document.getElementById('nextTargetNum').textContent = `Atteindre le ${nextExpected}`;
|
||||
} else if (count < total) {
|
||||
document.getElementById('nextTargetNum').textContent = `Couvrir les ${total - count} case(s) restante(s)`;
|
||||
} else {
|
||||
document.getElementById('nextTargetNum').textContent = `Terminé ! 🎉`;
|
||||
}
|
||||
}
|
||||
|
||||
function canMoveTo(from, to) {
|
||||
// Orthogonal adjacent only
|
||||
const dx = Math.abs(from.x - to.x);
|
||||
const dy = Math.abs(from.y - to.y);
|
||||
if (dx + dy !== 1) return false;
|
||||
|
||||
// Check walls
|
||||
const { vWalls, hWalls } = currentConfig;
|
||||
if (to.x === from.x + 1) { // Moving Right
|
||||
if (vWalls && vWalls.has(`${from.x},${from.y}`)) return false;
|
||||
} else if (to.x === from.x - 1) { // Moving Left
|
||||
if (vWalls && vWalls.has(`${to.x},${to.y}`)) return false;
|
||||
} else if (to.y === from.y + 1) { // Moving Down
|
||||
if (hWalls && hWalls.has(`${from.x},${from.y}`)) return false;
|
||||
} else if (to.y === from.y - 1) { // Moving Up
|
||||
if (hWalls && hWalls.has(`${from.x},${to.y}`)) return false;
|
||||
}
|
||||
|
||||
// Check numbers constraint: if 'to' is a numbered cell, it MUST be the next expected number
|
||||
const toKey = `${to.x},${to.y}`;
|
||||
const toNum = currentConfig.numbers[toKey];
|
||||
if (toNum !== undefined) {
|
||||
let highestVisited = 1;
|
||||
for (const p of path) {
|
||||
const num = currentConfig.numbers[`${p.x},${p.y}`];
|
||||
if (num && num > highestVisited) highestVisited = num;
|
||||
}
|
||||
if (toNum !== highestVisited + 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onPointerDown(x, y, e) {
|
||||
isDrawing = true;
|
||||
const head = path[path.length - 1];
|
||||
|
||||
// If clicked on an earlier path point, backtrack to it!
|
||||
const existingIdx = path.findIndex(p => p.x === x && p.y === y);
|
||||
if (existingIdx !== -1 && existingIdx < path.length - 1) {
|
||||
path = path.slice(0, existingIdx + 1);
|
||||
playBeep('undo');
|
||||
renderPath();
|
||||
updateStats();
|
||||
return;
|
||||
}
|
||||
|
||||
if (head && canMoveTo(head, { x, y })) {
|
||||
stepTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
function onPointerEnter(x, y, e) {
|
||||
if (!isDrawing) return;
|
||||
const head = path[path.length - 1];
|
||||
if (!head) return;
|
||||
|
||||
// Backtrack if moving back to previous cell
|
||||
if (path.length >= 2) {
|
||||
const prev = path[path.length - 2];
|
||||
if (prev.x === x && prev.y === y) {
|
||||
path.pop();
|
||||
playBeep('undo');
|
||||
renderPath();
|
||||
updateStats();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if already visited
|
||||
if (path.some(p => p.x === x && p.y === y)) return;
|
||||
|
||||
if (canMoveTo(head, { x, y })) {
|
||||
stepTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('pointerup', () => { isDrawing = false; });
|
||||
|
||||
function stepTo(x, y) {
|
||||
path.push({ x, y });
|
||||
const key = `${x},${y}`;
|
||||
if (currentConfig.numbers[key] !== undefined) {
|
||||
playBeep('checkpoint');
|
||||
} else {
|
||||
playBeep('step');
|
||||
}
|
||||
|
||||
renderPath();
|
||||
updateStats();
|
||||
checkWin();
|
||||
}
|
||||
|
||||
function undoMove() {
|
||||
if (path.length > 1) {
|
||||
path.pop();
|
||||
playBeep('undo');
|
||||
renderPath();
|
||||
updateStats();
|
||||
}
|
||||
}
|
||||
|
||||
function resetCurrentLevel() {
|
||||
if (path.length > 0) {
|
||||
path = [path[0]];
|
||||
renderPath();
|
||||
updateStats();
|
||||
startTimer();
|
||||
}
|
||||
}
|
||||
|
||||
function renderPath() {
|
||||
const cells = document.querySelectorAll('.cell');
|
||||
const head = path[path.length - 1];
|
||||
|
||||
// Clear states
|
||||
cells.forEach(c => {
|
||||
c.classList.remove('visited', 'current', 'visited-num');
|
||||
});
|
||||
|
||||
// Visited cells
|
||||
path.forEach((p, idx) => {
|
||||
const c = document.querySelector(`.cell[data-x="${p.x}"][data-y="${p.y}"]`);
|
||||
if (c) {
|
||||
c.classList.add('visited');
|
||||
if (idx === path.length - 1) c.classList.add('current');
|
||||
if (currentConfig.numbers[`${p.x},${p.y}`] !== undefined) {
|
||||
c.classList.add('visited-num');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Draw SVG polyline
|
||||
const svg = document.getElementById('pathSvg');
|
||||
svg.innerHTML = '';
|
||||
if (path.length < 2) return;
|
||||
|
||||
const gridRect = document.getElementById('gridEl').getBoundingClientRect();
|
||||
const points = path.map(p => {
|
||||
const c = document.querySelector(`.cell[data-x="${p.x}"][data-y="${p.y}"]`);
|
||||
const r = c.getBoundingClientRect();
|
||||
const cx = r.left - gridRect.left + r.width / 2;
|
||||
const cy = r.top - gridRect.top + r.height / 2;
|
||||
return `${cx},${cy}`;
|
||||
}).join(' ');
|
||||
|
||||
const poly = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
|
||||
poly.setAttribute('points', points);
|
||||
poly.setAttribute('class', 'path-line');
|
||||
svg.appendChild(poly);
|
||||
}
|
||||
|
||||
function checkWin() {
|
||||
const total = currentConfig.width * currentConfig.height;
|
||||
if (path.length !== total) return;
|
||||
|
||||
// Verify all numbers in sequence
|
||||
let lastNum = 0;
|
||||
for (const p of path) {
|
||||
const num = currentConfig.numbers[`${p.x},${p.y}`];
|
||||
if (num !== undefined) {
|
||||
if (num !== lastNum + 1) return;
|
||||
lastNum = num;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastNum === maxNumber) {
|
||||
// VICTORY!
|
||||
if (timerInterval) clearInterval(timerInterval);
|
||||
playBeep('win');
|
||||
document.getElementById('winTime').textContent = `Temps : ${document.getElementById('timerDisplay').textContent}`;
|
||||
document.getElementById('winOverlay').style.display = 'flex';
|
||||
}
|
||||
}
|
||||
|
||||
function loadSelectedLevel() {
|
||||
const val = document.getElementById('levelSelect').value;
|
||||
if (val === 'random') {
|
||||
generateRandomLevel();
|
||||
} else {
|
||||
initLevel(LEVELS[val]);
|
||||
}
|
||||
}
|
||||
|
||||
function nextLevelOrReplay() {
|
||||
const sel = document.getElementById('levelSelect');
|
||||
const cur = parseInt(sel.value, 10);
|
||||
if (cur < 3) {
|
||||
sel.value = String(cur + 1);
|
||||
loadSelectedLevel();
|
||||
} else {
|
||||
generateRandomLevel();
|
||||
}
|
||||
}
|
||||
|
||||
// Procedural Generator for Infinite Random Levels
|
||||
function generateRandomLevel() {
|
||||
document.getElementById('levelSelect').value = 'random';
|
||||
const w = 5, h = 5;
|
||||
const total = w * h;
|
||||
|
||||
// Self-avoiding walk generator with Warnsdorff heuristic
|
||||
let walk = [];
|
||||
let attempts = 0;
|
||||
while (attempts++ < 100) {
|
||||
walk = tryGenerateHamiltonianPath(w, h);
|
||||
if (walk.length === total) break;
|
||||
}
|
||||
|
||||
if (walk.length < total) {
|
||||
// Fallback to level 1 if failed
|
||||
initLevel(LEVELS[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick checkpoints: 1 at start, and 4 more evenly spaced along the walk
|
||||
const numbers = {};
|
||||
const indices = [0, Math.floor(total * 0.25), Math.floor(total * 0.5), Math.floor(total * 0.75), total - 1];
|
||||
indices.forEach((idx, numIdx) => {
|
||||
const pt = walk[idx];
|
||||
numbers[`${pt.x},${pt.y}`] = numIdx + 1;
|
||||
});
|
||||
|
||||
// Add a couple of random walls that don't block the solution
|
||||
const vWalls = new Set();
|
||||
const hWalls = new Set();
|
||||
const solutionEdges = new Set();
|
||||
for (let i = 0; i < walk.length - 1; i++) {
|
||||
const a = walk[i], b = walk[i+1];
|
||||
if (b.x === a.x + 1) solutionEdges.add(`V:${a.x},${a.y}`);
|
||||
else if (a.x === b.x + 1) solutionEdges.add(`V:${b.x},${b.y}`);
|
||||
else if (b.y === a.y + 1) solutionEdges.add(`H:${a.x},${a.y}`);
|
||||
else if (a.y === b.y + 1) solutionEdges.add(`H:${a.x},${b.y}`);
|
||||
}
|
||||
|
||||
for (let y = 0; y < h; y++) {
|
||||
for (let x = 0; x < w; x++) {
|
||||
if (x < w - 1 && !solutionEdges.has(`V:${x},${y}`) && Math.random() < 0.15) {
|
||||
vWalls.add(`${x},${y}`);
|
||||
}
|
||||
if (y < h - 1 && !solutionEdges.has(`H:${x},${y}`) && Math.random() < 0.15) {
|
||||
hWalls.add(`${x},${y}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initLevel({ width: w, height: h, numbers, vWalls, hWalls });
|
||||
}
|
||||
|
||||
function tryGenerateHamiltonianPath(w, h) {
|
||||
const visited = new Set();
|
||||
const path = [];
|
||||
const startX = Math.floor(Math.random() * w);
|
||||
const startY = Math.floor(Math.random() * h);
|
||||
|
||||
function dfs(x, y) {
|
||||
path.push({ x, y });
|
||||
visited.add(`${x},${y}`);
|
||||
if (path.length === w * h) return true;
|
||||
|
||||
const neighbors = [
|
||||
{ x: x + 1, y }, { x: x - 1, y }, { x, y: y + 1 }, { x, y: y - 1 }
|
||||
].filter(n => n.x >= 0 && n.x < w && n.y >= 0 && n.y < h && !visited.has(`${n.x},${n.y}`));
|
||||
|
||||
// Sort by Warnsdorff's heuristic (fewest unvisited neighbors first)
|
||||
neighbors.sort((a, b) => {
|
||||
const degA = countUnvisitedNeighbors(a.x, a.y, w, h, visited);
|
||||
const degB = countUnvisitedNeighbors(b.x, b.y, w, h, visited);
|
||||
return degA - degB;
|
||||
});
|
||||
|
||||
for (const n of neighbors) {
|
||||
if (dfs(n.x, n.y)) return true;
|
||||
}
|
||||
|
||||
path.pop();
|
||||
visited.delete(`${x},${y}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
dfs(startX, startY);
|
||||
return path;
|
||||
}
|
||||
|
||||
function countUnvisitedNeighbors(x, y, w, h, visited) {
|
||||
return [{ x: x + 1, y }, { x: x - 1, y }, { x, y: y + 1 }, { x, y: y - 1 }]
|
||||
.filter(n => n.x >= 0 && n.x < w && n.y >= 0 && n.y < h && !visited.has(`${n.x},${n.y}`)).length;
|
||||
}
|
||||
|
||||
// Keyboard support (Undo: Z or Backspace)
|
||||
window.addEventListener('keydown', e => {
|
||||
if (e.key === 'z' || e.key === 'Z' || e.key === 'Backspace') {
|
||||
undoMove();
|
||||
}
|
||||
});
|
||||
|
||||
initLevel(LEVELS[1]);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user