APmanageur Wi-Fi V1.0

This commit is contained in:
yoannmultigaming committed 2026-11-20 02:04:27 +01:00
1 parent 2b33e31589
commit d2a837ea17
7 files changed
+2445 -37

No files matched your search

+12 -6
View File
@@ -6277,7 +6277,7 @@
<!-- 10. Modal Easter Egg Arcade Games (Tetris, Dino, Zipline) -->
<div id="modalEasterEggGames" class="modal-overlay" style="z-index:99999">
<div class="modal-card" style="max-width:760px;width:96%;max-height:92vh;display:flex;flex-direction:column;padding:0;overflow:hidden;border:1px solid var(--blue);box-shadow:0 0 35px rgba(92,167,255,0.25)">
<div class="modal-card" style="max-width:820px;width:96%;max-height:92vh;display:flex;flex-direction:column;padding:0;overflow:hidden;border:1px solid var(--blue);box-shadow:0 0 35px rgba(92,167,255,0.25)">
<div class="modal-header" style="padding:12px 18px;background:var(--panel2);border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px">
<div style="display:flex;align-items:center;gap:10px">
<span style="font-size:22px">🕹️</span>
@@ -6288,10 +6288,13 @@
</h2>
</div>
</div>
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap">
<button type="button" id="btnEggGame_tetris" class="game-switch-btn active" onclick="switchEasterEggGame('tetris')" style="padding:5px 12px;font-size:12px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">🧱 <span>Tetris</span></button>
<button type="button" id="btnEggGame_dino" class="game-switch-btn" onclick="switchEasterEggGame('dino')" style="padding:5px 12px;font-size:12px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">🦖 <span>Dino T-Rex</span></button>
<button type="button" id="btnEggGame_zipline" class="game-switch-btn" onclick="switchEasterEggGame('zipline')" style="padding:5px 12px;font-size:12px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">⚡ <span>Zip (LinkedIn)</span></button>
<div style="display:flex;align-items:center;gap:5px;flex-wrap:wrap">
<button type="button" id="btnEggGame_tetris" class="game-switch-btn active" onclick="switchEasterEggGame('tetris')" style="padding:5px 10px;font-size:11.5px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">🧱 <span>Tetris</span></button>
<button type="button" id="btnEggGame_dino" class="game-switch-btn" onclick="switchEasterEggGame('dino')" style="padding:5px 10px;font-size:11.5px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">🦖 <span>Dino</span></button>
<button type="button" id="btnEggGame_zipline" class="game-switch-btn" onclick="switchEasterEggGame('zipline')" style="padding:5px 10px;font-size:11.5px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">⚡ <span>Zip</span></button>
<button type="button" id="btnEggGame_demineur" class="game-switch-btn" onclick="switchEasterEggGame('demineur')" style="padding:5px 10px;font-size:11.5px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">💣 <span>Démineur</span></button>
<button type="button" id="btnEggGame_pacman" class="game-switch-btn" onclick="switchEasterEggGame('pacman')" style="padding:5px 10px;font-size:11.5px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">🟡 <span>Pac-Man</span></button>
<button type="button" id="btnEggGame_spaceinvaders" class="game-switch-btn" onclick="switchEasterEggGame('spaceinvaders')" style="padding:5px 10px;font-size:11.5px;border-radius:6px;display:inline-flex;align-items:center;gap:4px">👾 <span>Space Invaders</span></button>
<button type="button" class="secondary" style="padding:4px 10px;font-size:16px;margin-left:4px" onclick="closeEasterEggModal()" title="Fermer (Échap)">✕</button>
</div>
</div>
@@ -14465,7 +14468,7 @@ ${vpnBadgeTopo}
window.switchEasterEggGame = function (gameName) {
currentEasterEggGame = gameName;
const validGames = ['tetris', 'dino', 'zipline'];
const validGames = ['tetris', 'dino', 'zipline', 'demineur', 'pacman', 'spaceinvaders'];
if (!validGames.includes(gameName)) gameName = 'tetris';
document.querySelectorAll('.game-switch-btn').forEach(btn => {
@@ -14512,6 +14515,9 @@ ${vpnBadgeTopo}
let g = (m[1] || 'tetris').trim().toLowerCase();
if (g === 'dino' || g === 'dinausore' || g === 'dinosaure' || g === 'trex' || g === 't-rex' || g === 'chrome' || g === 'runner') return 'dino';
if (g === 'zip' || g === 'zipline' || g === 'linkedin') return 'zipline';
if (g === 'demineur' || g === 'minesweeper' || g === 'mine' || g === 'mines') return 'demineur';
if (g === 'pacman' || g === 'pac-man' || g === 'pac') return 'pacman';
if (g === 'spaceinvaders' || g === 'space-invaders' || g === 'space' || g === 'invaders' || g === 'invader') return 'spaceinvaders';
if (g === 'tetris' || g === 'brique' || g === 'bricks' || g === '') return 'tetris';
return 'tetris';
}
+715
View File
@@ -0,0 +1,715 @@
<!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: 10px;
transition: background 0.3s ease, color 0.3s ease;
}
.game-card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 14px;
padding: 16px;
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: 620px;
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: 28px;
height: 28px;
background: var(--cell-up);
border: 2px outset var(--cell-border-light);
display: flex;
align-items: center;
justify-content: center;
font-size: 15px;
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'));
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) {}
}
// Game variables
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;
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}, 28px)`;
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>
+54 -23
View File
@@ -267,7 +267,10 @@
<div class="game-card">
<div class="header-bar">
<div>🦖 <strong id="dinoTitleText">Chrome T-Rex Runner</strong></div>
<div style="display:flex;align-items:center;gap:4px">
🦖 <strong id="dinoTitleText">Chrome T-Rex Runner</strong>
<span id="dinoLevelBadge" style="font-size:11px;padding:2px 8px;border-radius:12px;background:var(--panel-box);border:1px solid var(--border);color:var(--blue);margin-left:8px;font-weight:700;transition:transform 0.2s ease">Niveau 1</span>
</div>
<div class="scores">
<span class="hi">HI <span id="hiScore">00000</span></span>
<span id="currentScore">00000</span>
@@ -324,21 +327,26 @@
}
};
let currentDinoLang = 'fr';
let lastLevel = 1;
function applyDinoLang(lang) {
const l = (lang && (lang.startsWith('en') ? 'en' : 'fr')) || 'fr';
const dict = I18N_DINO[l] || I18N_DINO.fr;
currentDinoLang = (lang && (lang.startsWith('en') ? 'en' : 'fr')) || 'fr';
const dict = I18N_DINO[currentDinoLang] || I18N_DINO.fr;
const tEl = document.getElementById('dinoTitleText');
const goEl = document.getElementById('dinoGameOverText');
const rbEl = document.getElementById('dinoRestartBtn');
const hjEl = document.getElementById('dinoHintJump');
const hdEl = document.getElementById('dinoHintDuck');
const htEl = document.getElementById('dinoHintTouch');
const badge = document.getElementById('dinoLevelBadge');
if (tEl) tEl.textContent = dict.title;
if (goEl) goEl.innerHTML = dict.game_over;
if (rbEl) rbEl.textContent = dict.restart_btn;
if (hjEl) hjEl.innerHTML = dict.hint_jump;
if (hdEl) hdEl.innerHTML = dict.hint_duck;
if (htEl) htEl.textContent = dict.hint_touch;
if (badge) badge.textContent = (currentDinoLang.startsWith('en') ? 'Level ' : 'Niveau ') + lastLevel;
}
applyDinoLang(urlParams.get('lang'));
@@ -477,6 +485,7 @@
gameStarted = true;
score = 0;
gameSpeed = 6;
lastLevel = 1;
nextObstacleTimer = 90; // Période de grâce de 1.5s à chaque reprise
obstacles = [];
dino.y = GROUND_Y - 44;
@@ -487,32 +496,35 @@
overlay.style.display = 'none';
document.body.classList.remove('night-mode');
isNight = false;
const badge = document.getElementById('dinoLevelBadge');
if (badge) badge.textContent = (currentDinoLang.startsWith('en') ? 'Level 1' : 'Niveau 1');
}
function spawnObstacle() {
// Les ptérodactyles n'apparaissent qu'à partir de 450 points
const allowPtero = score > 450;
const type = (allowPtero && Math.random() < 0.28) ? 'ptero' : 'cactus';
// Les ptérodactyles apparaissent dès 280 points (plus palpitant)
const allowPtero = score > 280;
const pteroChance = score > 600 ? 0.35 : 0.25;
const type = (allowPtero && Math.random() < pteroChance) ? 'ptero' : 'cactus';
if (type === 'cactus') {
let isBig = false;
let count = 1;
// Difficulté progressive équitable
if (score < 100) {
// Début : 1 seul petit cactus (accessible pour s'échauffer)
if (score < 120) {
// Niveau 1 : 1 seul petit cactus (accessible)
isBig = false;
count = 1;
} else if (score < 250) {
// 1 cactus petit ou grand
} else if (score < 300) {
// Niveau 2 : 1 cactus petit ou grand
isBig = Math.random() < 0.45;
count = 1;
} else if (score < 450) {
// 1 ou 2 cactus
isBig = Math.random() < 0.4;
} else if (score < 550) {
// Niveau 3 : 1 ou 2 cactus
isBig = Math.random() < 0.45;
count = Math.random() < 0.6 ? 1 : 2;
} else {
// Vitesse élevée : jusqu'à 3 petits ou 2 grands
// Niveaux 4 & 5 : jusqu'à 3 petits ou 2 grands
isBig = Math.random() < 0.45;
count = isBig ? (Math.random() < 0.65 ? 1 : 2) : (Math.floor(Math.random() * 3) + 1);
}
@@ -528,7 +540,7 @@
isBig: isBig
});
} else {
// Ptérodactyles : hauteurs adaptées (haut = passer dessous, bas = sauter par dessus)
// Ptérodactyles : 3 hauteurs distinctes (basse = sauter, moyenne = se baisser obligatoirement, haute = passer dessous)
const heights = [GROUND_Y - 32, GROUND_Y - 55, GROUND_Y - 78];
const h = heights[Math.floor(Math.random() * heights.length)];
obstacles.push({
@@ -655,12 +667,31 @@
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');
// Calcul dynamique du niveau (1 à 5)
let currentLevel = 1;
if (score >= 900) currentLevel = 5;
else if (score >= 600) currentLevel = 4;
else if (score >= 350) currentLevel = 3;
else if (score >= 150) currentLevel = 2;
if (currentLevel !== lastLevel) {
lastLevel = currentLevel;
const badge = document.getElementById('dinoLevelBadge');
if (badge) {
badge.textContent = (currentDinoLang.startsWith('en') ? 'Level ' : 'Niveau ') + currentLevel;
badge.style.transform = 'scale(1.25)';
setTimeout(() => { if (badge) badge.style.transform = 'scale(1)'; }, 350);
}
playTone('score');
}
// Vitesse progressive qui monte au fur et à mesure (de 6.0 à 13.5 max)
gameSpeed = Math.min(13.5, 6.0 + Math.sqrt(score) * 0.26);
// High score
if (currentIntScore > highScore) {
highScore = currentIntScore;
@@ -668,14 +699,14 @@
localStorage.setItem('ap_dino_hi', highScore);
}
// Night mode toggle every 700 points
const nightCycle = Math.floor(score / 700) % 2 === 1;
// Alternance Jour / Nuit tous les 600 points
const nightCycle = Math.floor(score / 600) % 2 === 1;
if (nightCycle !== isNight) {
isNight = nightCycle;
document.body.classList.toggle('night-mode', isNight);
}
// Score milestone beep
// Son de palier tous les 100 points
if (currentIntScore > 0 && currentIntScore % 100 === 0 && Math.floor((score - 0.2)) % 100 !== 0) {
playTone('score');
}
@@ -701,9 +732,9 @@
nextObstacleTimer -= 1;
if (nextObstacleTimer <= 0) {
spawnObstacle();
// Intervalle équitable garantissant au joueur le temps de réatterrir (minimum 50 frames même à pleine vitesse)
const minFrames = Math.max(50, 95 - Math.floor(score / 40));
const randomVariance = Math.floor(Math.random() * 45);
// Intervalle équitable proportionnel à la vitesse (garantit toujours >= 330px d'espace entre les obstacles)
const minFrames = Math.max(38, Math.round(330 / gameSpeed));
const randomVariance = Math.floor(Math.random() * (Math.max(20, Math.round(180 / gameSpeed))));
nextObstacleTimer = minFrames + randomVariance;
}
+791
View File
@@ -0,0 +1,791 @@
<!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>Pac-Man - AP Manageur Arcade</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; 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;
--maze-wall: #1e40af;
--maze-bg: #030712;
--dot-color: #fef08a;
--power-color: #ffffff;
}
html[data-theme="light"] {
--bg: #f2f5fa;
--card-bg: #ffffff;
--panel-box: #e9eef7;
--border: #d2dcec;
--text: #15203a;
--muted: #5b6b8c;
--blue: #1e6ef0;
--blue-btn-text: #ffffff;
--maze-wall: #2563eb;
--maze-bg: #0f172a;
--dot-color: #fde047;
--power-color: #ffffff;
}
html[data-theme="winxp"] {
--bg: #ece9d8;
--card-bg: #ece9d8;
--panel-box: #ffffff;
--border: #7f9db9;
--text: #000000;
--muted: #444444;
--blue: #0055ea;
--blue-btn-text: #ffffff;
--maze-wall: #0055ea;
--maze-bg: #000000;
--dot-color: #ffff00;
--power-color: #ffffff;
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;
--maze-wall: #0071e3;
--maze-bg: #1c1c1e;
--dot-color: #ffcc00;
--power-color: #ffffff;
}
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;
--maze-wall: #0a84ff;
--maze-bg: #000000;
--dot-color: #ffd60a;
--power-color: #ffffff;
}
html[data-theme="futuristic"] {
--bg: #050811;
--card-bg: #091124;
--panel-box: #0f1c3a;
--border: #00f0ff;
--text: #e6f6ff;
--muted: #64b5f6;
--blue: #00f0ff;
--blue-btn-text: #050811;
--maze-wall: #00f0ff;
--maze-bg: #020713;
--dot-color: #fef08a;
--power-color: #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;
--maze-wall: #00ff41;
--maze-bg: #000000;
--dot-color: #a3e635;
--power-color: #ffffff;
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: 10px;
transition: background 0.3s ease, color 0.3s ease;
}
.game-card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 14px;
padding: 14px;
box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 20px rgba(92,167,255,0.12);
display: flex;
flex-direction: column;
align-items: center;
max-width: 480px;
width: 100%;
}
.header-bar {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
margin-bottom: 10px;
padding: 6px 10px;
background: var(--panel-box);
border-radius: 8px;
border: 1px solid var(--border);
font-size: 13px;
}
.scores-wrap {
display: flex;
gap: 16px;
font-weight: 700;
font-family: monospace;
font-size: 14px;
}
.score-val { color: var(--blue); }
.lives-val { color: #facc15; font-size: 16px; }
.canvas-wrap {
position: relative;
background: var(--maze-bg);
border: 2px solid var(--border);
border-radius: 10px;
overflow: hidden;
box-shadow: inset 0 0 15px rgba(0,0,0,0.6);
display: flex;
justify-content: center;
}
canvas {
display: block;
background: transparent;
}
.overlay {
position: absolute;
inset: 0;
background: rgba(3, 7, 18, 0.88);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
z-index: 10;
backdrop-filter: blur(3px);
}
.overlay h2 {
font-size: 26px;
color: #ef4444;
letter-spacing: 2px;
text-transform: uppercase;
}
.overlay h2.win { color: #32d583; }
.btn {
background: var(--blue);
color: var(--blue-btn-text);
border: 0;
padding: 8px 22px;
border-radius: 6px;
font-weight: 700;
font-size: 13px;
cursor: pointer;
transition: all 0.15s ease;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.touch-controls {
display: grid;
grid-template-columns: repeat(3, 50px);
gap: 6px;
margin-top: 10px;
justify-content: center;
}
.touch-btn {
width: 50px;
height: 44px;
background: var(--panel-box);
border: 1px solid var(--border);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
color: var(--text);
cursor: pointer;
user-select: none;
}
.touch-btn:active {
background: var(--blue);
color: var(--blue-btn-text);
}
.controls-hint {
margin-top: 8px;
font-size: 11px;
color: var(--muted);
text-align: center;
}
</style>
</head>
<body>
<div class="game-card">
<div class="header-bar">
<div>🟡 <strong>Pac-Man</strong></div>
<div class="scores-wrap">
<div>SCORE: <span id="scoreEl" class="score-val">0</span></div>
<div>HI: <span id="hiScoreEl" class="score-val">0</span></div>
<div id="livesEl" class="lives-val">🟡🟡🟡</div>
</div>
</div>
<div class="canvas-wrap">
<canvas id="pacmanCanvas" width="380" height="420"></canvas>
<div id="gameOverlay" class="overlay" style="display:none">
<h2 id="overlayTitle">GAME OVER</h2>
<div id="overlayScore" style="color:var(--blue);font-weight:700"></div>
<button id="overlayBtn" class="btn" onclick="initGame()">REJOUER</button>
</div>
</div>
<div class="touch-controls">
<div></div>
<div class="touch-btn" onclick="setNextDir(0, -1)">⬆️</div>
<div></div>
<div class="touch-btn" onclick="setNextDir(-1, 0)">⬅️</div>
<div class="touch-btn" onclick="setNextDir(0, 1)">⬇️</div>
<div class="touch-btn" onclick="setNextDir(1, 0)">➡️</div>
</div>
<div id="pacInstructions" class="controls-hint">
Flèches directionnelles ou ZQSD pour guider Pac-Man. Mangez toutes les pac-gommes et fuyez les fantômes !
</div>
</div>
<script>
// Theme & i18n
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'));
const I18N_PAC = {
fr: {
game_over: "GAME OVER",
level_cleared: "NIVEAU RÉUSSI ! 🎉",
replay_btn: "REJOUER",
next_level_btn: "NIVEAU SUIVANT ➡️",
instructions: "Flèches directionnelles ou ZQSD pour guider Pac-Man. Mangez toutes les pac-gommes et fuyez les fantômes !"
},
en: {
game_over: "GAME OVER",
level_cleared: "STAGE CLEARED! 🎉",
replay_btn: "PLAY AGAIN",
next_level_btn: "NEXT STAGE ➡️",
instructions: "Arrow keys or WASD to control Pac-Man. Eat all dots and avoid the ghosts!"
}
};
let currentPacLang = 'fr';
function applyPacLang(lang) {
currentPacLang = (lang && (lang.startsWith('en') ? 'en' : 'fr')) || 'fr';
const dict = I18N_PAC[currentPacLang] || I18N_PAC.fr;
const pi = document.getElementById('pacInstructions');
if (pi) pi.textContent = dict.instructions;
}
applyPacLang(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') applyPacLang(e.data.lang);
});
// Sound Synthesizer
let audioCtx = null;
function playSnd(type) {
try {
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
if (type === 'dot') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'triangle';
osc.frequency.setValueAtTime(320, now);
osc.frequency.linearRampToValueAtTime(560, now + 0.04);
g.gain.setValueAtTime(0.04, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.04);
osc.start(now); osc.stop(now + 0.04);
} else if (type === 'power') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(440, now);
osc.frequency.linearRampToValueAtTime(880, now + 0.15);
g.gain.setValueAtTime(0.08, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.15);
osc.start(now); osc.stop(now + 0.15);
} else if (type === 'eat_ghost') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(200, now);
osc.frequency.linearRampToValueAtTime(800, now + 0.2);
g.gain.setValueAtTime(0.08, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.2);
osc.start(now); osc.stop(now + 0.2);
} else if (type === 'die') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(500, now);
osc.frequency.linearRampToValueAtTime(100, now + 0.4);
g.gain.setValueAtTime(0.1, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.4);
osc.start(now); osc.stop(now + 0.4);
} else if (type === 'win') {
[523.25, 659.25, 783.99, 1046.5].forEach((f, i) => {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'triangle';
osc.frequency.setValueAtTime(f, now + i * 0.08);
g.gain.setValueAtTime(0.07, now + i * 0.08);
g.gain.exponentialRampToValueAtTime(0.001, now + i * 0.08 + 0.2);
osc.start(now + i * 0.08); osc.stop(now + i * 0.08 + 0.2);
});
}
} catch (e) {}
}
// Canvas & Game Map (19 cols x 21 rows)
// 1: Wall, 0: Dot, 2: Power Pellet, 3: Empty / Ghost house, 4: Pacman spawn
const MAP_TEMPLATE = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,2,1],
[1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1],
[1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1],
[1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1],
[1,1,1,1,0,1,1,1,3,1,3,1,1,1,0,1,1,1,1],
[3,3,3,1,0,1,3,3,3,3,3,3,3,1,0,1,3,3,3],
[1,1,1,1,0,1,3,1,1,3,1,1,3,1,0,1,1,1,1],
[3,3,3,3,0,3,3,1,3,3,3,1,3,3,0,3,3,3,3],
[1,1,1,1,0,1,3,1,1,1,1,1,3,1,0,1,1,1,1],
[3,3,3,1,0,1,3,3,3,3,3,3,3,1,0,1,3,3,3],
[1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1],
[1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1],
[1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1],
[1,2,0,1,0,0,0,0,0,4,0,0,0,0,0,1,0,2,1],
[1,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1],
[1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1],
[1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
const canvas = document.getElementById('pacmanCanvas');
const ctx = canvas.getContext('2d');
const TILE = 20;
const COLS = 19;
const ROWS = 21;
let map = [];
let totalDots = 0;
let eatenDots = 0;
let score = 0;
let highScore = parseInt(localStorage.getItem('ap_pacman_hi') || '0', 10);
let lives = 3;
let isGameOver = false;
let frightenedTimer = 0;
// Pac-man state
const pacman = {
x: 9, y: 16,
pixelX: 9 * TILE, pixelY: 16 * TILE,
dirX: 0, dirY: 0,
nextDirX: 0, nextDirY: 0,
speed: 2,
mouthAngle: 0.2,
mouthDir: 1
};
// Ghosts
const GHOST_COLORS = ['#ff0000', '#ffb8ff', '#00ffff', '#ffb852'];
let ghosts = [];
function initGhosts() {
ghosts = [
{ x: 9, y: 8, pixelX: 9 * TILE, pixelY: 8 * TILE, dirX: 0, dirY: -1, color: GHOST_COLORS[0], speed: 1.8, isEaten: false },
{ x: 8, y: 10, pixelX: 8 * TILE, pixelY: 10 * TILE, dirX: 1, dirY: 0, color: GHOST_COLORS[1], speed: 1.6, isEaten: false },
{ x: 9, y: 10, pixelX: 9 * TILE, pixelY: 10 * TILE, dirX: 0, dirY: -1, color: GHOST_COLORS[2], speed: 1.6, isEaten: false },
{ x: 10, y: 10, pixelX: 10 * TILE, pixelY: 10 * TILE, dirX: -1, dirY: 0, color: GHOST_COLORS[3], speed: 1.5, isEaten: false }
];
}
function initGame() {
document.getElementById('gameOverlay').style.display = 'none';
map = MAP_TEMPLATE.map(row => [...row]);
totalDots = 0;
eatenDots = 0;
for (let r = 0; r < ROWS; r++) {
for (let c = 0; c < COLS; c++) {
if (map[r][c] === 0 || map[r][c] === 2) totalDots++;
}
}
score = 0;
lives = 3;
isGameOver = false;
frightenedTimer = 0;
updateUI();
resetPositions();
}
function resetPositions() {
pacman.x = 9;
pacman.y = 16;
pacman.pixelX = 9 * TILE;
pacman.pixelY = 16 * TILE;
pacman.dirX = 0;
pacman.dirY = 0;
pacman.nextDirX = 0;
pacman.nextDirY = 0;
initGhosts();
}
function updateUI() {
document.getElementById('scoreEl').textContent = score;
document.getElementById('hiScoreEl').textContent = highScore;
let hearts = '';
for (let i = 0; i < lives; i++) hearts += '🟡';
document.getElementById('livesEl').textContent = hearts || '💀';
}
function setNextDir(dx, dy) {
pacman.nextDirX = dx;
pacman.nextDirY = dy;
if (pacman.dirX === 0 && pacman.dirY === 0) {
pacman.dirX = dx;
pacman.dirY = dy;
}
}
function canMove(tileX, tileY) {
if (tileX < 0 || tileX >= COLS) return true; // warp tunnel
if (tileY < 0 || tileY >= ROWS) return false;
return map[tileY][tileX] !== 1;
}
function update() {
if (!isGameOver) {
// Pacman mouth animation
pacman.mouthAngle += 0.04 * pacman.mouthDir;
if (pacman.mouthAngle >= 0.4 || pacman.mouthAngle <= 0.04) {
pacman.mouthDir *= -1;
}
// Frightened timer countdown
if (frightenedTimer > 0) {
frightenedTimer--;
}
// Turning at grid tile center
const onGridX = (pacman.pixelX % TILE === 0);
const onGridY = (pacman.pixelY % TILE === 0);
if (onGridX && onGridY) {
const curTileX = Math.round(pacman.pixelX / TILE);
const curTileY = Math.round(pacman.pixelY / TILE);
pacman.x = curTileX;
pacman.y = curTileY;
// Eat dot / power pellet
if (curTileY >= 0 && curTileY < ROWS && curTileX >= 0 && curTileX < COLS) {
if (map[curTileY][curTileX] === 0) {
map[curTileY][curTileX] = 3;
score += 10;
eatenDots++;
playSnd('dot');
checkWin();
} else if (map[curTileY][curTileX] === 2) {
map[curTileY][curTileX] = 3;
score += 50;
eatenDots++;
frightenedTimer = 350; // ~6 seconds
playSnd('power');
checkWin();
}
}
if (score > highScore) {
highScore = score;
localStorage.setItem('ap_pacman_hi', highScore);
}
updateUI();
// Try turn in requested direction
if (canMove(curTileX + pacman.nextDirX, curTileY + pacman.nextDirY)) {
pacman.dirX = pacman.nextDirX;
pacman.dirY = pacman.nextDirY;
}
// If blocked in current direction, stop
if (!canMove(curTileX + pacman.dirX, curTileY + pacman.dirY)) {
pacman.dirX = 0;
pacman.dirY = 0;
}
}
// Move Pacman
pacman.pixelX += pacman.dirX * pacman.speed;
pacman.pixelY += pacman.dirY * pacman.speed;
// Wrap tunnel left-right
if (pacman.pixelX < -TILE / 2) pacman.pixelX = (COLS - 0.5) * TILE;
if (pacman.pixelX > (COLS - 0.5) * TILE) pacman.pixelX = -TILE / 2;
// Move Ghosts
ghosts.forEach(g => {
const gOnGridX = (g.pixelX % TILE === 0);
const gOnGridY = (g.pixelY % TILE === 0);
if (gOnGridX && gOnGridY) {
const gx = Math.round(g.pixelX / TILE);
const gy = Math.round(g.pixelY / TILE);
g.x = gx;
g.y = gy;
const possibleDirs = [
{ dx: 1, dy: 0 }, { dx: -1, dy: 0 }, { dx: 0, dy: 1 }, { dx: 0, dy: -1 }
].filter(d => {
// Don't turn immediately 180 degrees backwards unless forced
if (d.dx === -g.dirX && d.dy === -g.dirY) return false;
return canMove(gx + d.dx, gy + d.dy);
});
if (possibleDirs.length > 0) {
// Simple AI: target Pacman or random when frightened
if (frightenedTimer > 0 || Math.random() < 0.3) {
const pick = possibleDirs[Math.floor(Math.random() * possibleDirs.length)];
g.dirX = pick.dx;
g.dirY = pick.dy;
} else {
// Best direction towards Pacman
possibleDirs.sort((a, b) => {
const distA = Math.hypot((gx + a.dx) - pacman.x, (gy + a.dy) - pacman.y);
const distB = Math.hypot((gx + b.dx) - pacman.x, (gy + b.dy) - pacman.y);
return distA - distB;
});
g.dirX = possibleDirs[0].dx;
g.dirY = possibleDirs[0].dy;
}
} else if (!canMove(gx + g.dirX, gy + g.dirY)) {
g.dirX *= -1;
g.dirY *= -1;
}
}
const curGhostSpeed = (frightenedTimer > 0) ? 1.0 : g.speed;
g.pixelX += g.dirX * curGhostSpeed;
g.pixelY += g.dirY * curGhostSpeed;
// Ghost Wrap
if (g.pixelX < -TILE / 2) g.pixelX = (COLS - 0.5) * TILE;
if (g.pixelX > (COLS - 0.5) * TILE) g.pixelX = -TILE / 2;
// Collision detection with Pacman
const dist = Math.hypot(g.pixelX - pacman.pixelX, g.pixelY - pacman.pixelY);
if (dist < TILE * 0.75) {
if (frightenedTimer > 0 && !g.isEaten) {
// Eat ghost
g.isEaten = true;
g.pixelX = 9 * TILE;
g.pixelY = 10 * TILE;
score += 200;
playSnd('eat_ghost');
updateUI();
} else if (!g.isEaten) {
// Pacman dies
lives--;
playSnd('die');
updateUI();
if (lives <= 0) {
gameOver(false);
} else {
resetPositions();
}
}
}
});
}
draw();
requestAnimationFrame(update);
}
function checkWin() {
if (eatenDots >= totalDots) {
gameOver(true);
}
}
function gameOver(isWin) {
isGameOver = true;
const overlay = document.getElementById('gameOverlay');
const title = document.getElementById('overlayTitle');
const scoreTxt = document.getElementById('overlayScore');
const btn = document.getElementById('overlayBtn');
const dict = I18N_PAC[currentPacLang] || I18N_PAC.fr;
overlay.style.display = 'flex';
scoreTxt.textContent = `Score final : ${score}`;
if (isWin) {
title.textContent = dict.level_cleared;
title.className = 'win';
btn.textContent = dict.next_level_btn;
playSnd('win');
} else {
title.textContent = dict.game_over;
title.className = '';
btn.textContent = dict.replay_btn;
}
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw Maze
const wallColor = getComputedStyle(document.documentElement).getPropertyValue('--maze-wall').trim() || '#1e40af';
const dotColor = getComputedStyle(document.documentElement).getPropertyValue('--dot-color').trim() || '#fde047';
const powerColor = getComputedStyle(document.documentElement).getPropertyValue('--power-color').trim() || '#ffffff';
for (let r = 0; r < ROWS; r++) {
for (let c = 0; c < COLS; c++) {
const type = map[r][c];
const px = c * TILE;
const py = r * TILE;
if (type === 1) {
ctx.fillStyle = wallColor;
ctx.fillRect(px, py, TILE, TILE);
ctx.strokeStyle = 'rgba(0,0,0,0.2)';
ctx.strokeRect(px + 1, py + 1, TILE - 2, TILE - 2);
} else if (type === 0) {
ctx.fillStyle = dotColor;
ctx.beginPath();
ctx.arc(px + TILE / 2, py + TILE / 2, 2.5, 0, Math.PI * 2);
ctx.fill();
} else if (type === 2) {
// Power pellet pulsing
const pulse = (Math.sin(performance.now() * 0.008) + 1) * 2 + 4;
ctx.fillStyle = powerColor;
ctx.beginPath();
ctx.arc(px + TILE / 2, py + TILE / 2, pulse, 0, Math.PI * 2);
ctx.fill();
}
}
}
// Draw Pac-Man
const pmX = pacman.pixelX + TILE / 2;
const pmY = pacman.pixelY + TILE / 2;
let baseRot = 0;
if (pacman.dirX === 1) baseRot = 0;
else if (pacman.dirX === -1) baseRot = Math.PI;
else if (pacman.dirY === 1) baseRot = Math.PI * 0.5;
else if (pacman.dirY === -1) baseRot = Math.PI * 1.5;
ctx.fillStyle = '#facc15';
ctx.beginPath();
ctx.arc(
pmX, pmY, TILE * 0.44,
baseRot + pacman.mouthAngle * Math.PI,
baseRot + (2 - pacman.mouthAngle) * Math.PI
);
ctx.lineTo(pmX, pmY);
ctx.fill();
// Draw Ghosts
ghosts.forEach(g => {
const gx = g.pixelX + TILE / 2;
const gy = g.pixelY + TILE / 2;
const isScared = frightenedTimer > 0;
const isBlinking = frightenedTimer < 100 && Math.floor(frightenedTimer / 10) % 2 === 0;
ctx.fillStyle = isScared ? (isBlinking ? '#ffffff' : '#1d4ed8') : g.color;
// Ghost body & rounded head
ctx.beginPath();
ctx.arc(gx, gy - 2, TILE * 0.42, Math.PI, 0, false);
ctx.lineTo(gx + TILE * 0.42, gy + TILE * 0.4);
// Tentacles
ctx.lineTo(gx + TILE * 0.2, gy + TILE * 0.25);
ctx.lineTo(gx, gy + TILE * 0.4);
ctx.lineTo(gx - TILE * 0.2, gy + TILE * 0.25);
ctx.lineTo(gx - TILE * 0.42, gy + TILE * 0.4);
ctx.closePath();
ctx.fill();
// Eyes
const eyeOffsetX = g.dirX * 2;
const eyeOffsetY = g.dirY * 2;
ctx.fillStyle = '#ffffff';
ctx.beginPath();
ctx.arc(gx - 4 + eyeOffsetX, gy - 4 + eyeOffsetY, 3, 0, Math.PI * 2);
ctx.arc(gx + 4 + eyeOffsetX, gy - 4 + eyeOffsetY, 3, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = isScared ? '#ff0000' : '#1e3a8a';
ctx.beginPath();
ctx.arc(gx - 4 + eyeOffsetX * 1.5, gy - 4 + eyeOffsetY * 1.5, 1.5, 0, Math.PI * 2);
ctx.arc(gx + 4 + eyeOffsetX * 1.5, gy - 4 + eyeOffsetY * 1.5, 1.5, 0, Math.PI * 2);
ctx.fill();
});
}
// Keyboard controls
window.addEventListener('keydown', e => {
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '].includes(e.key)) {
e.preventDefault();
}
if (e.key === 'ArrowUp' || e.key === 'z' || e.key === 'Z' || e.key === 'w' || e.key === 'W') setNextDir(0, -1);
else if (e.key === 'ArrowDown' || e.key === 's' || e.key === 'S') setNextDir(0, 1);
else if (e.key === 'ArrowLeft' || e.key === 'q' || e.key === 'Q' || e.key === 'a' || e.key === 'A') setNextDir(-1, 0);
else if (e.key === 'ArrowRight' || e.key === 'd' || e.key === 'D') setNextDir(1, 0);
});
initGame();
update();
</script>
</body>
</html>
+866
View File
@@ -0,0 +1,866 @@
<!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>Space Invaders - AP Manageur Arcade</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; 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;
--canvas-bg: #020713;
--cannon-color: #34d399;
--laser-color: #38bdf8;
--bomb-color: #ff6b6b;
--shield-color: #22c55e;
--ufo-color: #f43f5e;
}
html[data-theme="light"] {
--bg: #f2f5fa;
--card-bg: #ffffff;
--panel-box: #e9eef7;
--border: #d2dcec;
--text: #15203a;
--muted: #5b6b8c;
--blue: #1e6ef0;
--blue-btn-text: #ffffff;
--canvas-bg: #0f172a;
--cannon-color: #10b981;
--laser-color: #0284c7;
--bomb-color: #ef4444;
--shield-color: #16a34a;
--ufo-color: #e11d48;
}
html[data-theme="winxp"] {
--bg: #ece9d8;
--card-bg: #ece9d8;
--panel-box: #ffffff;
--border: #7f9db9;
--text: #000000;
--muted: #444444;
--blue: #0055ea;
--blue-btn-text: #ffffff;
--canvas-bg: #000000;
--cannon-color: #00ff00;
--laser-color: #ffffff;
--bomb-color: #ff0000;
--shield-color: #00cc00;
--ufo-color: #ff00ff;
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;
--canvas-bg: #1c1c1e;
--cannon-color: #34c759;
--laser-color: #5ac8fa;
--bomb-color: #ff3b30;
--shield-color: #30d158;
--ufo-color: #ff2d55;
}
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;
--canvas-bg: #000000;
--cannon-color: #30d158;
--laser-color: #64d2ff;
--bomb-color: #ff453a;
--shield-color: #32d74b;
--ufo-color: #ff375f;
}
html[data-theme="futuristic"] {
--bg: #050811;
--card-bg: #091124;
--panel-box: #0f1c3a;
--border: #00f0ff;
--text: #e6f6ff;
--muted: #64b5f6;
--blue: #00f0ff;
--blue-btn-text: #050811;
--canvas-bg: #020713;
--cannon-color: #00f0ff;
--laser-color: #38bdf8;
--bomb-color: #f43f5e;
--shield-color: #00f0ff;
--ufo-color: #e879f9;
}
html[data-theme="hacker"] {
--bg: #000000;
--card-bg: #051206;
--panel-box: #0a1f0c;
--border: #00ff41;
--text: #00ff41;
--muted: #008f11;
--blue: #00ff41;
--blue-btn-text: #000000;
--canvas-bg: #000000;
--cannon-color: #00ff41;
--laser-color: #a3e635;
--bomb-color: #ff0033;
--shield-color: #00ff41;
--ufo-color: #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: 10px;
transition: background 0.3s ease, color 0.3s ease;
}
.game-card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 14px;
padding: 14px;
box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 20px rgba(92,167,255,0.12);
display: flex;
flex-direction: column;
align-items: center;
max-width: 580px;
width: 100%;
}
.header-bar {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
margin-bottom: 10px;
padding: 6px 14px;
background: var(--panel-box);
border-radius: 8px;
border: 1px solid var(--border);
font-size: 13px;
}
.scores-wrap {
display: flex;
gap: 16px;
font-weight: 700;
font-family: monospace;
font-size: 14px;
}
.score-val { color: var(--blue); }
.lives-val { color: var(--cannon-color); font-size: 15px; }
.canvas-wrap {
position: relative;
background: var(--canvas-bg);
border: 2px solid var(--border);
border-radius: 10px;
overflow: hidden;
box-shadow: inset 0 0 20px rgba(0,0,0,0.7);
}
canvas {
display: block;
}
.overlay {
position: absolute;
inset: 0;
background: rgba(3, 7, 18, 0.88);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
z-index: 10;
backdrop-filter: blur(3px);
}
.overlay h2 {
font-size: 26px;
color: #ef4444;
letter-spacing: 2px;
text-transform: uppercase;
}
.overlay h2.win { color: #32d583; }
.btn {
background: var(--blue);
color: var(--blue-btn-text);
border: 0;
padding: 8px 22px;
border-radius: 6px;
font-weight: 700;
font-size: 13px;
cursor: pointer;
transition: all 0.15s ease;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.touch-controls {
display: flex;
gap: 12px;
margin-top: 10px;
justify-content: center;
width: 100%;
max-width: 360px;
}
.touch-btn {
flex: 1;
height: 44px;
background: var(--panel-box);
border: 1px solid var(--border);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
color: var(--text);
cursor: pointer;
user-select: none;
}
.touch-btn.fire {
background: var(--blue);
color: var(--blue-btn-text);
font-weight: 700;
font-size: 14px;
}
.touch-btn:active {
transform: scale(0.96);
}
.controls-hint {
margin-top: 8px;
font-size: 11px;
color: var(--muted);
text-align: center;
}
</style>
</head>
<body>
<div class="game-card">
<div class="header-bar">
<div>👾 <strong>Space Invaders</strong></div>
<div class="scores-wrap">
<div>SCORE: <span id="scoreEl" class="score-val">0000</span></div>
<div>HI: <span id="hiScoreEl" class="score-val">0000</span></div>
<div id="livesEl" class="lives-val">🚀🚀🚀</div>
</div>
</div>
<div class="canvas-wrap">
<canvas id="siCanvas" width="520" height="420"></canvas>
<div id="gameOverlay" class="overlay" style="display:none">
<h2 id="overlayTitle">GAME OVER</h2>
<div id="overlayScore" style="color:var(--blue);font-weight:700"></div>
<button id="overlayBtn" class="btn" onclick="initGame()">REJOUER</button>
</div>
</div>
<div class="touch-controls">
<div class="touch-btn" id="btnLeft">⬅️</div>
<div class="touch-btn fire" id="btnFire">🔥 TIR</div>
<div class="touch-btn" id="btnRight">➡️</div>
</div>
<div id="siInstructions" class="controls-hint">
⬅️ ➡️ ou A/D pour vous déplacer, Espace pour tirer. Détruisez tous les envahisseurs avant qu'ils n'atteignent le sol !
</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'));
const I18N_SI = {
fr: {
game_over: "GAME OVER",
level_cleared: "VICTOIRE ! VAGUE DÉTRUITE 🎉",
replay_btn: "REJOUER",
next_level_btn: "VAGUE SUIVANTE ➡️",
instructions: "⬅️ ➡️ ou A/D pour vous déplacer, Espace pour tirer. Détruisez tous les envahisseurs avant qu'ils n'atteignent le sol !"
},
en: {
game_over: "GAME OVER",
level_cleared: "VICTORY! WAVE CLEARED 🎉",
replay_btn: "PLAY AGAIN",
next_level_btn: "NEXT WAVE ➡️",
instructions: "⬅️ ➡️ or A/D to move, Space to fire. Destroy all invaders before they land on Earth!"
}
};
let currentSiLang = 'fr';
function applySiLang(lang) {
currentSiLang = (lang && (lang.startsWith('en') ? 'en' : 'fr')) || 'fr';
const dict = I18N_SI[currentSiLang] || I18N_SI.fr;
const el = document.getElementById('siInstructions');
if (el) el.textContent = dict.instructions;
}
applySiLang(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') applySiLang(e.data.lang);
});
// Sound Synthesizer
let audioCtx = null;
let marchPitchIndex = 0;
const MARCH_FREQS = [160, 140, 120, 100];
function playSound(type) {
try {
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
if (audioCtx.state === 'suspended') audioCtx.resume();
const now = audioCtx.currentTime;
if (type === 'laser') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'square';
osc.frequency.setValueAtTime(880, now);
osc.frequency.exponentialRampToValueAtTime(220, now + 0.12);
g.gain.setValueAtTime(0.06, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.12);
osc.start(now); osc.stop(now + 0.12);
} else if (type === 'invader_hit') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(280, now);
osc.frequency.linearRampToValueAtTime(60, now + 0.15);
g.gain.setValueAtTime(0.08, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.15);
osc.start(now); osc.stop(now + 0.15);
} else if (type === 'march') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sawtooth';
const f = MARCH_FREQS[marchPitchIndex];
marchPitchIndex = (marchPitchIndex + 1) % MARCH_FREQS.length;
osc.frequency.setValueAtTime(f, now);
g.gain.setValueAtTime(0.06, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.08);
osc.start(now); osc.stop(now + 0.08);
} else if (type === 'player_hit') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(180, now);
osc.frequency.linearRampToValueAtTime(40, now + 0.4);
g.gain.setValueAtTime(0.12, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.4);
osc.start(now); osc.stop(now + 0.4);
} else if (type === 'ufo') {
const osc = audioCtx.createOscillator();
const g = audioCtx.createGain();
osc.connect(g); g.connect(audioCtx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(500, now);
osc.frequency.linearRampToValueAtTime(900, now + 0.2);
g.gain.setValueAtTime(0.05, now);
g.gain.exponentialRampToValueAtTime(0.001, now + 0.2);
osc.start(now); osc.stop(now + 0.2);
}
} catch (e) {}
}
const canvas = document.getElementById('siCanvas');
const ctx = canvas.getContext('2d');
let score = 0;
let highScore = parseInt(localStorage.getItem('ap_si_hi') || '0', 10);
let lives = 3;
let isGameOver = false;
// Cannon
const player = {
x: canvas.width / 2 - 15,
y: canvas.height - 35,
w: 30,
h: 18,
speed: 4.5,
movingLeft: false,
movingRight: false,
canShoot: true
};
let bullets = [];
let enemyBombs = [];
let invaders = [];
let invaderDir = 1;
let invaderStepDown = false;
let marchTimer = 0;
let marchInterval = 45; // frames between march ticks
// Bunkers / Shields
let shields = [];
// UFO Mystery Ship
let ufo = null;
let ufoTimer = 600;
function initShields() {
shields = [];
const numShields = 4;
const shieldW = 44;
const shieldH = 26;
const spacing = (canvas.width - numShields * shieldW) / (numShields + 1);
for (let i = 0; i < numShields; i++) {
const sx = spacing + i * (shieldW + spacing);
const sy = canvas.height - 85;
// Block pixels 4x4
for (let bx = 0; bx < shieldW; bx += 4) {
for (let by = 0; by < shieldH; by += 4) {
// Cutout bottom arch
if (bx >= 12 && bx <= 28 && by >= 14) continue;
// Cutout top corners
if ((bx < 4 && by < 4) || (bx >= 40 && by < 4)) continue;
shields.push({ x: sx + bx, y: sy + by, w: 4, h: 4, health: 3 });
}
}
}
}
function initInvaders() {
invaders = [];
const rows = 5;
const cols = 10;
const startX = 40;
const startY = 45;
const gapX = 38;
const gapY = 26;
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
let type = 1; // Squid (top)
let points = 30;
let color = '#ec4899';
if (r === 1 || r === 2) {
type = 2; // Crab (middle)
points = 20;
color = '#38bdf8';
} else if (r >= 3) {
type = 3; // Octopus (bottom)
points = 10;
color = '#a855f7';
}
invaders.push({
x: startX + c * gapX,
y: startY + r * gapY,
w: 24,
h: 18,
type,
points,
color,
alive: true,
frame: 0
});
}
}
invaderDir = 1;
marchInterval = 45;
}
function initGame() {
document.getElementById('gameOverlay').style.display = 'none';
score = 0;
lives = 3;
isGameOver = false;
bullets = [];
enemyBombs = [];
ufo = null;
ufoTimer = 500;
player.x = canvas.width / 2 - 15;
updateUI();
initShields();
initInvaders();
}
function updateUI() {
document.getElementById('scoreEl').textContent = String(score).padStart(4, '0');
document.getElementById('hiScoreEl').textContent = String(highScore).padStart(4, '0');
let hearts = '';
for (let i = 0; i < lives; i++) hearts += '🚀';
document.getElementById('livesEl').textContent = hearts || '💥';
}
function shootLaser() {
if (!isGameOver && player.canShoot) {
// Limit to 2 concurrent player bullets
if (bullets.length < 2) {
bullets.push({
x: player.x + player.w / 2 - 2,
y: player.y - 6,
w: 3,
h: 10,
speed: 8
});
playSound('laser');
player.canShoot = false;
setTimeout(() => { player.canShoot = true; }, 180);
}
}
}
function update() {
if (!isGameOver) {
// Player movement
if (player.movingLeft) player.x -= player.speed;
if (player.movingRight) player.x += player.speed;
player.x = Math.max(10, Math.min(canvas.width - player.w - 10, player.x));
// Player bullets
for (let i = bullets.length - 1; i >= 0; i--) {
const b = bullets[i];
b.y -= b.speed;
if (b.y < 0) {
bullets.splice(i, 1);
continue;
}
// Bullet vs Shield
let hitShield = false;
for (let s = shields.length - 1; s >= 0; s--) {
const sh = shields[s];
if (b.x < sh.x + sh.w && b.x + b.w > sh.x && b.y < sh.y + sh.h && b.y + b.h > sh.y) {
shields.splice(s, 1);
hitShield = true;
break;
}
}
if (hitShield) {
bullets.splice(i, 1);
continue;
}
// Bullet vs UFO
if (ufo && b.x < ufo.x + ufo.w && b.x + b.w > ufo.x && b.y < ufo.y + ufo.h && b.y + b.h > ufo.y) {
score += ufo.points;
playSound('invader_hit');
ufo = null;
bullets.splice(i, 1);
updateUI();
continue;
}
// Bullet vs Invaders
for (let j = 0; j < invaders.length; j++) {
const inv = invaders[j];
if (inv.alive && b.x < inv.x + inv.w && b.x + b.w > inv.x && b.y < inv.y + inv.h && b.y + b.h > inv.y) {
inv.alive = false;
bullets.splice(i, 1);
score += inv.points;
playSound('invader_hit');
if (score > highScore) {
highScore = score;
localStorage.setItem('ap_si_hi', highScore);
}
updateUI();
// Speed up march as aliens die
const aliveCount = invaders.filter(a => a.alive).length;
marchInterval = Math.max(6, Math.floor(aliveCount * 0.9) + 4);
// Wave cleared check
if (aliveCount === 0) {
gameOver(true);
}
break;
}
}
}
// Enemy bombs movement
for (let i = enemyBombs.length - 1; i >= 0; i--) {
const b = enemyBombs[i];
b.y += b.speed;
// Bomb vs Shield
let hitShield = false;
for (let s = shields.length - 1; s >= 0; s--) {
const sh = shields[s];
if (b.x < sh.x + sh.w && b.x + b.w > sh.x && b.y < sh.y + sh.h && b.y + b.h > sh.y) {
shields.splice(s, 1);
hitShield = true;
break;
}
}
if (hitShield) {
enemyBombs.splice(i, 1);
continue;
}
// Bomb vs Player
if (b.x < player.x + player.w && b.x + b.w > player.x && b.y < player.y + player.h && b.y + b.h > player.y) {
enemyBombs.splice(i, 1);
lives--;
playSound('player_hit');
updateUI();
if (lives <= 0) {
gameOver(false);
}
continue;
}
if (b.y > canvas.height) {
enemyBombs.splice(i, 1);
}
}
// Invaders march movement
marchTimer++;
if (marchTimer >= marchInterval) {
marchTimer = 0;
playSound('march');
let hitEdge = false;
const aliveInvaders = invaders.filter(inv => inv.alive);
aliveInvaders.forEach(inv => {
inv.frame = inv.frame === 0 ? 1 : 0;
if (invaderDir === 1 && inv.x + inv.w >= canvas.width - 15) hitEdge = true;
if (invaderDir === -1 && inv.x <= 15) hitEdge = true;
});
if (hitEdge) {
invaderDir *= -1;
aliveInvaders.forEach(inv => {
inv.y += 14;
// Check if invaded earth / shields
if (inv.y + inv.h >= player.y) {
gameOver(false);
}
});
} else {
aliveInvaders.forEach(inv => {
inv.x += invaderDir * 10;
});
}
// Random bomb drop from lowest invader of a random column
if (Math.random() < 0.45 && aliveInvaders.length > 0 && enemyBombs.length < 3) {
const randomInvader = aliveInvaders[Math.floor(Math.random() * aliveInvaders.length)];
enemyBombs.push({
x: randomInvader.x + randomInvader.w / 2,
y: randomInvader.y + randomInvader.h,
w: 3,
h: 8,
speed: 4
});
}
}
// UFO Management
ufoTimer--;
if (ufoTimer <= 0) {
if (!ufo && Math.random() < 0.5) {
ufo = {
x: -40,
y: 20,
w: 36,
h: 16,
speed: 2.2,
points: [100, 150, 200, 300][Math.floor(Math.random() * 4)]
};
playSound('ufo');
}
ufoTimer = 650;
}
if (ufo) {
ufo.x += ufo.speed;
if (ufo.x > canvas.width + 40) ufo = null;
}
}
draw();
requestAnimationFrame(update);
}
function gameOver(isWin) {
isGameOver = true;
const overlay = document.getElementById('gameOverlay');
const title = document.getElementById('overlayTitle');
const scoreTxt = document.getElementById('overlayScore');
const btn = document.getElementById('overlayBtn');
const dict = I18N_SI[currentSiLang] || I18N_SI.fr;
overlay.style.display = 'flex';
scoreTxt.textContent = `Score final : ${score}`;
if (isWin) {
title.textContent = dict.level_cleared;
title.className = 'win';
btn.textContent = dict.next_level_btn;
} else {
title.textContent = dict.game_over;
title.className = '';
btn.textContent = dict.replay_btn;
}
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Starfield background
ctx.fillStyle = 'rgba(255,255,255,0.4)';
for (let i = 0; i < 20; i++) {
ctx.fillRect((i * 47) % canvas.width, (i * 31 + (performance.now() * 0.02)) % canvas.height, 1.5, 1.5);
}
// Draw Shields
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--shield-color').trim() || '#22c55e';
shields.forEach(s => {
ctx.fillRect(s.x, s.y, s.w, s.h);
});
// Draw Player Cannon
const cannonColor = getComputedStyle(document.documentElement).getPropertyValue('--cannon-color').trim() || '#34d399';
ctx.fillStyle = cannonColor;
// Base
ctx.fillRect(player.x, player.y + 6, player.w, 12);
// Mid turret
ctx.fillRect(player.x + 6, player.y + 2, player.w - 12, 6);
// Gun nozzle
ctx.fillRect(player.x + player.w / 2 - 2, player.y - 3, 4, 6);
// Draw Player Bullets
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--laser-color').trim() || '#38bdf8';
bullets.forEach(b => {
ctx.fillRect(b.x, b.y, b.w, b.h);
});
// Draw Enemy Bombs
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--bomb-color').trim() || '#ff6b6b';
enemyBombs.forEach(b => {
ctx.fillRect(b.x, b.y, b.w, b.h);
// Little zigzag bomb tip
ctx.fillRect(b.x - 1, b.y + 2, 5, 2);
});
// Draw Invaders
invaders.forEach(inv => {
if (!inv.alive) return;
ctx.fillStyle = inv.color;
const x = inv.x, y = inv.y, w = inv.w, h = inv.h;
if (inv.type === 1) { // Squid
ctx.fillRect(x + 8, y, 8, 4);
ctx.fillRect(x + 4, y + 4, 16, 6);
ctx.fillRect(x + 6, y + 10, 12, 4);
if (inv.frame === 0) {
ctx.fillRect(x + 2, y + 14, 4, 4);
ctx.fillRect(x + 18, y + 14, 4, 4);
} else {
ctx.fillRect(x + 6, y + 14, 4, 4);
ctx.fillRect(x + 14, y + 14, 4, 4);
}
} else if (inv.type === 2) { // Crab
ctx.fillRect(x + 4, y, 16, 4);
ctx.fillRect(x + 2, y + 4, 20, 8);
if (inv.frame === 0) {
ctx.fillRect(x, y + 12, 4, 6);
ctx.fillRect(x + 20, y + 12, 4, 6);
} else {
ctx.fillRect(x + 4, y + 12, 4, 6);
ctx.fillRect(x + 16, y + 12, 4, 6);
}
} else { // Octopus
ctx.fillRect(x + 6, y, 12, 4);
ctx.fillRect(x + 2, y + 4, 20, 8);
ctx.fillRect(x + 4, y + 12, 16, 4);
if (inv.frame === 0) {
ctx.fillRect(x + 2, y + 14, 3, 4);
ctx.fillRect(x + 19, y + 14, 3, 4);
} else {
ctx.fillRect(x + 7, y + 14, 3, 4);
ctx.fillRect(x + 14, y + 14, 3, 4);
}
}
});
// Draw UFO
if (ufo) {
ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--ufo-color').trim() || '#f43f5e';
ctx.beginPath();
ctx.ellipse(ufo.x + ufo.w / 2, ufo.y + ufo.h / 2, ufo.w / 2, ufo.h / 2, 0, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#ffffff';
ctx.fillRect(ufo.x + ufo.w / 2 - 4, ufo.y + 2, 8, 4);
}
}
// Keyboard controls
window.addEventListener('keydown', e => {
if (['ArrowLeft', 'ArrowRight', ' '].includes(e.key)) e.preventDefault();
if (e.key === 'ArrowLeft' || e.key === 'q' || e.key === 'Q' || e.key === 'a' || e.key === 'A') player.movingLeft = true;
else if (e.key === 'ArrowRight' || e.key === 'd' || e.key === 'D') player.movingRight = true;
else if (e.key === ' ') shootLaser();
});
window.addEventListener('keyup', e => {
if (e.key === 'ArrowLeft' || e.key === 'q' || e.key === 'Q' || e.key === 'a' || e.key === 'A') player.movingLeft = false;
else if (e.key === 'ArrowRight' || e.key === 'd' || e.key === 'D') player.movingRight = false;
});
// Touch controls
const bLeft = document.getElementById('btnLeft');
const bRight = document.getElementById('btnRight');
const bFire = document.getElementById('btnFire');
bLeft.addEventListener('pointerdown', e => { e.preventDefault(); player.movingLeft = true; });
bLeft.addEventListener('pointerup', e => { e.preventDefault(); player.movingLeft = false; });
bLeft.addEventListener('pointerleave', e => { player.movingLeft = false; });
bRight.addEventListener('pointerdown', e => { e.preventDefault(); player.movingRight = true; });
bRight.addEventListener('pointerup', e => { e.preventDefault(); player.movingRight = false; });
bRight.addEventListener('pointerleave', e => { player.movingRight = false; });
bFire.addEventListener('pointerdown', e => { e.preventDefault(); shootLaser(); });
initGame();
update();
</script>
</body>
</html>
-1
View File
@@ -1003,7 +1003,6 @@
});
// Initialize theme from URL query param safely after all variables exist
const urlParams = new URLSearchParams(window.location.search);
setTheme(urlParams.get('theme') || 'dark', urlParams.get('macosMode'));
startGame();
+7 -7
View File
@@ -585,7 +585,7 @@
} catch (e) {}
}
// Curated Levels
// Niveaux certifiés 100% faisables et vérifiés mathématiquement
const LEVELS = {
1: {
width: 5,
@@ -597,16 +597,16 @@
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'])
numbers: { '0,0': 1, '1,3': 2, '2,2': 3, '3,3': 4, '4,0': 5 },
vWalls: new Set(['0,2', '2,2']),
hWalls: new Set(['4,0', '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'])
numbers: { '0,0': 1, '1,4': 2, '2,2': 3, '3,2': 4, '4,2': 5, '5,4': 6 },
vWalls: new Set(['2,4', '0,0', '0,4']),
hWalls: new Set(['4,0', '5,3', '4,2'])
}
};