Files
apmanageur/jeux/demineur.html
T

715 lines
21 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="fr" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Démineur - AP Manageur Arcade</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }
:root, html[data-theme="dark"] {
--bg: #071326;
--card-bg: #0d1d36;
--panel-box: #132746;
--border: #223c68;
--text: #eef4ff;
--muted: #9aa8c5;
--blue: #5ca7ff;
--blue-btn-text: #071326;
--cell-up: #1e365d;
--cell-down: #0c1c36;
--cell-border-light: #2c4d82;
--cell-border-dark: #071326;
--display-bg: #050d1a;
--display-text: #ff453a;
}
html[data-theme="light"] {
--bg: #f2f5fa;
--card-bg: #ffffff;
--panel-box: #e9eef7;
--border: #d2dcec;
--text: #15203a;
--muted: #5b6b8c;
--blue: #1e6ef0;
--blue-btn-text: #ffffff;
--cell-up: #e2e8f0;
--cell-down: #cbd5e1;
--cell-border-light: #ffffff;
--cell-border-dark: #94a3b8;
--display-bg: #1e293b;
--display-text: #ef4444;
}
html[data-theme="winxp"] {
--bg: #ece9d8;
--card-bg: #ece9d8;
--panel-box: #c0c0c0;
--border: #7f9db9;
--text: #000000;
--muted: #444444;
--blue: #0055ea;
--blue-btn-text: #ffffff;
--cell-up: #c0c0c0;
--cell-down: #bdbdbd;
--cell-border-light: #ffffff;
--cell-border-dark: #7b7b7b;
--display-bg: #000000;
--display-text: #ff0000;
font-family: 'Tahoma', sans-serif !important;
}
html[data-theme="macos"][data-macos-mode="light"],
html[data-theme="macos"]:not([data-macos-mode="dark"]) {
--bg: #f5f5f7;
--card-bg: #ffffff;
--panel-box: #f2f2f7;
--border: rgba(0, 0, 0, 0.12);
--text: #1d1d1f;
--muted: #86868b;
--blue: #0071e3;
--blue-btn-text: #ffffff;
--cell-up: #e5e5ea;
--cell-down: #d1d1d6;
--cell-border-light: #ffffff;
--cell-border-dark: #aeaeb2;
--display-bg: #1c1c1e;
--display-text: #ff3b30;
}
html[data-theme="macos"][data-macos-mode="dark"] {
--bg: #1e1e1e;
--card-bg: #2d2d2d;
--panel-box: #3a3a3c;
--border: rgba(255, 255, 255, 0.15);
--text: #f5f5f7;
--muted: #98989d;
--blue: #0a84ff;
--blue-btn-text: #ffffff;
--cell-up: #48484a;
--cell-down: #2c2c2e;
--cell-border-light: #636366;
--cell-border-dark: #1c1c1e;
--display-bg: #000000;
--display-text: #ff453a;
}
html[data-theme="futuristic"] {
--bg: #050811;
--card-bg: #091124;
--panel-box: #0f1c3a;
--border: #00f0ff;
--text: #e6f6ff;
--muted: #64b5f6;
--blue: #00f0ff;
--blue-btn-text: #050811;
--cell-up: #0d2244;
--cell-down: #051024;
--cell-border-light: #00f0ff;
--cell-border-dark: #020713;
--display-bg: #020713;
--display-text: #00f0ff;
}
html[data-theme="hacker"] {
--bg: #000000;
--card-bg: #051206;
--panel-box: #0a1f0c;
--border: #00ff41;
--text: #00ff41;
--muted: #008f11;
--blue: #00ff41;
--blue-btn-text: #000000;
--cell-up: #042407;
--cell-down: #020f04;
--cell-border-light: #00ff41;
--cell-border-dark: #010a02;
--display-bg: #000000;
--display-text: #00ff41;
font-family: 'Courier New', monospace !important;
}
body {
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
overflow-x: hidden;
padding: 4px;
transition: background 0.3s ease, color 0.3s ease;
}
.game-card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 14px;
padding: 10px 14px;
box-shadow: 0 10px 30px rgba(0,0,0,0.4), 0 0 20px rgba(92,167,255,0.1);
display: flex;
flex-direction: column;
align-items: center;
max-width: 540px;
width: 100%;
}
.top-controls {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
margin-bottom: 12px;
gap: 10px;
flex-wrap: wrap;
}
.level-select {
background: var(--panel-box);
color: var(--text);
border: 1px solid var(--border);
padding: 6px 10px;
border-radius: 6px;
font-size: 12px;
cursor: pointer;
}
.flag-toggle-btn {
background: var(--panel-box);
color: var(--text);
border: 1px solid var(--border);
padding: 6px 12px;
border-radius: 6px;
font-size: 12px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 4px;
font-weight: 600;
transition: all 0.15s ease;
}
.flag-toggle-btn.active {
background: #ff453a !important;
color: #ffffff !important;
border-color: #ff453a !important;
box-shadow: 0 0 10px rgba(255,69,58,0.4);
}
.header-bar {
display: flex;
justify-content: space-between;
align-items: center;
background: var(--panel-box);
border: 2px solid var(--border);
border-radius: 8px;
padding: 8px 14px;
width: 100%;
margin-bottom: 12px;
}
.digital-counter {
background: var(--display-bg);
color: var(--display-text);
font-family: 'Courier New', Courier, monospace;
font-size: 26px;
font-weight: 900;
padding: 2px 10px;
border-radius: 4px;
border: 1px solid var(--border);
letter-spacing: 2px;
min-width: 70px;
text-align: center;
text-shadow: 0 0 6px currentColor;
}
.face-btn {
font-size: 26px;
background: var(--cell-up);
border: 2px outset var(--cell-border-light);
border-radius: 50%;
width: 44px;
height: 44px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: transform 0.1s ease;
}
.face-btn:active {
border-style: inset;
transform: scale(0.95);
}
.board-wrap {
overflow: auto;
max-width: 100%;
max-height: 400px;
padding: 4px;
border-radius: 8px;
background: var(--display-bg);
border: 2px solid var(--border);
display: flex;
justify-content: center;
}
.grid {
display: grid;
gap: 1px;
background: var(--border);
border: 2px solid var(--border);
}
.cell {
width: 23px;
height: 23px;
background: var(--cell-up);
border: 2px outset var(--cell-border-light);
display: flex;
align-items: center;
justify-content: center;
font-size: 13px;
font-weight: 800;
cursor: pointer;
user-select: none;
}
.cell.revealed {
background: var(--cell-down);
border: 1px solid rgba(0,0,0,0.1);
cursor: default;
}
.cell.mine-hit {
background: #ff3b30 !important;
}
.c-1 { color: #3b82f6; }
.c-2 { color: #10b981; }
.c-3 { color: #ef4444; }
.c-4 { color: #8b5cf6; }
.c-5 { color: #b91c1c; }
.c-6 { color: #06b6d4; }
.c-7 { color: #111827; }
.c-8 { color: #6b7280; }
.instructions {
font-size: 11.5px;
color: var(--muted);
margin-top: 12px;
text-align: center;
line-height: 1.4;
}
</style>
</head>
<body>
<div class="game-card">
<div class="top-controls">
<select id="diffSelect" class="level-select" onchange="changeDifficulty()">
<option value="easy">Débutant (9×9, 10 mines)</option>
<option value="medium" selected>Intermédiaire (16×16, 40 mines)</option>
<option value="hard">Expert (30×16, 99 mines)</option>
</select>
<button id="flagModeBtn" class="flag-toggle-btn" onclick="toggleFlagMode()">
🚩 <span id="flagModeText">Mode Drapeau : OFF</span>
</button>
</div>
<div class="header-bar">
<div id="mineCount" class="digital-counter">040</div>
<div id="faceBtn" class="face-btn" onclick="initGame()">🙂</div>
<div id="timerDisplay" class="digital-counter">000</div>
</div>
<div class="board-wrap">
<div id="mineGrid" class="grid"></div>
</div>
<div id="mineInstructions" class="instructions">
Clic gauche pour révéler une case, clic droit (ou mode 🚩) pour poser un drapeau. Le 1er clic est toujours sécurisé !
</div>
</div>
<script>
// Theme Management
function setTheme(theme, macosMode) {
if (!theme) theme = 'dark';
document.documentElement.dataset.theme = theme;
if (theme === 'macos' && macosMode) {
document.documentElement.dataset.macosMode = macosMode;
} else {
delete document.documentElement.dataset.macosMode;
}
}
const urlParams = new URLSearchParams(window.location.search);
setTheme(urlParams.get('theme') || 'dark', urlParams.get('macosMode'));
// Game variables & state (declared early to prevent TDZ errors)
const CONFIGS = {
easy: { cols: 9, rows: 9, mines: 10 },
medium: { cols: 16, rows: 16, mines: 40 },
hard: { cols: 30, rows: 16, mines: 99 }
};
let cols = 16, rows = 16, totalMines = 40;
let board = [];
let isGameOver = false;
let isGameWon = false;
let firstClick = true;
let flagsPlaced = 0;
let timer = 0;
let timerId = null;
let isFlagMode = false;
const I18N_MINE = {
fr: {
opt_easy: "Débutant (9×9, 10 mines)",
opt_med: "Intermédiaire (16×16, 40 mines)",
opt_hard: "Expert (30×16, 99 mines)",
flag_on: "Mode Drapeau : ON",
flag_off: "Mode Drapeau : OFF",
instructions: "Clic gauche pour révéler une case, clic droit (ou mode 🚩) pour poser un drapeau. Le 1er clic est toujours sécurisé !"
},
en: {
opt_easy: "Beginner (9×9, 10 mines)",
opt_med: "Intermediate (16×16, 40 mines)",
opt_hard: "Expert (30×16, 99 mines)",
flag_on: "Flag Mode: ON",
flag_off: "Flag Mode: OFF",
instructions: "Left click to reveal cell, right click (or 🚩 mode) to plant flag. First click is always 100% safe!"
}
};
let currentMineLang = 'fr';
function applyMineLang(lang) {
currentMineLang = (lang && (lang.startsWith('en') ? 'en' : 'fr')) || 'fr';
const dict = I18N_MINE[currentMineLang] || I18N_MINE.fr;
const opts = document.getElementById('diffSelect').options;
if (opts.length >= 3) {
opts[0].text = dict.opt_easy;
opts[1].text = dict.opt_med;
opts[2].text = dict.opt_hard;
}
const ft = document.getElementById('flagModeText');
if (ft) ft.textContent = isFlagMode ? dict.flag_on : dict.flag_off;
const mi = document.getElementById('mineInstructions');
if (mi) mi.textContent = dict.instructions;
}
applyMineLang(urlParams.get('lang'));
window.addEventListener('message', e => {
if (e.data && e.data.type === 'themeChange') {
setTheme(e.data.theme, e.data.macosMode);
}
if (e.data && e.data.type === 'langChange') {
applyMineLang(e.data.lang);
}
});
// Audio synthesizer
let audioCtx = null;
function playTone(type) {
try {
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
if (type === 'click') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'triangle';
osc.frequency.setValueAtTime(400, now);
g.gain.setValueAtTime(0.04, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.05);
osc.start(now); osc.stop(now + 0.05);
} else if (type === 'flag') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(600, now);
osc.frequency.setValueAtTime(800, now + 0.05);
g.gain.setValueAtTime(0.05, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.1);
osc.start(now); osc.stop(now + 0.1);
} else if (type === 'boom') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(120, now);
osc.frequency.linearRampToValueAtTime(30, now + 0.35);
g.gain.setValueAtTime(0.12, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.35);
osc.start(now); osc.stop(now + 0.35);
} else if (type === 'win') {
[523.25, 659.25, 783.99, 1046.5].forEach((freq, idx) => {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'triangle';
osc.frequency.setValueAtTime(freq, now + idx * 0.09);
g.gain.setValueAtTime(0.08, now + idx * 0.09);
g.gain.exponentialRampToValueAtTime(0.001, now + idx * 0.09 + 0.25);
osc.start(now + idx * 0.09); osc.stop(now + idx * 0.09 + 0.25);
});
}
} catch (e) {}
}
function toggleFlagMode() {
isFlagMode = !isFlagMode;
const btn = document.getElementById('flagModeBtn');
const text = document.getElementById('flagModeText');
const dict = I18N_MINE[currentMineLang] || I18N_MINE.fr;
if (btn) btn.classList.toggle('active', isFlagMode);
if (text) text.textContent = isFlagMode ? dict.flag_on : dict.flag_off;
}
function changeDifficulty() {
const diff = document.getElementById('diffSelect').value;
const cfg = CONFIGS[diff] || CONFIGS.medium;
cols = cfg.cols;
rows = cfg.rows;
totalMines = cfg.mines;
initGame();
}
function initGame() {
if (timerId) clearInterval(timerId);
timer = 0;
timerId = null;
document.getElementById('timerDisplay').textContent = '000';
isGameOver = false;
isGameWon = false;
firstClick = true;
flagsPlaced = 0;
updateMineCounter();
document.getElementById('faceBtn').textContent = '🙂';
const gridEl = document.getElementById('mineGrid');
gridEl.innerHTML = '';
gridEl.style.gridTemplateColumns = `repeat(${cols}, 23px)`;
board = [];
for (let r = 0; r < rows; r++) {
const row = [];
for (let c = 0; c < cols; c++) {
const cell = {
r, c,
isMine: false,
isRevealed: false,
isFlagged: false,
count: 0,
el: null
};
const el = document.createElement('div');
el.className = 'cell';
el.addEventListener('click', (e) => handleCellClick(cell, e));
el.addEventListener('contextmenu', (e) => {
e.preventDefault();
handleRightClick(cell);
});
cell.el = el;
row.push(cell);
gridEl.appendChild(el);
}
board.push(row);
}
}
function updateMineCounter() {
const remaining = Math.max(-99, totalMines - flagsPlaced);
const str = remaining < 0 ? String(remaining).padStart(3, '0') : String(remaining).padStart(3, '0');
document.getElementById('mineCount').textContent = str;
}
function startTimer() {
if (timerId) return;
timerId = setInterval(() => {
timer++;
if (timer > 999) timer = 999;
document.getElementById('timerDisplay').textContent = String(timer).padStart(3, '0');
}, 1000);
}
function placeMines(safeR, safeC) {
let placed = 0;
while (placed < totalMines) {
const r = Math.floor(Math.random() * rows);
const c = Math.floor(Math.random() * cols);
// Avoid initial click position and its neighbors for a pleasant first opening
if (Math.abs(r - safeR) <= 1 && Math.abs(c - safeC) <= 1) continue;
if (!board[r][c].isMine) {
board[r][c].isMine = true;
placed++;
}
}
// Calculate neighbor counts
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
if (board[r][c].isMine) continue;
let count = 0;
for (let dr = -1; dr <= 1; dr++) {
for (let dc = -1; dc <= 1; dc++) {
const nr = r + dr, nc = c + dc;
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols && board[nr][nc].isMine) {
count++;
}
}
}
board[r][c].count = count;
}
}
}
function handleCellClick(cell, e) {
if (isGameOver || isGameWon) return;
if (isFlagMode) {
handleRightClick(cell);
return;
}
if (cell.isFlagged) return;
if (firstClick) {
firstClick = false;
placeMines(cell.r, cell.c);
startTimer();
}
// If already revealed and clicked, chord click
if (cell.isRevealed) {
chordClick(cell);
return;
}
revealCell(cell);
}
function handleRightClick(cell) {
if (isGameOver || isGameWon || cell.isRevealed) return;
cell.isFlagged = !cell.isFlagged;
playTone('flag');
if (cell.isFlagged) {
cell.el.textContent = '🚩';
flagsPlaced++;
} else {
cell.el.textContent = '';
flagsPlaced--;
}
updateMineCounter();
checkWinCondition();
}
function revealCell(cell) {
if (cell.isRevealed || cell.isFlagged) return;
cell.isRevealed = true;
cell.el.classList.add('revealed');
if (cell.isMine) {
// BOOM
cell.el.classList.add('mine-hit');
cell.el.textContent = '💥';
gameOver(false);
return;
}
playTone('click');
if (cell.count > 0) {
cell.el.textContent = cell.count;
cell.el.classList.add(`c-${cell.count}`);
} else {
// Flood fill 0 cells
for (let dr = -1; dr <= 1; dr++) {
for (let dc = -1; dc <= 1; dc++) {
const nr = cell.r + dr, nc = cell.c + dc;
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols) {
const neighbor = board[nr][nc];
if (!neighbor.isRevealed && !neighbor.isFlagged) {
revealCell(neighbor);
}
}
}
}
}
checkWinCondition();
}
function chordClick(cell) {
if (cell.count === 0) return;
let flagCount = 0;
const neighbors = [];
for (let dr = -1; dr <= 1; dr++) {
for (let dc = -1; dc <= 1; dc++) {
const nr = cell.r + dr, nc = cell.c + dc;
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols && (dr !== 0 || dc !== 0)) {
const n = board[nr][nc];
neighbors.push(n);
if (n.isFlagged) flagCount++;
}
}
}
if (flagCount === cell.count) {
neighbors.forEach(n => {
if (!n.isRevealed && !n.isFlagged) revealCell(n);
});
}
}
function checkWinCondition() {
let unrevealedSafe = 0;
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const cell = board[r][c];
if (!cell.isMine && !cell.isRevealed) {
unrevealedSafe++;
}
}
}
if (unrevealedSafe === 0) {
gameOver(true);
}
}
function gameOver(won) {
if (timerId) clearInterval(timerId);
timerId = null;
if (won) {
isGameWon = true;
document.getElementById('faceBtn').textContent = '😎';
playTone('win');
// Flag remaining mines
board.forEach(row => row.forEach(cell => {
if (cell.isMine && !cell.isFlagged) {
cell.el.textContent = '🚩';
}
}));
document.getElementById('mineCount').textContent = '000';
} else {
isGameOver = true;
document.getElementById('faceBtn').textContent = '😵';
playTone('boom');
// Reveal all mines
board.forEach(row => row.forEach(cell => {
if (cell.isMine && !cell.el.classList.contains('mine-hit')) {
cell.el.textContent = '💣';
cell.el.classList.add('revealed');
} else if (!cell.isMine && cell.isFlagged) {
cell.el.textContent = '❌'; // False flag
}
}));
}
}
initGame();
</script>
</body>
</html>