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

Add Gun From Sound Game #2971

Closed
wants to merge 3 commits into from
Closed
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
Binary file added Games/Gun_From_Sound/Image/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions Games/Gun_From_Sound/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# **Gun From Sound**

---

<br>

## **Description 📃**

It is a weapon Guessing Game. By this you can came to about lots of new weapon from WWII,PUBG,COD etc.

-

## **functionalities 🎮**

You will get three weapons to guess. You have to guess the weapon by hearing the firing sound of the weapon. You will get 3 chances to guess the weapon. If you guess the weapon correctly you will get 3 points. If you guess the weapon incorrectly you will lose 1 points. If you guess the weapon correctly in the first chance you will get 3 points. If you guess the weapon correctly in the second chance you will get 2 points. If you guess the weapon correctly in the third chance you will get 1 points. If you guess the weapon incorrectly in the first chance you will lose 1 points. If you guess the weapon incorrectly in the second chance you will lose 1 points. If you guess the weapon incorrectly in the third chance you will lose 1 point and get 0 point.
<br>

## **How to play? 🕹️**

First click the start button. Then you will get three weapons to guess and three chance to guess each of them. Again for each wrong ans you will lose one point. If you give wrong answer each time you will get point zero and move to the next question. After ending you can see your score. You can also play again by clicking the play again button.

-

<br>

## **Screenshots 📸**

<br>
![image](../../assets/images/Gun_From_Sound.png)

<br>

## **Working video 📹**

<!-- add your working video over here -->

<br>

## **Creator**
[Saikat Samanta](https://github.com/psykatsamanta)
Binary file added Games/Gun_From_Sound/asset/AA-12.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/AK_47.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/BanelliM4.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/Barrett50M82.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/Desert_Eagle.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/G36.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/M249.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/M95.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/MP40.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/MP5.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/P90.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/PKM.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/SPAS12.mp3
Binary file not shown.
Binary file added Games/Gun_From_Sound/asset/Thompson.mp3
Binary file not shown.
50 changes: 50 additions & 0 deletions Games/Gun_From_Sound/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<link rel="icon" type="image/png" href="./Image/icon.png" />
<title>Gun_From_Sound</title>
</head>
<body>
<div id="intro">
<h1>Gun From Sound</h1>
<p>
This is a guess game for guessing the correct name of the weapon. You
will given three gun firing sound and You will get three chance to identify it.
The more you take chance the less you will get score.
</p>
<button id="start_btn">
Lets Start<i class="fa-solid fa-arrow-right"></i>
</button>
</div>
<div id="game" class="showResult">
<div id="image_box">
<audio
controls
controlsList="nodownload"
src=""
type="audio/mp3"
></audio>
</div>
<ul>
<li id="opt1">Value1</li>
<li id="opt2">Value2</li>
<li id="opt3">Value3</li>
<li id="opt4">Value4</li>
</ul>
<div class="option">
<button id="next_ques">
Next<i class="fa-solid fa-arrow-right"></i>
</button>
</div>
</div>
<div id="result" class="showReplay">
<h1>Awesome you are a Pro Player<br />Your score is 5</h1>
<button id="replay">Play Again<i class="fa-solid fa-play"></i></button>
</div>
<script src="info.js"></script>
<script src="script.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions Games/Gun_From_Sound/info.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 115 additions & 0 deletions Games/Gun_From_Sound/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const startBtn = document.getElementById('start_btn');
const song = document.querySelector('audio');
const replayBtn = document.getElementById("replay");
const options = document.querySelectorAll("#game ul li");
const nextBtn = document.getElementById("next_ques");
const resultInfo = document.querySelector("#result h1");
const gameBox = document.getElementById("game");
const opt1 = document.getElementById("opt1");
const opt2 = document.getElementById("opt2");
const opt3 = document.getElementById("opt3");
const opt4 = document.getElementById("opt4");
const intro = document.getElementById('intro');
const ansBody = document.getElementById("result");
let question = [], i = 0, score = 0, wrongCount = 0;

// Function to start the game by clicking the start button

startBtn.addEventListener('click', () => {
intro.classList.add('fadeOut');
initQuestions();
gameBox.classList.remove("showResult");
});

// Array Of Objects For Questions And Answers

const initQuestions = () => {
question = [];
i = 0; score = 0;wrongCount = 0;
while (question.length < 3) {
const randomInd = Math.floor(Math.random() * info.length);
if (!question.includes(randomInd)) {
question.push(randomInd);
}
}
changeQuestion(i);
}

// Function For Changing The Active Class

options.forEach((option) => {
option.addEventListener("click", () => {
options.forEach((opt) => {
opt.classList.remove("active");
})
option.classList.add("active");
})
});

// Function For Changing The Question

const changeQuestion = (i) => {
song.src = info[question[i]].audio_src;
opt1.textContent = info[question[i]].option1;
opt2.textContent = info[question[i]].option2;
opt3.textContent = info[question[i]].option3;
opt4.textContent = info[question[i]].option4;
}

// Function For Checking The Answer And Deside the correct Answer and Wrong Answer and give score to the user

nextBtn.addEventListener("click", () => {
let selected = document.querySelector(".active");
if (!selected) {
alert("Please select an option");
return;
}
if (selected.textContent === info[question[i]].answer) {
i++;
score += (3 - wrongCount);
if (i === 3) {
resultInfo.textContent = `Your Score is ${score}`;
gameBox.classList.add("showResult");
ansBody.classList.remove("showReplay");
options.forEach((opt) => {
opt.classList.remove("active");
})
initQuestions();
return;
}
changeQuestion(i);
options.forEach((opt) => {
opt.classList.remove("active");
})
}
else {
alert("Wrong Answer");
wrongCount++;
if (wrongCount === 3) {
i++;
if (i == 3) {
resultInfo.textContent = `Your Score is ${score}`;
gameBox.classList.add("showResult");
ansBody.classList.remove("showReplay");
options.forEach((opt) => {
opt.classList.remove("active");
})
initQuestions();
return;
}
wrongCount = 0;
changeQuestion(i);
options.forEach((opt) => {
opt.classList.remove("active");
})
}
}
})

// Function For Restart The Game By Showing The Main Screen

replayBtn.addEventListener("click", () => {
initQuestions();
ansBody.classList.add("showReplay");
intro.classList.remove('fadeOut');
})
Loading
Loading