Skip to content

Commit

Permalink
Merge pull request #1049 from Aditi22Bansal/main
Browse files Browse the repository at this point in the history
Solved issue #1048- Quantum Maze game
  • Loading branch information
Durgesh4993 authored Jul 2, 2024
2 parents 14de412 + 0d7c800 commit 6b4aa69
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
16 changes: 16 additions & 0 deletions SinglePlayer - Games/Quantum_Maze/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quantum Maze</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Quantum Maze</h1>
<div id="game-container">
<canvas id="gameCanvas"></canvas>
</div>
<script src="script.js"></script>
</body>
</html>
82 changes: 82 additions & 0 deletions SinglePlayer - Games/Quantum_Maze/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 600;
canvas.height = 600;


const gridSize = 20;
const mazeSize = canvas.width / gridSize;
const player = {
x: 0,
y: 0,
color: 'yellow'
};


const quantumWalls = [];
const entangledPaths = [];


for (let i = 0; i < mazeSize; i++) {
quantumWalls[i] = [];
for (let j = 0; j < mazeSize; j++) {
quantumWalls[i][j] = Math.random() > 0.7 ? 'wall' : 'empty';
}
}


function drawMaze() {
for (let i = 0; i < mazeSize; i++) {
for (let j = 0; j < mazeSize; j++) {
if (quantumWalls[i][j] === 'wall') {
ctx.fillStyle = 'grey';
ctx.fillRect(i * gridSize, j * gridSize, gridSize, gridSize);
}
}
}
}


function drawPlayer() {
ctx.fillStyle = player.color;
ctx.fillRect(player.x * gridSize, player.y * gridSize, gridSize, gridSize);
}


function movePlayer(x, y) {
if (x >= 0 && x < mazeSize && y >= 0 && y < mazeSize) {
if (quantumWalls[x][y] !== 'wall') {
player.x = x;
player.y = y;
collapseWalls(x, y);
}
}
}


function collapseWalls(x, y) {
if (Math.random() > 0.5) {
quantumWalls[x][y] = 'empty';
} else {
quantumWalls[x][y] = 'wall';
}
}


document.addEventListener('keydown', (event) => {
if (event.key === 'ArrowUp') movePlayer(player.x, player.y - 1);
if (event.key === 'ArrowDown') movePlayer(player.x, player.y + 1);
if (event.key === 'ArrowLeft') movePlayer(player.x - 1, player.y);
if (event.key === 'ArrowRight') movePlayer(player.x + 1, player.y);
updateGame();
});


function updateGame() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawMaze();
drawPlayer();
}


updateGame();
25 changes: 25 additions & 0 deletions SinglePlayer - Games/Quantum_Maze/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #000;
color: #fff;
margin: 0;
font-family: Arial, sans-serif;
}


#game-container {
position: relative;
width: 600px;
height: 600px;
background-color: #333;
}


canvas {
border: 2px solid #fff;
background-color: #222;
}

0 comments on commit 6b4aa69

Please sign in to comment.