Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Mirror Mind Maze - Navigate Your Reflections</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- body {
- background: linear-gradient(135deg, #0a0a0a, #1a0033, #0a0a0a);
- color: #fff;
- font-family: 'Courier New', monospace;
- overflow: hidden;
- height: 100vh;
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
- }
- body::before {
- content: '';
- position: absolute;
- inset: 0;
- background:
- radial-gradient(circle at 20% 50%, rgba(255, 0, 255, 0.1), transparent 50%),
- radial-gradient(circle at 80% 50%, rgba(0, 255, 255, 0.1), transparent 50%);
- animation: pulse 8s ease-in-out infinite;
- pointer-events: none;
- }
- @keyframes pulse {
- 0%, 100% { opacity: 0.3; }
- 50% { opacity: 0.6; }
- }
- #gameContainer {
- position: relative;
- width: 800px;
- height: 600px;
- border: 2px solid rgba(255, 255, 255, 0.2);
- box-shadow:
- 0 0 50px rgba(255, 0, 255, 0.5),
- inset 0 0 50px rgba(0, 255, 255, 0.2);
- background: rgba(0, 0, 0, 0.8);
- }
- #maze {
- position: absolute;
- width: 100%;
- height: 100%;
- overflow: hidden;
- }
- .wall {
- position: absolute;
- background: linear-gradient(45deg, #2a2a3a, #1a1a2a);
- border: 1px solid rgba(255, 255, 255, 0.1);
- box-shadow:
- inset 0 0 10px rgba(0, 0, 0, 0.5),
- 0 0 5px rgba(100, 100, 200, 0.3);
- }
- .mirror-wall {
- background: linear-gradient(135deg,
- rgba(255, 255, 255, 0.1),
- rgba(200, 200, 255, 0.05),
- rgba(255, 255, 255, 0.1));
- backdrop-filter: blur(5px);
- border: 1px solid rgba(255, 255, 255, 0.3);
- box-shadow:
- inset 0 0 20px rgba(255, 255, 255, 0.2),
- 0 0 15px rgba(100, 200, 255, 0.4);
- animation: shimmer 3s linear infinite;
- }
- @keyframes shimmer {
- 0% { filter: brightness(1) hue-rotate(0deg); }
- 50% { filter: brightness(1.2) hue-rotate(10deg); }
- 100% { filter: brightness(1) hue-rotate(0deg); }
- }
- .player {
- position: absolute;
- width: 20px;
- height: 20px;
- background: radial-gradient(circle, #00ffff, #0088ff);
- border-radius: 50%;
- box-shadow:
- 0 0 20px #00ffff,
- 0 0 40px #00ffff,
- inset 0 0 10px rgba(255, 255, 255, 0.5);
- z-index: 10;
- transition: none;
- }
- .reflection {
- position: absolute;
- width: 20px;
- height: 20px;
- border-radius: 50%;
- opacity: 0.7;
- transition: all 0.3s ease;
- pointer-events: none;
- z-index: 5;
- }
- .reflection.type-1 {
- background: radial-gradient(circle, #ff00ff, #8800ff);
- box-shadow:
- 0 0 15px #ff00ff,
- 0 0 30px #ff00ff;
- animation: float 2s ease-in-out infinite;
- }
- .reflection.type-2 {
- background: radial-gradient(circle, #ffff00, #ff8800);
- box-shadow:
- 0 0 15px #ffff00,
- 0 0 30px #ffaa00;
- animation: float 2s ease-in-out infinite reverse;
- }
- .reflection.type-3 {
- background: radial-gradient(circle, #00ff00, #00ff88);
- box-shadow:
- 0 0 15px #00ff00,
- 0 0 30px #00ff00;
- animation: rotate 3s linear infinite;
- }
- @keyframes float {
- 0%, 100% { transform: translateY(0); }
- 50% { transform: translateY(-5px); }
- }
- @keyframes rotate {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(360deg); }
- }
- .goal {
- position: absolute;
- width: 30px;
- height: 30px;
- background: radial-gradient(circle, #fff, #00ffff, transparent);
- border-radius: 50%;
- box-shadow:
- 0 0 30px #00ffff,
- 0 0 60px #00ffff,
- inset 0 0 20px rgba(255, 255, 255, 0.8);
- animation: goalPulse 1.5s ease-in-out infinite;
- z-index: 3;
- }
- @keyframes goalPulse {
- 0%, 100% { transform: scale(1); opacity: 0.8; }
- 50% { transform: scale(1.2); opacity: 1; }
- }
- .power-up {
- position: absolute;
- width: 20px;
- height: 20px;
- box-shadow:
- 0 0 20px currentColor,
- 0 0 40px currentColor,
- inset 0 0 10px rgba(255, 255, 255, 0.5);
- animation: goalPulse 1.5s ease-in-out infinite;
- z-index: 3;
- }
- .power-up.life-up {
- background: radial-gradient(circle, #ff0000, #ff8800);
- }
- .power-up.speed-boost {
- background: radial-gradient(circle, #ffff00, #ffaa00);
- }
- .power-up.plus-reflections {
- background: radial-gradient(circle, #ff00ff, #8800ff);
- }
- .power-up.minus-reflections {
- background: radial-gradient(circle, #00ff00, #00ff88);
- }
- .power-up.invisibility {
- background: radial-gradient(circle, #0000ff, #0088ff);
- }
- .power-up.teleport {
- background: radial-gradient(circle, #ff00ff, #ff88ff);
- }
- .power-up.shield {
- background: radial-gradient(circle, #00ffff, #00aaff);
- }
- #ui {
- position: absolute;
- top: 20px;
- left: 20px;
- font-size: 14px;
- color: #00ffff;
- text-shadow: 0 0 10px #00ffff;
- z-index: 100;
- }
- #message {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- font-size: 24px;
- color: #fff;
- text-align: center;
- text-shadow: 0 0 20px currentColor;
- z-index: 1000;
- display: none;
- animation: messageGlow 1s ease-in-out;
- }
- @keyframes messageGlow {
- 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
- 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
- 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
- }
- #controls {
- position: absolute;
- bottom: 20px;
- left: 50%;
- transform: translateX(-50%);
- text-align: center;
- color: rgba(255, 255, 255, 0.6);
- font-size: 12px;
- }
- .particle {
- position: absolute;
- width: 2px;
- height: 2px;
- background: #fff;
- border-radius: 50%;
- pointer-events: none;
- animation: particleFade 1s ease-out forwards;
- }
- @keyframes particleFade {
- 0% {
- opacity: 1;
- transform: translate(0, 0) scale(1);
- }
- 100% {
- opacity: 0;
- transform: translate(var(--dx), var(--dy)) scale(0);
- }
- }
- .danger-pulse {
- animation: dangerPulse 0.5s ease-in-out infinite;
- }
- @keyframes dangerPulse {
- 0%, 100% { box-shadow: 0 0 20px #ff0000, 0 0 40px #ff0000; }
- 50% { box-shadow: 0 0 40px #ff0000, 0 0 80px #ff0000; }
- }
- .invisible {
- opacity: 0.5;
- }
- .speed-boost {
- animation: speedGlow 0.5s ease-in-out infinite;
- }
- @keyframes speedGlow {
- 0%, 100% { box-shadow: 0 0 20px #ffff00, 0 0 40px #ffff00; }
- 50% { box-shadow: 0 0 40px #ffff00, 0 0 80px #ffff00; }
- }
- </style>
- </head>
- <body>
- <div id="gameContainer">
- <div id="maze"></div>
- <div id="ui">
- <div>Level: <span id="level">1</span></div>
- <div>Moves: <span id="moves">0</span></div>
- <div>Reflections: <span id="reflectionCount">0</span></div>
- <div style="color: #ff6666;">Lives: <span id="lives">3</span></div>
- </div>
- <div id="message"></div>
- <div id="controls">
- Use ARROW KEYS or WASD to move | R to restart level<br>
- <span style="color: #ff6666;">Get surrounded by 2 reflections and lose!</span>
- </div>
- </div>
- <script>
- class MirrorMindMaze {
- constructor() {
- this.maze = document.getElementById('maze');
- this.level = 1;
- this.moves = 0;
- this.lives = 3;
- this.playerPos = { x: 1, y: 1 };
- this.goalPos = { x: 18, y: 13 };
- this.powerUps = [];
- this.activePowerUps = new Set();
- this.reflections = [];
- this.extraReflections = [];
- this.reflectionModifier = 0;
- this.moveHistory = [];
- this.gridSize = 20;
- this.cols = 40;
- this.rows = 30;
- this.walls = [];
- this.mirrorWalls = [];
- this.isMoving = false;
- this.player = null;
- this.goal = null;
- this.init();
- }
- init() {
- this.setupMaze();
- this.createPlayer();
- this.createGoal();
- this.createPowerUps();
- this.setupControls();
- this.updateUI();
- }
- setupMaze() {
- // Clear maze
- this.maze.innerHTML = '';
- this.walls = [];
- this.mirrorWalls = [];
- this.powerUps = [];
- this.activePowerUps.clear();
- // Generate maze layout
- const mazeLayout = this.level === 1 ?
- this.generateLevel1() :
- this.generateProceduralLevel();
- // Create walls
- mazeLayout.forEach(wall => {
- const wallEl = document.createElement('div');
- wallEl.className = wall.mirror ? 'wall mirror-wall' : 'wall';
- wallEl.style.left = wall.x * this.gridSize + 'px';
- wallEl.style.top = wall.y * this.gridSize + 'px';
- wallEl.style.width = wall.width * this.gridSize + 'px';
- wallEl.style.height = wall.height * this.gridSize + 'px';
- this.maze.appendChild(wallEl);
- if (wall.mirror) {
- this.mirrorWalls.push(wall);
- } else {
- this.walls.push(wall);
- }
- });
- }
- generateLevel1() {
- const layout = [];
- // Outer walls
- layout.push({ x: 0, y: 0, width: this.cols, height: 1, mirror: false });
- layout.push({ x: 0, y: this.rows - 1, width: this.cols, height: 1, mirror: false });
- layout.push({ x: 0, y: 0, width: 1, height: this.rows, mirror: false });
- layout.push({ x: this.cols - 1, y: 0, width: 1, height: this.rows, mirror: false });
- // Level 1 specific pattern
- layout.push({ x: 5, y: 5, width: 10, height: 1, mirror: true });
- layout.push({ x: 10, y: 10, width: 1, height: 8, mirror: true });
- layout.push({ x: 20, y: 5, width: 1, height: 10, mirror: true });
- layout.push({ x: 25, y: 15, width: 8, height: 1, mirror: true });
- // Regular walls
- layout.push({ x: 15, y: 2, width: 1, height: 8, mirror: false });
- layout.push({ x: 5, y: 20, width: 15, height: 1, mirror: false });
- layout.push({ x: 30, y: 8, width: 1, height: 12, mirror: false });
- // No power-ups in level 1
- this.powerUps = [];
- return layout;
- }
- generateProceduralLevel() {
- const layout = [];
- // Outer walls
- layout.push({ x: 0, y: 0, width: this.cols, height: 1, mirror: false });
- layout.push({ x: 0, y: this.rows - 1, width: this.cols, height: 1, mirror: false });
- layout.push({ x: 0, y: 0, width: 1, height: this.rows, mirror: false });
- layout.push({ x: this.cols - 1, y: 0, width: 1, height: this.rows, mirror: false });
- // Calculate complexity based on level
- const mirrorCount = Math.min(3 + this.level, 12);
- const wallCount = Math.min(5 + Math.floor(this.level / 2), 15);
- // Place random starting position
- this.playerPos = {
- x: 1 + Math.floor(Math.random() * 5),
- y: 1 + Math.floor(Math.random() * 5)
- };
- // Place goal far from start
- this.goalPos = {
- x: this.cols - 2 - Math.floor(Math.random() * 5),
- y: this.rows - 2 - Math.floor(Math.random() * 5)
- };
- // Generate mirror walls
- for (let i = 0; i < mirrorCount; i++) {
- const isHorizontal = Math.random() > 0.5;
- let wall;
- if (isHorizontal) {
- wall = {
- x: 3 + Math.floor(Math.random() * (this.cols - 10)),
- y: 3 + Math.floor(Math.random() * (this.rows - 6)),
- width: 4 + Math.floor(Math.random() * 8),
- height: 1,
- mirror: true
- };
- } else {
- wall = {
- x: 3 + Math.floor(Math.random() * (this.cols - 6)),
- y: 3 + Math.floor(Math.random() * (this.rows - 10)),
- width: 1,
- height: 4 + Math.floor(Math.random() * 8),
- mirror: true
- };
- }
- if (!this.wallBlocksPosition(wall, this.playerPos) &&
- !this.wallBlocksPosition(wall, this.goalPos)) {
- layout.push(wall);
- }
- }
- // Generate regular walls
- for (let i = 0; i < wallCount; i++) {
- const isHorizontal = Math.random() > 0.5;
- let wall;
- if (isHorizontal) {
- wall = {
- x: 2 + Math.floor(Math.random() * (this.cols - 8)),
- y: 2 + Math.floor(Math.random() * (this.rows - 4)),
- width: 3 + Math.floor(Math.random() * 6),
- height: 1,
- mirror: false
- };
- } else {
- wall = {
- x: 2 + Math.floor(Math.random() * (this.cols - 4)),
- y: 2 + Math.floor(Math.random() * (this.rows - 8)),
- width: 1,
- height: 3 + Math.floor(Math.random() * 6),
- mirror: false
- };
- }
- if (!this.wallBlocksPosition(wall, this.playerPos) &&
- !this.wallBlocksPosition(wall, this.goalPos)) {
- layout.push(wall);
- }
- }
- // Generate power-ups: 1-4 per level, spaced out
- this.powerUps = [];
- const powerUpTypes = [
- 'life-up', 'speed-boost', 'plus-reflections', 'minus-reflections',
- 'invisibility', 'teleport', 'shield'
- ];
- const numPowerUps = (this.level % 5 === 0 || this.level % 5 === 1) ? 1 + Math.floor(Math.random() * 2) : 3 + Math.floor(Math.random() * 2); // 1-2 or 3-4
- const selectedTypes = powerUpTypes.sort(() => 0.5 - Math.random()).slice(0, numPowerUps);
- selectedTypes.forEach(type => {
- let attempts = 0;
- let pos;
- do {
- pos = {
- x: 2 + Math.floor(Math.random() * (this.cols - 4)),
- y: 2 + Math.floor(Math.random() * (this.rows - 4))
- };
- attempts++;
- } while ((this.wallBlocksPositionAny(layout, pos) ||
- this.powerUps.some(p => p.pos.x === pos.x && p.pos.y === pos.y) ||
- (pos.x === this.playerPos.x && pos.y === this.playerPos.y) ||
- (pos.x === this.goalPos.x && pos.y === this.goalPos.y)) && attempts < 100);
- if (attempts < 100) {
- this.powerUps.push({ type, pos, element: null });
- }
- });
- return layout;
- }
- wallBlocksPositionAny(walls, pos) {
- return walls.some(wall => this.wallBlocksPosition(wall, pos));
- }
- wallBlocksPosition(wall, pos) {
- return pos.x >= wall.x && pos.x < wall.x + wall.width &&
- pos.y >= wall.y && pos.y < wall.y + wall.height;
- }
- createPlayer() {
- if (this.player) {
- this.player.remove();
- }
- this.player = document.createElement('div');
- this.player.className = 'player';
- this.updatePlayerPosition();
- this.maze.appendChild(this.player);
- }
- createGoal() {
- if (this.goal) {
- this.goal.remove();
- }
- this.goal = document.createElement('div');
- this.goal.className = 'goal';
- this.goal.style.left = this.goalPos.x * this.gridSize - 5 + 'px';
- this.goal.style.top = this.goalPos.y * this.gridSize - 5 + 'px';
- this.maze.appendChild(this.goal);
- }
- createPowerUps() {
- this.powerUps.forEach(powerUp => {
- if (powerUp.element) {
- powerUp.element.remove();
- }
- const el = document.createElement('div');
- el.className = `power-up ${powerUp.type}`;
- el.style.left = powerUp.pos.x * this.gridSize + 'px';
- el.style.top = powerUp.pos.y * this.gridSize + 'px';
- this.maze.appendChild(el);
- powerUp.element = el;
- });
- }
- updatePlayerPosition() {
- if (this.player) {
- this.player.style.left = this.playerPos.x * this.gridSize + 'px';
- this.player.style.top = this.playerPos.y * this.gridSize + 'px';
- this.createParticles(this.playerPos.x * this.gridSize + 10, this.playerPos.y * this.gridSize + 10);
- }
- }
- createParticles(x, y) {
- for (let i = 0; i < 5; i++) {
- const particle = document.createElement('div');
- particle.className = 'particle';
- particle.style.left = x + 'px';
- particle.style.top = y + 'px';
- particle.style.setProperty('--dx', (Math.random() - 0.5) * 30 + 'px');
- particle.style.setProperty('--dy', (Math.random() - 0.5) * 30 + 'px');
- this.maze.appendChild(particle);
- setTimeout(() => particle.remove(), 1000);
- }
- }
- setupControls() {
- document.addEventListener('keydown', (e) => {
- if (this.isMoving) return;
- let dx = 0, dy = 0;
- switch(e.key.toLowerCase()) {
- case 'arrowup':
- case 'w':
- dy = -1;
- break;
- case 'arrowdown':
- case 's':
- dy = 1;
- break;
- case 'arrowleft':
- case 'a':
- dx = -1;
- break;
- case 'arrowright':
- case 'd':
- dx = 1;
- break;
- case 'r':
- this.resetLevel();
- return;
- }
- if (dx !== 0 || dy !== 0) {
- this.movePlayer(dx, dy);
- }
- });
- }
- movePlayer(dx, dy) {
- let steps = this.activePowerUps.has('speed-boost') ? 2 : 1;
- for (let step = 0; step < steps; step++) {
- const newX = this.playerPos.x + dx;
- const newY = this.playerPos.y + dy;
- if (this.checkCollision(newX, newY)) {
- break;
- }
- this.moves++;
- this.moveHistory.push({ dx, dy, time: Date.now() });
- this.playerPos.x = newX;
- this.playerPos.y = newY;
- this.updatePlayerPosition();
- this.updateReflections(dx, dy);
- if (this.checkSurrounded()) {
- if (this.activePowerUps.has('shield')) {
- this.activePowerUps.delete('shield');
- this.showMessage('Shield blocked surround!');
- } else {
- this.loseLife();
- return;
- }
- }
- if (this.checkGoal()) {
- this.levelComplete();
- return;
- }
- this.checkPowerUps();
- }
- this.updateUI();
- this.isMoving = false;
- }
- checkCollision(x, y) {
- if (x < 1 || x >= this.cols - 1 || y < 1 || y >= this.rows - 1) return true;
- for (const wall of [...this.walls, ...this.mirrorWalls]) {
- if (x >= wall.x && x < wall.x + wall.width && y >= wall.y && y < wall.y + wall.height) return true;
- }
- for (const reflection of this.reflections) {
- if (reflection.x === x && reflection.y === y) {
- const typeColors = { 1: 'Purple', 2: 'Orange', 3: 'Green' };
- this.showMessage(`Blocked by ${typeColors[reflection.type]} reflection!`);
- console.log(`Collision: Player at (${x},${y}) hit ${typeColors[reflection.type]} at (${reflection.x},${reflection.y})`);
- return true;
- }
- }
- return false;
- }
- updateReflections(dx, dy) {
- document.querySelectorAll('.reflection').forEach(r => r.remove());
- this.reflections = [];
- let baseReflections = Math.min(5 + Math.floor(this.level / 2), 8) + this.reflectionModifier;
- baseReflections = Math.max(0, baseReflections);
- this.mirrorWalls.forEach((mirror, index) => {
- const reflectionsPerMirror = Math.min(1 + Math.floor(this.level / 3), 3);
- for (let i = 0; i < reflectionsPerMirror && this.reflections.length < baseReflections; i++) {
- const type = ((index + i) % 3) + 1;
- let refX = mirror.width > mirror.height ? this.playerPos.x + (i - 1) * 2 : 2 * mirror.x - this.playerPos.x;
- let refY = mirror.width > mirror.height ? 2 * mirror.y - this.playerPos.y : this.playerPos.y + (i - 1) * 2;
- const delay = this.moveHistory[Math.max(0, this.moveHistory.length - 3)];
- if (delay) {
- if (type === 1) {
- refX += delay.dx;
- refY += delay.dy;
- } else if (type === 2) {
- refX -= delay.dx;
- refY -= delay.dy;
- }
- }
- if (type === 3) {
- refX += Math.floor(Math.sin(Date.now() / 1000 + i) * 2);
- refY += Math.floor(Math.cos(Date.now() / 1000 + i) * 2);
- }
- if (this.activePowerUps.has('invisibility')) {
- // Invert direction to path away
- refX -= (this.playerPos.x - refX) / 2;
- refY -= (this.playerPos.y - refY) / 2;
- } else {
- // Normal attract
- refX += (this.playerPos.x - refX) / 4; // Slight pull towards player
- refY += (this.playerPos.y - refY) / 4;
- }
- // Add slight random movement like Pac-Man ghosts
- const randomDx = Math.floor(Math.random() * 3 - 1);
- const randomDy = Math.floor(Math.random() * 3 - 1);
- refX += randomDx;
- refY += randomDy;
- refX = Math.round(Math.max(1, Math.min(this.cols - 2, refX)));
- refY = Math.round(Math.max(1, Math.min(this.rows - 2, refY)));
- let valid = true;
- for (const wall of [...this.walls, ...this.mirrorWalls]) {
- if (refX >= wall.x && refX < wall.x + wall.width && refY >= wall.y && refY < wall.y + wall.height) {
- valid = false;
- break;
- }
- }
- if (valid) {
- const reflection = document.createElement('div');
- reflection.className = `reflection type-${type}`;
- reflection.style.left = refX * this.gridSize + 'px';
- reflection.style.top = refY * this.gridSize + 'px';
- this.maze.appendChild(reflection);
- this.reflections.push({ x: refX, y: refY, type });
- if (type === 2) console.log(`Orange at (${refX}, ${refY})`);
- }
- }
- });
- // Add persistent extra reflections (static)
- this.extraReflections.forEach(extra => {
- // Add slight random to extras too for consistency
- extra.x += Math.floor(Math.random() * 3 - 1);
- extra.y += Math.floor(Math.random() * 3 - 1);
- extra.x = Math.round(Math.max(1, Math.min(this.cols - 2, extra.x)));
- extra.y = Math.round(Math.max(1, Math.min(this.rows - 2, extra.y)));
- const reflection = document.createElement('div');
- reflection.className = `reflection type-${extra.type}`;
- reflection.style.left = extra.x * this.gridSize + 'px';
- reflection.style.top = extra.y * this.gridSize + 'px';
- this.maze.appendChild(reflection);
- this.reflections.push(extra);
- });
- document.getElementById('reflectionCount').textContent = this.reflections.length;
- }
- checkSurrounded() {
- let adjacent = 0;
- const positions = [
- { x: this.playerPos.x - 1, y: this.playerPos.y },
- { x: this.playerPos.x + 1, y: this.playerPos.y },
- { x: this.playerPos.x, y: this.playerPos.y - 1 },
- { x: this.playerPos.x, y: this.playerPos.y + 1 },
- { x: this.playerPos.x - 1, y: this.playerPos.y - 1 },
- { x: this.playerPos.x + 1, y: this.playerPos.y - 1 },
- { x: this.playerPos.x - 1, y: this.playerPos.y + 1 },
- { x: this.playerPos.x + 1, y: this.playerPos.y + 1 }
- ];
- for (const pos of positions) {
- for (const ref of this.reflections) {
- if (Math.round(ref.x) === pos.x && Math.round(ref.y) === pos.y) {
- adjacent++;
- break;
- }
- }
- }
- if (adjacent >= 1 && this.player) this.player.classList.add('danger-pulse');
- else if (this.player) this.player.classList.remove('danger-pulse');
- return adjacent >= 2;
- }
- loseLife() {
- this.lives--;
- if (this.lives < 0) {
- this.gameOver();
- } else {
- this.showMessage(`Surrounded! Lives: ${this.lives}`);
- setTimeout(() => this.resetLevel(), 2000);
- }
- }
- gameOver() {
- this.showMessage('Game Over! Press R to restart');
- this.level = 1;
- this.lives = 3;
- setTimeout(() => this.resetLevel(), 3000);
- }
- checkGoal() {
- return this.playerPos.x === this.goalPos.x && this.playerPos.y === this.goalPos.y;
- }
- checkPowerUps() {
- this.powerUps = this.powerUps.filter(powerUp => {
- if (this.playerPos.x === powerUp.pos.x && this.playerPos.y === powerUp.pos.y) {
- this.activatePowerUp(powerUp.type);
- powerUp.element.remove();
- return false;
- }
- return true;
- });
- }
- activatePowerUp(type) {
- this.activePowerUps.add(type);
- let message = '';
- switch (type) {
- case 'life-up':
- this.lives++;
- message = 'Life Up! +1 Life';
- break;
- case 'speed-boost':
- this.player.classList.add('speed-boost');
- message = 'Speed Boost! x2 Speed';
- break;
- case 'plus-reflections':
- for (let i = 0; i < 2; i++) {
- this.addRandomReflection();
- }
- message = '+2 Reflections!';
- break;
- case 'minus-reflections':
- if (this.extraReflections.length > 0) {
- const idx = Math.floor(Math.random() * this.extraReflections.length);
- this.extraReflections.splice(idx, 1);
- } else {
- this.reflectionModifier -= 1;
- }
- message = '-1 Reflection!';
- break;
- case 'invisibility':
- this.player.classList.add('invisible');
- message = 'Invisibility! Reflections Flee';
- break;
- case 'teleport':
- this.teleportPlayer();
- message = 'Teleport! Warped';
- this.activePowerUps.delete('teleport'); // One-time
- break;
- case 'shield':
- message = 'Shield! Blocks One Surround';
- break;
- }
- this.showMessage(message);
- this.updateUI();
- }
- addRandomReflection() {
- let refX, refY, attempts = 0;
- do {
- refX = 1 + Math.floor(Math.random() * (this.cols - 2));
- refY = 1 + Math.floor(Math.random() * (this.rows - 2));
- attempts++;
- } while (this.checkCollision(refX, refY) && attempts < 100);
- if (attempts < 100) {
- const type = Math.floor(Math.random() * 3) + 1;
- this.extraReflections.push({ x: refX, y: refY, type });
- }
- }
- teleportPlayer() {
- let newX, newY, attempts = 0;
- do {
- newX = 1 + Math.floor(Math.random() * (this.cols - 2));
- newY = 1 + Math.floor(Math.random() * (this.rows - 2));
- attempts++;
- } while (this.checkCollision(newX, newY) && attempts < 100);
- if (attempts < 100) {
- this.playerPos.x = newX;
- this.playerPos.y = newY;
- this.updatePlayerPosition();
- }
- }
- levelComplete() {
- this.showMessage(`Level ${this.level} Complete!`);
- setTimeout(() => {
- this.level++;
- this.nextLevel();
- }, 2000);
- }
- nextLevel() {
- this.moves = 0;
- this.moveHistory = [];
- this.reflections = [];
- this.extraReflections = [];
- this.reflectionModifier = 0;
- this.activePowerUps.clear();
- this.isMoving = false;
- this.setupMaze();
- this.createPlayer();
- this.createGoal();
- this.createPowerUps();
- this.updateUI();
- document.getElementById('message').style.display = 'none';
- }
- resetLevel() {
- this.moves = 0;
- this.moveHistory = [];
- this.reflections = [];
- this.extraReflections = [];
- this.reflectionModifier = 0;
- this.activePowerUps.clear();
- this.isMoving = false;
- if (this.level === 1) {
- this.playerPos = { x: 1, y: 1 };
- this.goalPos = { x: 18, y: 13 };
- }
- this.setupMaze();
- this.createPlayer();
- this.createGoal();
- this.createPowerUps();
- this.updateUI();
- document.getElementById('message').style.display = 'none';
- }
- showMessage(text) {
- const message = document.getElementById('message');
- message.textContent = text;
- message.style.display = 'block';
- if (!text.includes('Game Over')) {
- setTimeout(() => message.style.display = 'none', 1500);
- }
- }
- updateUI() {
- document.getElementById('level').textContent = this.level;
- document.getElementById('moves').textContent = this.moves;
- document.getElementById('reflectionCount').textContent = this.reflections.length;
- document.getElementById('lives').textContent = this.lives;
- }
- }
- const game = new MirrorMindMaze();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment