-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maze runner #4547
Closed
Closed
Maze runner #4547
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9019085
added maze_runner game in maze_runner branch
sanayamahajan-23 0841143
Update README.md
sanayamahajan-23 184223e
Update README.md
sanayamahajan-23 ad7be94
Merge branch 'kunjgit:main' into Maze_runner
sanayamahajan-23 306d086
Update README.md
sanayamahajan-23 3cf01e4
Update README.md
sanayamahajan-23 a45439a
Update README.md
sanayamahajan-23 246183a
Update README.md
sanayamahajan-23 e4525e4
added Maze_Runner.png in assets/images
sanayamahajan-23 884a25b
Update README.md
sanayamahajan-23 88e2232
Merge branch 'main' into Maze_runner
sanayamahajan-23 e549f4e
Commit local changes to pr_tags.yaml
sanayamahajan-23 9fb146e
resolved conflict
sanayamahajan-23 19ed2c2
resolved conflict in readme.md
sanayamahajan-23 22870b9
Merge branch 'Maze_runner' of https://github.com/sanayamahajan-23/Gam…
sanayamahajan-23 416f6e2
added link to game in readme.md file
sanayamahajan-23 7e10b53
resolve conflict
sanayamahajan-23 b2a4bc5
resolve conflicts
sanayamahajan-23 74d1c1a
resolve conflict
sanayamahajan-23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,78 @@ | ||
# name: Pull Request Labels | ||
|
||
# on: | ||
# pull_request_target: | ||
# types: | ||
# - opened | ||
# - synchronize | ||
|
||
# jobs: | ||
# pr-validation: | ||
# runs-on: ubuntu-latest | ||
|
||
# steps: | ||
# - name: Checkout repository | ||
# uses: actions/checkout@v2 | ||
|
||
# - name: Set up Node.js | ||
# uses: actions/setup-node@v2 | ||
# with: | ||
# node-version: '14' | ||
|
||
# - name: Install dependencies | ||
# run: npm install --prefix .github octokit | ||
|
||
# - name: Fetch related issue and labels | ||
# id: fetch_issue | ||
# uses: actions/github-script@v4 | ||
# with: | ||
# github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
# script: | | ||
# const prNumber = context.payload.pull_request.number; | ||
# const repoOwner = context.payload.repository.owner.login; | ||
# const repoName = context.payload.repository.name; | ||
|
||
# const { data: pr } = await github.pulls.get({ | ||
# owner: repoOwner, | ||
# repo: repoName, | ||
# pull_number: prNumber | ||
# }); | ||
|
||
# const issueNumber = pr.body.match(/#([0-9]+)/)[1]; | ||
|
||
# const { data: issue } = await github.issues.get({ | ||
# owner: repoOwner, | ||
# repo: repoName, | ||
# issue_number: issueNumber | ||
# }); | ||
|
||
# return { | ||
# issue: issue, | ||
# prNumber: prNumber, | ||
# repoOwner: repoOwner, | ||
# repoName: repoName | ||
# }; | ||
|
||
# - name: Apply labels to PR | ||
# if: | | ||
# steps.fetch_issue.outputs.issue.labels.some(function(label) { | ||
# return label.name.toLowerCase() === 'gssoc'; | ||
# }) | ||
# run: | | ||
# const issueLabels = steps.fetch_issue.outputs.issue.labels; | ||
# const prNumber = steps.fetch_issue.outputs.prNumber; | ||
# const repoOwner = steps.fetch_issue.outputs.repoOwner; | ||
# const repoName = steps.fetch_issue.outputs.repoName; | ||
|
||
# const prLabels = issueLabels.filter(function(label) { | ||
# return label.name.toLowerCase().startsWith('level'); | ||
# }); | ||
# prLabels.push('gssoc'); | ||
# await github.issues.addLabels({ | ||
# owner: repoOwner, | ||
# repo: repoName, | ||
# issue_number: prNumber, | ||
# labels: prLabels.map(function(label) { | ||
# return label.name; | ||
# }) | ||
# }); |
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,43 @@ | ||
# Maze_Runner | ||
<hr> | ||
<hr> | ||
<br> | ||
|
||
## **Description 📃** | ||
<hr> | ||
<br> | ||
This Maze Runner game challenges players to navigate through a randomly generated maze to reach the goal. Players control a character using arrow keys and must avoid maze walls to successfully complete each level. | ||
- | ||
|
||
## **functionalities 🎮** | ||
<hr> | ||
<br> | ||
Navigate the maze using arrow keys (Up, Down, Left, Right). | ||
Reach the goal represented by a green circle. | ||
Avoid colliding with black walls (generated randomly). | ||
Timer starts upon game start and counts down. | ||
Game over if timer reaches zero. | ||
Restart button available after game over to play again. | ||
|
||
<br> | ||
|
||
## **How to play? 🕹️** | ||
<hr> | ||
<br> | ||
Movement: Use arrow keys to move the player character. | ||
Goal: Reach the green circle to win each level. | ||
Timer: A 60-second timer starts upon game start. | ||
Game Over: Timer ends or player reaches goal. Restart button appears. | ||
Restart: Click Restart to play again from the beginning. | ||
- | ||
|
||
<br> | ||
|
||
## **Screenshots 📸** | ||
|
||
<br> | ||
|
||
![image](https://github.com/sanayamahajan-23/GameZone/blob/Maze_runner/Games/Maze_Runner/assets/images/Maze_Runner.png) | ||
|
||
<br> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Maze Runner Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div id="gameContainer"> | ||
<canvas id="gameCanvas"></canvas> | ||
<div id="timer">Time Left: <span id="time">30</span>s</div> | ||
</div> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script> | ||
<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,208 @@ | ||
const canvas = document.getElementById('gameCanvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
const canvasWidth = 800; | ||
const canvasHeight = 600; | ||
canvas.width = canvasWidth; | ||
canvas.height = canvasHeight; | ||
|
||
const cellSize = 40; | ||
let level = 1; | ||
let mazeWidth = Math.floor(canvasWidth / cellSize); | ||
let mazeHeight = Math.floor(canvasHeight / cellSize); | ||
|
||
const player = { | ||
x: 0, | ||
y: 0, | ||
size: cellSize / 2, | ||
color: 'red', | ||
speed: 5 | ||
}; | ||
|
||
const goal = { | ||
x: mazeWidth - 1, | ||
y: mazeHeight - 1, | ||
size: cellSize / 2, | ||
color: 'green' | ||
}; | ||
|
||
let maze = generateMaze(mazeWidth, mazeHeight); | ||
let timeLeft = 60; | ||
let timerInterval; | ||
|
||
function generateMaze(width, height) { | ||
const maze = new Array(height).fill(null).map(() => new Array(width).fill(1)); | ||
|
||
function carvePassagesFrom(cx, cy, maze) { | ||
const directions = shuffle([ | ||
[0, -1], // Up | ||
[1, 0], // Right | ||
[0, 1], // Down | ||
[-1, 0] // Left | ||
]); | ||
|
||
directions.forEach(([dx, dy]) => { | ||
const nx = cx + dx * 2; | ||
const ny = cy + dy * 2; | ||
|
||
if (nx >= 0 && ny >= 0 && nx < width && ny < height && maze[ny][nx] === 1) { | ||
maze[cy + dy][cx + dx] = 0; | ||
maze[ny][nx] = 0; | ||
carvePassagesFrom(nx, ny, maze); | ||
} | ||
}); | ||
} | ||
|
||
maze[0][0] = 0; | ||
carvePassagesFrom(0, 0, maze); | ||
maze[height - 1][width - 1] = 0; | ||
|
||
return maze; | ||
} | ||
|
||
function shuffle(array) { | ||
for (let i = array.length - 1; i > 0; i--) { | ||
const j = Math.floor(Math.random() * (i + 1)); | ||
[array[i], array[j]] = [array[j], array[i]]; | ||
} | ||
return array; | ||
} | ||
|
||
function drawMaze(maze) { | ||
ctx.clearRect(0, 0, canvasWidth, canvasHeight); | ||
for (let y = 0; y < mazeHeight; y++) { | ||
for (let x = 0; x < mazeWidth; x++) { | ||
if (maze[y][x] === 1) { | ||
ctx.fillStyle = 'black'; | ||
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function drawPlayer(player) { | ||
ctx.fillStyle = player.color; | ||
ctx.beginPath(); | ||
ctx.arc( | ||
player.x * cellSize + player.size, | ||
player.y * cellSize + player.size, | ||
player.size, | ||
0, | ||
Math.PI * 2 | ||
); | ||
ctx.fill(); | ||
} | ||
|
||
function drawGoal(goal) { | ||
ctx.fillStyle = goal.color; | ||
ctx.beginPath(); | ||
ctx.arc( | ||
goal.x * cellSize + goal.size, | ||
goal.y * cellSize + goal.size, | ||
goal.size, | ||
0, | ||
Math.PI * 2 | ||
); | ||
ctx.fill(); | ||
} | ||
|
||
function isCollision(x, y) { | ||
return maze[y][x] === 1; | ||
} | ||
|
||
function movePlayer(dx, dy) { | ||
const newX = player.x + dx; | ||
const newY = player.y + dy; | ||
if (newX >= 0 && newX < mazeWidth && newY >= 0 && newY < mazeHeight && !isCollision(newX, newY)) { | ||
player.x = newX; | ||
player.y = newY; | ||
checkWin(); | ||
} | ||
} | ||
|
||
function checkWin() { | ||
if (player.x === goal.x && player.y === goal.y) { | ||
clearInterval(timerInterval); | ||
// Display win message | ||
ctx.fillStyle = 'black'; | ||
ctx.font = '30px Arial'; | ||
ctx.fillText('You Won!', canvasWidth / 2 - 50, canvasHeight / 2); | ||
|
||
setTimeout(() => { | ||
nextLevel(); | ||
}, 3000); // 3 seconds delay before moving to the next level | ||
} | ||
} | ||
|
||
function nextLevel() { | ||
level++; | ||
mazeWidth = Math.floor(canvasWidth / cellSize) + level; | ||
mazeHeight = Math.floor(canvasHeight / cellSize) + level; | ||
player.x = 0; | ||
player.y = 0; | ||
goal.x = mazeWidth - 1; | ||
goal.y = mazeHeight - 1; | ||
maze = generateMaze(mazeWidth, mazeHeight); | ||
timeLeft = 30; // Reset timer for the new level | ||
startTimer(); | ||
draw(); | ||
} | ||
|
||
|
||
|
||
document.addEventListener('keydown', (event) => { | ||
switch (event.key) { | ||
case 'ArrowUp': | ||
movePlayer(0, -1); | ||
break; | ||
case 'ArrowDown': | ||
movePlayer(0, 1); | ||
break; | ||
case 'ArrowLeft': | ||
movePlayer(-1, 0); | ||
break; | ||
case 'ArrowRight': | ||
movePlayer(1, 0); | ||
break; | ||
} | ||
draw(); | ||
}); | ||
|
||
function draw() { | ||
drawMaze(maze); | ||
drawPlayer(player); | ||
drawGoal(goal); | ||
} | ||
|
||
|
||
function startTimer() { | ||
const timerDisplay = document.getElementById('time'); | ||
clearInterval(timerInterval); | ||
timerInterval = setInterval(() => { | ||
if (timeLeft > 0) { | ||
timeLeft--; | ||
timerDisplay.textContent = timeLeft; | ||
} else { | ||
clearInterval(timerInterval); | ||
alert('Game Over! Time ran out.'); | ||
resetGame(); | ||
} | ||
}, 1000); | ||
} | ||
|
||
function resetGame() { | ||
level = 1; | ||
mazeWidth = Math.floor(canvasWidth / cellSize); | ||
mazeHeight = Math.floor(canvasHeight / cellSize); | ||
player.x = 0; | ||
player.y = 0; | ||
goal.x = mazeWidth - 1; | ||
goal.y = mazeHeight - 1; | ||
maze = generateMaze(mazeWidth, mazeHeight); | ||
timeLeft = 60; | ||
startTimer(); | ||
draw(); | ||
} | ||
|
||
startTimer(); | ||
draw(); |
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,28 @@ | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#gameContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
#gameCanvas { | ||
border: 2px solid #000; | ||
background-color: #fff; | ||
} | ||
|
||
#timer { | ||
margin-top: 10px; | ||
font-size: 20px; | ||
font-weight: bold; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
place this in the asset folder of the gamezone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done all the changes