Skip to content
Open
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
23 changes: 23 additions & 0 deletions Games/Speaking Number Guessings/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<!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="style.css" />
<link rel="manifest" href="manifest.json">

<title>Speak Number Guess</title>
</head>
<body>
<img
src="https://i.ibb.co/Kb6SkTm/8399350-mic-microphone-audio-icon.png"
alt="Speak"
/>
<h1>Guess a Number Between 1 - 100</h1>
<h2>Speak the number into your microphone</h2>

<div id="msg" class="msg"></div>
<script src="script.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions Games/Speaking Number Guessings/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Speak Number Guess",
"short_name": "Num Guess",
"description": "A game where you guess a number between 1 and 100 by speaking it into your microphone.",
"start_url": ".",
"display": "standalone",
"background_color": "#27273d",
"theme_color": "#27273d",
"orientation": "portrait-primary",
"icons": [
{
"src": "https://i.ibb.co/Kb6SkTm/8399350-mic-microphone-audio-icon.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "https://i.ibb.co/Kb6SkTm/8399350-mic-microphone-audio-icon.png",
"sizes": "512x512",
"type": "image/png"
}
],
"permissions": [
"microphone"
]
}

56 changes: 56 additions & 0 deletions Games/Speaking Number Guessings/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const messageElement = document.getElementById("msg");

const randomNumber = getRandomNumber();

window.SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition;
let recognition = new window.SpeechRecognition();
recognition.start();

function getRandomNumber() {
return Math.floor(Math.random() * 100) + 1;
}

function onSpeak(event) {
const message = event.results[0][0].transcript;
writeMessage(message);
checkNumber(message);
}

function writeMessage(message) {
messageElement.innerHTML = `
<div>You said: </div>
<span class="box">${message}</span>
`;
}

function checkNumber(message) {
const number = +message;
if (Number.isNaN(number)) {
messageElement.innerHTML += "<div>That is not a valid number</div>";
return;
}
if (number > 100 || number < 1) {
messageElement.innerHTML += "<div>Number must be between 1 and 100</div>";
return;
}
if (number === randomNumber) {
document.body.innerHTML = `
<h2>Congrats! You have guessed the number! <br><br>
It was ${number}</h2>
<button class="play-again" id="play-again">Play Again</button>
`;
} else if (number > randomNumber) {
messageElement.innerHTML += "<div>GO LOWER</div>";
} else {
messageElement.innerHTML += "<div>GO HIGHER</div>";
}
}

// Event Listeners
recognition.addEventListener("result", onSpeak);
recognition.addEventListener("end", () => recognition.start());

document.body.addEventListener("click", (e) => {
if (e.target.id == "play-again") history.go(0);
});
85 changes: 85 additions & 0 deletions Games/Speaking Number Guessings/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@import url("https://fonts.googleapis.com/css2?family=Recursive:wght@400;700&display=swap");

* {
box-sizing: border-box;
}

body {
background: #27273d
url("https://images.unsplash.com/photo-1552749412-091909ed9f82?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80")
no-repeat center center/cover;
color: rgba(255, 255, 255, 0.87);
font-family: "Recursive", sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
height: 100vh;
overflow: hidden;
margin: 0;
}

body::after {
content: "";
background-color: rgba(0, 0, 0, 0.7);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

body * {
z-index: 1;
}

img {
width: 8rem;
height: 8rem;
}

h1,
h2 {
margin-bottom: 0;
}

h2 {
font-size: 1.17rem;
}

p {
line-height: 1.5;
margin: 0;
}

.play-again {
cursor: pointer;
padding: 0.5rem 1rem;
border: 0;
background-color: #f4f4f4;
border-radius: 5px;
margin-top: 2rem;
}

.play-again:hover {
background-color: #27273d;
color: #f4f4f4;
}

.play-again:focus {
outline: none;
}

.msg {
font-size: 1.5rem;
margin-top: 2.5rem;
}

.box {
border: 1px solid #dedede;
display: inline-block;
font-size: 1.875rem;
margin: 1.25rem;
padding: 0.625rem;
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ This repository also provides one such platforms where contributers come over an


| [Master Typing](https://github.com/kunjgit/GameZone/tree/main/Games/Master_Typing) | [Treasure Hunt](https://github.com/Antiquely3059/GameZone/tree/main/Games/Treasure%20Hunt) | [Virtual Pet](https://github.com/Antiquely3059/GameZone/tree/main/Games/Virtual_Pet) | [MazeRunner](https://github.com/kunjgit/GameZone/tree/main/Games/MazeRunner) | [Ping_Pong_Singleplayer](https://github.com/kunjgit/GameZone/tree/main/Games/Ping_Pong_Singleplayer) | [Madlibs](https://github.com/AaryanManghnani/GameZone/tree/main/Games/Madlibs) |

| [Speaking Number Guessing](https://github.com/ankit071105/GameZone/tree/main/Games/Speaking%20Number%20Guessings) |
| [Bulls_And_Cows_New](https://github.com/kunjgit/GameZone/tree/main/Games/Bulls_And_Cows_New)
| [Find The Number](https://github.com/kunjgit/GameZone/tree/main/Games/Find_the_Number)
| [Guess_That_Pokemon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_That_Pokemon)
Expand Down