-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1049 from Aditi22Bansal/main
Solved issue #1048- Quantum Maze game
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |