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

Added Time Limit #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion css/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,19 @@ body {
transform: scale(2);
opacity: 0;
}
}
}
#timer-container {
text-align: center;
margin-top: 10px;
}

#timer-prefix {
margin-bottom: 5px;
font-size: 16px;
}

#timer {
font-size: 24px;
font-weight: bold;
color: #ff0000; /* Set the color of the timer */
}
170 changes: 93 additions & 77 deletions pages/game.html
Original file line number Diff line number Diff line change
@@ -1,91 +1,107 @@
<!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="https://use.fontawesome.com/releases/v5.15.4/css/all.css"
integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm"
crossorigin="anonymous"
/>
<link rel="icon" type="image/x-icon" href="../images/Main.ico" />
<title>Quiz Page - Main Game</title>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous" />
<link rel="icon" type="image/x-icon" href="../images/Main.ico" />
<title>Quiz Page - Main Game</title>
<link rel="stylesheet" href="../css/index.css" />
<link rel="stylesheet" href="../css/game.css" />
<script type="module" defer>
import { gameQA } from "../js/data/index.js";
import { Quiz } from "../js/QuizClass.js";

<link rel="stylesheet" href="../css/index.css" />
<link rel="stylesheet" href="../css/game.css" />
<script type="module" defer>
import { gameQA } from "../js/data/index.js";
import { Quiz } from "../js/QuizClass.js";
const QuizInstance = new Quiz(gameQA);
let timer;
let timeLimit = 10; // Set the initial time limit in seconds

const QuizInstance = new Quiz(gameQA);
document.addEventListener("click", (e) => {
if (e.target.dataset.number) {
QuizInstance.checkAnswer(+e.target.dataset.number, QuizInstance.answer);
resetTimer();
}
});

document.addEventListener("click", (e) => {
if (e.target.dataset.number) {
QuizInstance.checkAnswer(
+e.target.dataset.number,
QuizInstance.answer
);
function updateTimerDisplay() {
document.getElementById("timer").innerText = `${timeLimit}s`;
}

function startTimer() {
timer = setInterval(() => {
timeLimit--;
updateTimerDisplay();

if (timeLimit <= 0) {
QuizInstance.handleTimeout();
resetTimer();
}
});
</script>
</head>
}, 1000);
}

<body>
<div class="container">
<div id="game" class="justify-center flex-column">
<div id="hud">
<div class="hud-item">
<p id="progressText" class="hud-prefix">Question</p>
<div id="progressBar">
<div id="progressBarFull"></div>
</div>
</div>
<div class="hud-item">
<p class="hud-prefix">Score</p>
<h1 class="hud-main-text" id="score">0</h1>
<p id="addPoints" class="hud-item"></p>
<p id="subPoints" class="hud-item">-100</p>
function resetTimer() {
clearInterval(timer);
timeLimit = 10;
updateTimerDisplay();
startTimer();
}

startTimer();
</script>
</head>
<body>
<div class="container">
<div id="game" class="justify-center flex-column">
<div id="hud">
<div class="hud-item">
<p id="progressText" class="hud-prefix">Question</p>
<div id="progressBar">
<div id="progressBarFull"></div>
</div>
</div>
<h1 id="question">What is the answer to this question</h1>
<div class="choice-container">
<p class="choice-prefix">A</p>
<p class="choice-text" data-number="1">Choice</p>
</div>
<div class="choice-container">
<p class="choice-prefix">B</p>
<p class="choice-text" data-number="2">Choice 2</p>
</div>
<div class="choice-container">
<p class="choice-prefix">C</p>
<p class="choice-text" data-number="3">Choice 3</p>
</div>
<div class="choice-container">
<p class="choice-prefix">D</p>
<p class="choice-text" data-number="4">Choice 4</p>
<div class="hud-item">
<p class="hud-prefix">Score</p>
<h1 class="hud-main-text" id="score">0</h1>
<p id="addPoints" class="hud-item"></p>
<p id="subPoints" class="hud-item">-100</p>
</div>
</div>
</div>
<div class="music">
<audio loop="loop" id="my_audio" preload="auto" autoplay>
<source id="audio_source" src="" type="audio/mpeg" />
</audio>

<div class="music-container flex-center flex-row">
<a
onclick="toggleMusic()"
class="button1"
id="musicOnButton"
style="display: none"
>
Music On <i class="fas fa-light fa-headphones"></i
></a>
<a onclick="pauseMusic()" class="button2">
Music Off <i class="fas fa-light fa-volume-off"></i
></a>
<div id="timer-container">
<p id="timer-prefix">Time Left:</p>
<p id="timer">10s</p>
</div>
<h1 id="question">What is the answer to this question</h1>
<div class="choice-container">
<p class="choice-prefix">A</p>
<p class="choice-text" data-number="1">Choice</p>
</div>
<div class="choice-container">
<p class="choice-prefix">B</p>
<p class="choice-text" data-number="2">Choice 2</p>
</div>
<div class="choice-container">
<p class="choice-prefix">C</p>
<p class="choice-text" data-number="3">Choice 3</p>
</div>
<div class="choice-container">
<p class="choice-prefix">D</p>
<p class="choice-text" data-number="4">Choice 4</p>
</div>
</div>
</div>
<div class="music">
<audio loop="loop" id="my_audio" preload="auto" autoplay>
<source id="audio_source" src="" type="audio/mpeg" />
</audio>
<div class="music-container flex-center flex-row">
<a onclick="toggleMusic()" class="button1" id="musicOnButton" style="display: none">
Music On <i class="fas fa-light fa-headphones"></i>
</a>
<a onclick="pauseMusic()" class="button2">
Music Off <i class="fas fa-light fa-volume-off"></i>
</a>
</div>
</body>
<script src="/js/songs.js"></script>
</div>
</body>
<script src="/js/songs.js"></script>
</html>