From 862b73a5a382932f48229830a1ee9cadbf37cd5c Mon Sep 17 00:00:00 2001 From: Ankit Kumar <139707943+ankit071105@users.noreply.github.com> Date: Sat, 10 Aug 2024 08:52:37 +0530 Subject: [PATCH] Add files via upload Added Speaking Number By Guessing As per it has been assigned me --- Games/Speaking Number Guessings/index.html | 23 +++++ Games/Speaking Number Guessings/manifest.json | 26 ++++++ Games/Speaking Number Guessings/script.js | 56 ++++++++++++ Games/Speaking Number Guessings/style.css | 85 +++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 Games/Speaking Number Guessings/index.html create mode 100644 Games/Speaking Number Guessings/manifest.json create mode 100644 Games/Speaking Number Guessings/script.js create mode 100644 Games/Speaking Number Guessings/style.css diff --git a/Games/Speaking Number Guessings/index.html b/Games/Speaking Number Guessings/index.html new file mode 100644 index 0000000000..2106e7db3d --- /dev/null +++ b/Games/Speaking Number Guessings/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + Speak Number Guess + + + Speak +

Guess a Number Between 1 - 100

+

Speak the number into your microphone

+ +
+ + + diff --git a/Games/Speaking Number Guessings/manifest.json b/Games/Speaking Number Guessings/manifest.json new file mode 100644 index 0000000000..336489e115 --- /dev/null +++ b/Games/Speaking Number Guessings/manifest.json @@ -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" + ] + } + \ No newline at end of file diff --git a/Games/Speaking Number Guessings/script.js b/Games/Speaking Number Guessings/script.js new file mode 100644 index 0000000000..f80a749a91 --- /dev/null +++ b/Games/Speaking Number Guessings/script.js @@ -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 = ` +
You said:
+ ${message} + `; +} + +function checkNumber(message) { + const number = +message; + if (Number.isNaN(number)) { + messageElement.innerHTML += "
That is not a valid number
"; + return; + } + if (number > 100 || number < 1) { + messageElement.innerHTML += "
Number must be between 1 and 100
"; + return; + } + if (number === randomNumber) { + document.body.innerHTML = ` +

Congrats! You have guessed the number!

+ It was ${number}

+ + `; + } else if (number > randomNumber) { + messageElement.innerHTML += "
GO LOWER
"; + } else { + messageElement.innerHTML += "
GO HIGHER
"; + } +} + +// 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); +}); diff --git a/Games/Speaking Number Guessings/style.css b/Games/Speaking Number Guessings/style.css new file mode 100644 index 0000000000..70ae87a7dc --- /dev/null +++ b/Games/Speaking Number Guessings/style.css @@ -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; +}