Skip to content

Commit

Permalink
function reponse question
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 11, 2023
1 parent 62a6b96 commit 64ac874
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ <h1>HTML5 Pacman</h1>

<div id="popup" class="popup">
<h3 id="question">Question: How many points do you want to gain?</h3>
<button id="R1" onclick="selectResponse(10)">10 Points</button>
<button id="R2" onclick="selectResponse(20)">20 Points</button>
<button id="R3" onclick="selectResponse(30)">30 Points</button>
<button class="close-button" onclick="closePopup()">Validate</button>
<
<button id="R1" onclick="selectResponse(this)">10 Points</button>
<button id="R2" onclick="selectResponse(this)">20 Points</button>
<button id="R3" onclick="selectResponse(this)">30 Points</button>
<!-- <button class="close-button" onclick="closePopup()">Validate</button> -->
</div>
<script src="question.js"></script>
<script src="pacman.js"></script>
Expand All @@ -86,6 +87,7 @@ <h3 id="question">Question: How many points do you want to gain?</h3>
if (Modernizr.canvas && Modernizr.localstorage &&
Modernizr.audio && (Modernizr.audio.ogg || Modernizr.audio.mp3)) {
window.setTimeout(function () { PACMAN.init(el, "./"); }, 0);

} else {
el.innerHTML = "Sorry, needs a decent browser<br /><small>" +
"(firefox 3.6+, Chrome 4+, Opera 10+ and Safari 4+)</small>";
Expand Down
62 changes: 41 additions & 21 deletions pacman.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ Pacman.Ghost = function (game, map, colour) {

Pacman.User = function (game, map) {

var position = null,
let position = null,
direction = null,
eaten = null,
due = null,
lives = null,
score = 5,
score = 0,
keyMap = {};

keyMap[KEY.ARROW_LEFT] = LEFT;
Expand All @@ -293,6 +293,7 @@ Pacman.User = function (game, map) {
keyMap[KEY.ARROW_DOWN] = DOWN;

function addScore(nScore) {
console.log("coucou depuis addscore")
score += nScore;
if (score >= 10000 && score - nScore < 10000) {
lives += 1;
Expand Down Expand Up @@ -436,7 +437,6 @@ Pacman.User = function (game, map) {
block === Pacman.BISCUIT || block === Pacman.PILL) {

map.setBlock(nextWhole, Pacman.EMPTY);
addScore((block === Pacman.BISCUIT) ? 0 : 50);

if (eaten === 4) {
game.completedLevel();
Expand Down Expand Up @@ -878,7 +878,7 @@ var PACMAN = (function () {
}

function setState(nState) {
console.log(nState)
// console.log(nState)
state = nState;
stateChanged = true;
};
Expand Down Expand Up @@ -1019,16 +1019,15 @@ var PACMAN = (function () {
drawFooter();
}

function eatenPill() {
function eatenPill() {
audio.play("eatpill");
timerStart = tick;
eatenCount = 0;
console.log("miam")
// console.log("miam")
const randomQuestionNumber = Math.floor(Math.random() * questionsRestante);

openPopup(randomQuestionNumber, questions);
questions.splice(randomQuestionNumber);
console.log(questions.length)

for (i = 0; i < ghosts.length; i += 1) {
ghosts[i].makeEatable(ctx);
}
Expand Down Expand Up @@ -1112,7 +1111,10 @@ var PACMAN = (function () {
};

return {
"init" : init
"init" : init,
"questions" : questions,
"questionsRestante": questionsRestante,
"user" : user
};

}());
Expand Down Expand Up @@ -1305,16 +1307,22 @@ const pe = new KeyboardEvent('keydown', {
cancelable: true,
});

function openPopup(index, questions) {
function openPopup(index) {
const popup = document.getElementById("popup");
const question = document.getElementById("question")
const R1 = document.getElementById("R1")
const R2 = document.getElementById("R2")
const R3 = document.getElementById("R3")

question.textContent = questions["question"]
const question = document.getElementById("question");
const R1 = document.getElementById("R1");
const R2 = document.getElementById("R2");
const R3 = document.getElementById("R3");


question.textContent = PACMAN.questions[index].question;
R1.textContent = PACMAN.questions[index].answers[0];
R1.setAttribute("key", index);
R2.textContent = PACMAN.questions[index].answers[1];
R2.setAttribute("key", index);
R3.textContent = PACMAN.questions[index].answers[2];
R3.setAttribute("key", index);

console.log("popup affiche")
document.dispatchEvent(pe);
popup.style.display = "block";
}
Expand All @@ -1329,13 +1337,25 @@ function closePopup() {
}

// Function to handle response selection
function selectResponse(points) {
// You can perform any action here with the selected points value
console.log(`Selected ${points} points.`);
function selectResponse(button) {
const id = button.getAttribute('key')
// console.log(PACMAN.questionsRestante);
// console.log(id);
// console.log("pacmanquestion " + PACMAN.questions[id].answers);
if(button.textContent === PACMAN.questions[id].correctAnswer){
window.alert("Bonne réponse");
}else {
window.alert("Faux");
}

PACMAN.questions.splice(id, 1);
PACMAN.questionsRestante --;
closePopup();

}

// Simulate opening the popup when Pac-Man eats a pill
function simulatePillEating() {
openPopup();
}

0 comments on commit 64ac874

Please sign in to comment.