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

Issue #1597 Solved :- Inserted Crowd Source Escape Room #1598

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions projects/Crowd Source Escape Room/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Escape Room</title>
</head>
<body>
<div class="container">
<h1>Escape Room Challenge</h1>
<div id="puzzle-container">
<p id="puzzle-text">Solve the puzzle to escape!</p>
<input type="text" id="user-input" placeholder="Enter your answer">
<button id="submit-button">Submit</button>
<p id="feedback"></p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
61 changes: 61 additions & 0 deletions projects/Crowd Source Escape Room/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const puzzles = [
{ question: "What has keys but can't open locks?", answer: "piano" },
{ question: "I speak without a mouth and hear without ears. What am I?", answer: "echo" },
{ question: "I’m tall when I’m young, and I’m short when I’m old. What am I?", answer: "candle" }
];

let currentPuzzleIndex = 0;
let score = 0;
let timer;
const timeLimit = 30; // seconds

const puzzleText = document.getElementById('puzzle-text');
const userInput = document.getElementById('user-input');
const submitButton = document.getElementById('submit-button');
const feedback = document.getElementById('feedback');

function displayPuzzle() {
if (currentPuzzleIndex < puzzles.length) {
puzzleText.textContent = puzzles[currentPuzzleIndex].question;
feedback.textContent = '';
userInput.value = '';
startTimer();
} else {
puzzleText.textContent = "You've escaped the room! Your score: " + score;
userInput.style.display = 'none';
submitButton.style.display = 'none';
}
}

function startTimer() {
clearInterval(timer);
let timeLeft = timeLimit;
feedback.textContent = `Time left: ${timeLeft}s`;

timer = setInterval(() => {
timeLeft--;
feedback.textContent = `Time left: ${timeLeft}s`;
if (timeLeft <= 0) {
clearInterval(timer);
feedback.textContent = "Time's up! Game over.";
userInput.style.display = 'none';
submitButton.style.display = 'none';
}
}, 1000);
}

submitButton.addEventListener('click', () => {
const userAnswer = userInput.value.toLowerCase();
if (userAnswer === puzzles[currentPuzzleIndex].answer) {
feedback.textContent = "Correct! Score: " + (++score);
currentPuzzleIndex++;
displayPuzzle();
} else {
feedback.textContent = "Try again!";
userInput.classList.add('incorrect');
setTimeout(() => userInput.classList.remove('incorrect'), 500);
}
});

// Initialize the first puzzle
displayPuzzle();
54 changes: 54 additions & 0 deletions projects/Crowd Source Escape Room/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: black;
color: white;
font-family: Arial, sans-serif;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}

.container {
text-align: center;
}

#puzzle-container {
background-color: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

input {
padding: 10px;
margin: 10px 0;
border-radius: 5px;
border: none;
}

button {
padding: 10px 15px;
border: none;
border-radius: 5px;
background-color: #007BFF;
color: white;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}

#feedback {
margin-top: 10px;
}

.incorrect {
border: 2px solid red;
}
Loading