Skip to content
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

New game Path_Finder_Challenge #5137

Merged
merged 11 commits into from
Aug 9, 2024
93 changes: 0 additions & 93 deletions Games/Alien_Language_Translator/script.js

This file was deleted.

64 changes: 64 additions & 0 deletions Games/Path_Finder_Challenge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## About the game
Path Finder Challenge
Hii, I am back with another game,
The Path Finder Challenge is a grid-based puzzle game where players navigate from a source tile to a destination tile while avoiding obstacles and collecting bonuses. The game is designed with a dark theme for a modern and immersive experience.


# Game Overview
In Path Finder Challenge, you must find a path from the top-left corner of an 8x8 grid to the bottom-right corner while dealing with obstacles and collecting bonuses. The game is timed, and the goal is to achieve the highest score possible before time runs out.

# Features
Dark Theme: A sleek, dark theme for an immersive gaming experience.
Dynamic Grid: An 8x8 grid with randomly placed obstacles, bonuses, and special tiles.
Score System: Earn points by reaching the destination and avoid obstacles to maximize your score.
Timer: A countdown timer adds urgency to the game.

# Gameplay
-Objective: Navigate from the source tile (top-left) to the destination tile (bottom-right) while avoiding obstacles and collecting bonuses.
-Controls: Click on tiles to select your path. The selected path will be highlighted.
-Scoring:
Reaching the destination tile awards 100 points.
Avoiding obstacles reduces your score by 10 points.
Collect bonuses for additional points.
-Timer: You have 60 seconds to achieve the highest score possible. The game ends when the timer reaches zero.

# Installation
To run the Path Finder Challenge locally, follow these steps:

-Clone the Repository:
bash
git clone https://github.com/yourusername/path-finder-challenge.git

-Navigate to the Project Directory:
bash
cd path-finder-challenge
-Open index.html in Your Browser:
-You can simply open the index.html file in your web browser to start playing.

# Usage
Click on tiles to select and navigate your path.
Keep an eye on the score and timer.
Use the "Start Game" button to begin a new game and "Restart Game" to play again after the game ends.

# Features
-Dark Theme: Sleek and modern dark theme for an immersive gaming experience.
-Dynamic Grid: 8x8 grid with randomly assigned tiles, including obstacles, bonuses, and special tiles.
-Scoring System: Points are awarded for reaching the destination and collecting bonuses, while avoiding obstacles deducts points.
-Timer: A countdown timer adds a challenge by limiting your time to complete the game.
-Responsive Design: The game adapts to different screen sizes for a smooth experience across devices.
-Play the game by navigating through the grid and avoiding obstacles.
-Restart the game at any time by clicking the "Restart Game" button.

# Points System
Destination Reached: +100 points for successfully reaching the destination tile.
Bonus Tiles: +20 points for each bonus tile collected.
Obstacles: -10 points for each obstacle encountered.
Normal Tiles: +10 points for each normal tile clicked (except when an obstacle is encountered).

# image of the game
![Game Screenshot](assets\images\Path_Finder_Challenge.png)

# More information
Game Developer: Nikita
Assets: All symbols and assets used are free to use and modify.
Any Queries? Send Messages via my mail [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Games/Path_Finder_Challenge/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Path Finder Challenge Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="game-container">
<div class="grid-container"></div>
<div class="info-container">
<div id="score">Score: 0</div>
<div id="timer">Time: 60s</div>
<button id="start-game">Start Game</button>
<button id="restart-game">Restart Game</button>
</div>
</div>
<div class="game-over hidden">
<div>Game Over</div>
<div>Your Score: <span id="final-score">0</span></div>
</div>
<script src="script.js"></script>
</body>
</html>
148 changes: 148 additions & 0 deletions Games/Path_Finder_Challenge/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//script.js
document.addEventListener('DOMContentLoaded', () => {
let score = 0;
let time = 60;
let timer;
let gameRunning = false;
const gridSize = 8; // 8x8 grid
let sourceIndex, destinationIndex;
let selectedPath = []; // Track the selected tiles

const gridContainer = document.querySelector('.grid-container');
const scoreElement = document.getElementById('score');
const timerElement = document.getElementById('timer');
const gameOverScreen = document.querySelector('.game-over');
const finalScoreElement = document.getElementById('final-score');
const startGameButton = document.getElementById('start-game');
const restartGameButton = document.getElementById('restart-game');

if (!startGameButton || !restartGameButton) {
console.error('One or more of the required elements were not found.');
return;
}

// Apply dark theme
document.body.classList.add('dark-theme');

function startGame() {
gameRunning = true;
time = 60;
score = 0;
selectedPath = []; // Reset the selected path
scoreElement.textContent = `Score: ${score}`;
timerElement.textContent = `Time: ${time}s`;
gameOverScreen.classList.add('hidden');
gridContainer.innerHTML = ''; // Clear existing grid
createGrid();
startTimer();
}

function createGrid() {
for (let i = 0; i < gridSize * gridSize; i++) {
const tile = document.createElement('div');
tile.className = 'grid-item';
tile.dataset.index = i;
tile.addEventListener('click', handleTileClick);
gridContainer.appendChild(tile);

// Randomly assign tiles
const rand = Math.random();
if (rand < 0.15) {
tile.classList.add('obstacle');
} else if (rand < 0.2) {
tile.classList.add('bonus');
} else if (rand < 0.5) {
tile.classList.add('special');
} else {
tile.classList.add('normal');
}
}

// Set fixed source and destination indices
sourceIndex = 0; // Top-left corner
destinationIndex = gridSize * gridSize - 1; // Bottom-right corner
gridContainer.children[sourceIndex].classList.add('source');
gridContainer.children[destinationIndex].classList.add('destination');
}

function handleTileClick(event) {
if (!gameRunning) return;

const tile = event.target;
const tileIndex = parseInt(tile.dataset.index);

if (selectedPath.includes(tileIndex)) return;

tile.classList.add('selected');
selectedPath.push(tileIndex);

if (tileIndex === destinationIndex) {
score += 100;
tile.classList.add('active');
setTimeout(() => tile.classList.remove('active'), 300);
setTimeout(startGame, 500); // Restart the game after reaching destination
} else if (tile.classList.contains('obstacle')) {
score -= 10;
tile.classList.add('obstacle'); // Ensure obstacle styling is applied
} else {
score += 10;
}

scoreElement.textContent = `Score: ${score}`;

if (!hasValidPath()) {
endGame();
}
}

function hasValidPath() {
// Implement BFS or DFS to check if there's still a valid path
const queue = [sourceIndex];
const visited = new Set();
visited.add(sourceIndex);

while (queue.length > 0) {
const index = queue.shift();

if (index === destinationIndex) return true;

const directions = [-1, 1, -gridSize, gridSize];

for (const direction of directions) {
const newIndex = index + direction;

if (
newIndex >= 0 &&
newIndex < gridSize * gridSize &&
!visited.has(newIndex) &&
!gridContainer.children[newIndex].classList.contains('obstacle')
) {
visited.add(newIndex);
queue.push(newIndex);
}
}
}

return false;
}

function startTimer() {
timer = setInterval(() => {
time--;
timerElement.textContent = `Time: ${time}s`;
if (time <= 0) {
endGame();
}
}, 1000);
}

function endGame() {
clearInterval(timer);
gameRunning = false;
finalScoreElement.textContent = score;
gameOverScreen.classList.remove('hidden');
}

startGameButton.addEventListener('click', startGame);
restartGameButton.addEventListener('click', startGame);
});
Loading
Loading