diff --git a/Games/Bulls_And_Cows_New/README.MD b/Games/Bulls_And_Cows_New/README.MD new file mode 100644 index 0000000000..24f91eaf53 --- /dev/null +++ b/Games/Bulls_And_Cows_New/README.MD @@ -0,0 +1,24 @@ +## Description:- +- The computer will have a unique 4-digit number while the player tries to guess it. +- The number to be guessed must be a 4 digit number, using unique digits only from 0 - 9(0 should not be the first digit) +- e.g. 1874 is valid, 0172 is not valid, 9877 is not valid, 9536 is valid. + +### For every guess that the player makes, he gets 2 values - the number of bulls and the number of cows. +- 1 bull means the guess and the target number have 1 digit in common, and in the correct position. +- 1 cow means the guess and the target number have 1 digit in common, but not in correct position. +Eg. Let the target be 1234. Guessing 4321 will give 0 bulls and 4 cows. 3241 will give 1 bull and 3 cows. 4 bulls means you have won the game! + +## Rules:- +The player gets total 7 chances to correctly guess the entire number and is awarded points in accordance to the number of guesses it took to win + +- 1 guess - 70 points +- 2 guess - 60 points +- 3 guess - 50 points +- 4 guess - 40 points +- 5 guess - 30 points +- 6 guess - 20 points +- 7 guess - 10 points +- if the player cannot guess then 0 points + +## Screenshot:- +![Bulls And Cows game Image](./assets/Bulls_And_Cows_New.png) \ No newline at end of file diff --git a/Games/Bulls_And_Cows_New/assets/Bulls_And_Cows_New.png b/Games/Bulls_And_Cows_New/assets/Bulls_And_Cows_New.png new file mode 100644 index 0000000000..a0c74dc9e2 Binary files /dev/null and b/Games/Bulls_And_Cows_New/assets/Bulls_And_Cows_New.png differ diff --git a/Games/Bulls_And_Cows_New/assets/arcade_game.jpg b/Games/Bulls_And_Cows_New/assets/arcade_game.jpg new file mode 100644 index 0000000000..363905984d Binary files /dev/null and b/Games/Bulls_And_Cows_New/assets/arcade_game.jpg differ diff --git a/Games/Bulls_And_Cows_New/index.html b/Games/Bulls_And_Cows_New/index.html new file mode 100644 index 0000000000..d5f9bf00b7 --- /dev/null +++ b/Games/Bulls_And_Cows_New/index.html @@ -0,0 +1,48 @@ + + + + + + Code Cracker Game + + + + +
+
+

Bulls And Cows

+
+ +
+
+ + +
+
+ + How to Play: + +
+
+ + + + + + \ No newline at end of file diff --git a/Games/Bulls_And_Cows_New/script.js b/Games/Bulls_And_Cows_New/script.js new file mode 100644 index 0000000000..7c6861c51c --- /dev/null +++ b/Games/Bulls_And_Cows_New/script.js @@ -0,0 +1,95 @@ +// JavaScript +let hiddenPattern = createRandomSequence(); +let attemptLog = []; +let attempts = 0; +let score = 0; + +function createRandomSequence() { + const distinctNumbers = new Set(); + while (distinctNumbers.size < 4) { + distinctNumbers.add(Math.floor(Math.random() * 10)); + } + return Array.from(distinctNumbers).join(""); +} + +function evaluateGuess() { + const userAttempt = document.getElementById("guess-input").value; + let exactMatches = 0; + let partialMatches = 0; + + for (let i = 0; i < 4; i++) { + if (userAttempt[i] === hiddenPattern[i]) { + exactMatches++; + } else if (hiddenPattern.includes(userAttempt[i]) && userAttempt[i]!== hiddenPattern[i]) { + partialMatches++; + } + } + + const resultMessage = `${exactMatches} Bull${exactMatches!== 1? "s" : ""} and ${partialMatches} Cow${partialMatches!== 1? "es" : ""}`; + const attemptSummary = `Attempt: ${userAttempt} - ${resultMessage}`; + attemptLog.push(attemptSummary); + + document.getElementById("output-panel").innerText = attemptSummary; + document.getElementById("guess-log").innerHTML = `Attempt History:
${attemptLog.join("
")}`; + + attempts++; + + if (exactMatches === 4) { + // Show the custom modal + document.getElementById("modal-message").innerText = "Congratulations, you cracked the code!"; + document.getElementById("modal").style.display = "block"; + + // Calculate score based on the number of attempts + switch (attempts) { + case 1: + score = 70; + break; + case 2: + score = 60; + break; + case 3: + score = 50; + break; + case 4: + score = 40; + break; + case 5: + score = 30; + break; + case 6: + score = 20; + break; + case 7: + score = 10; + break; + default: + score = 0; + } + alert(`You scored ${score} points!`); + // Reset the game + hiddenPattern = createRandomSequence(); + attemptLog = []; + attempts = 0; + score = 0; + document.getElementById("guess-input").value = ""; // Clear the guess input + document.getElementById("output-panel").innerText = ""; + document.getElementById("guess-log").innerHTML = ""; + document.getElementById("container").classList.add("celebration"); // Add celebration class + setTimeout(() => { + document.getElementById("container").classList.remove("celebration"); // Remove celebration class after 2 seconds + }, 2000); + } else if (attempts === 7) { + document.getElementById("modal-message").innerText = "Sorry, you didn't guess the code in 7 attempts. You scored 0 points."; + document.getElementById("modal").style.display = "block"; + // Reset the game + hiddenPattern = createRandomSequence(); + attemptLog = []; + attempts = 0; + score = 0; + document.getElementById("guess-input").value = ""; // Clear the guess input + document.getElementById("output-panel").innerText = ""; + document.getElementById("guess-log").innerHTML = ""; + } +} + +document.getElementById("submit").addEventListener("click", evaluateGuess); \ No newline at end of file diff --git a/Games/Bulls_And_Cows_New/style.css b/Games/Bulls_And_Cows_New/style.css new file mode 100644 index 0000000000..381f3f1a97 --- /dev/null +++ b/Games/Bulls_And_Cows_New/style.css @@ -0,0 +1,196 @@ +html, body { + height: 100%; + margin: 0; + text-align: center; + font-family: 'Press Start 2P', cursive; /* Arcade-like font */ + background: url('./assets/arcade_game.jpg') no-repeat center center fixed; + -webkit-background-size: cover; + -moz-background-size: cover; + -o-background-size: cover; + background-size: cover; + height: 100%; +} + +.container { + max-width: 800px; + margin: 40px auto; + padding: 20px; + background-color: #333; + border: 1px solid #666; + box-shadow: 0 0 60px 30px rgb(56, 56, 42), /* Inner neon yellow glow */ + 0 0 140px 90px rgb(29, 29, 29); /* Outer cyan glow */ + border-radius: 10px; /* Add a slight rounded corner effect */ + padding: 20px; /* Add some padding to the container */ +} + +.header-bar { + background-color: #222; + padding: 10px; + border-bottom: 1px solid #333; + display: flex; + justify-content: space-between; + align-items: center; +} + +.header-bar h1 { + font-size: 24px; + color: #C7F464; /* Neon pink */ + margin: 0; + text-align: center; + display: block; /* Make the h1 a block element */ + width: 100%; + text-shadow: 0 0 10px #C7F464; +} + +.header-bar .home-icon { + font-size: 24px; + color: #33CC33; /* Neon green */ + margin-left: 10px; +} + +#output-panel { + padding: 20px; + background-color: #444; + border: 1px solid #666; + border-radius: 10px; + margin-top: 20px; + margin-bottom: 20px; + color: #FFFF00; /* Neon yellow */ + text-shadow: 0 0 10px #FFFF00; +} + +#guess-input { + width: 100%; + padding: 10px; + font-size: 18px; + border: 1px solid #ccc; + border-radius: 10px; + margin-bottom: 10px; + background-color: #333; + color: #FFFFFF; /* White */ +} + +#submit-btn { + background-color: #55b94d; /* Neon pink */ + color: #FFFFFF; /* White */ + padding: 10px 20px; + border: none; + border-radius: 10px; + cursor: pointer; +} + +#submit-btn:hover { + background-color: #FFC0CB; /* Pastel pink */ +} + +#guess-log { + padding: 20px; + background-color: #444; + border: 1px solid #666; + border-radius: 10px; + margin-top: 20px; + overflow-y: auto; + max-height: 200px; + color: #33CC33; /* Neon green */ + text-shadow: 0 0 10px #33CC33; +} + +#guess-log strong { + font-weight: bold; + color: #FFFF00; /* Neon yellow */ + text-shadow: 0 0 10px #FFFF00; +} + +#game-rules { + padding: 20px; + background-color: #444; + border: 1px solid #666; + border-radius: 10px; + margin-top: 20px; + color: #FFFFFF; /* White */ + text-shadow: 0 0 10px #FFFFFF; +} + +#game-rules ul { + list-style: none; + padding: 0; + margin: 0; +} + +#game-rules li { + margin-bottom: 10px; +} + +#game-rules strong { + font-weight: bold; + color: #FF69B4; /* Neon pink */ + text-shadow: 0 0 10px #FF69B4; +} + +/* Celebration animation */ +.celebration { + animation: celebration 2s ease-in-out; +} + +.modal { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + } + + .modal-content { + background-color: #f1f1f1; + margin: 15% auto; + padding: 20px; + border: 1px solid #888; + width: 80%; + max-width: 800px; + } + + .close { + color: #aaa; + float: right; + font-size: 28px; + font-weight: bold; + } + + .close:hover, + .close:focus { + color: black; + text-decoration: none; + cursor: pointer; + } + +@keyframes celebration { + 0% { + transform: scale(1); + } + 50% { + transform: scale(1.2); + } + 100% { + transform: scale(1); + } +} + +/* Responsive design */ +@media (max-width: 600px) { + .container { + margin: 20px 20px; + padding: 10px; + } + #output-panel, #guess-log, #game-rules { + padding: 10px; + } + #guess-input { + width: 80%; + } + #submit-btn { + padding: 10px 15px; + } +} \ No newline at end of file diff --git a/README.md b/README.md index 9a10877a66..6a19ca2768 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ 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) | - +| [Bulls_And_Cows_New](https://github.com/kunjgit/GameZone/tree/main/Games/Bulls_And_Cows_New) | [Tilting Maze](https://github.com/kunjgit/GameZone/tree/main/Games/Tilting_Maze) | [Simon Game Challenge](https://github.com/kunjgit/GameZone/tree/main/Games/Simon_Game_Challenge) | [Snake Game](https://github.com/kunjgit/GameZone/tree/main/Games/Snake_Game) | [Dino Runner Game](https://github.com/kunjgit/GameZone/tree/main/Games/Dino_Runner_Game) | | [Whack a Mole](https://github.com/kunjgit/GameZone/tree/main/Games/Whack_a_Mole) | [Doraemon Jump](https://github.com/kunjgit/GameZone/tree/main/Games/Doraemon_Jump) | [Black Jack](https://github.com/kunjgit/GameZone/tree/main/Games/Black_Jack) | [Memory Game](https://github.com/kunjgit/GameZone/tree/main/Games/Memory_Game) | [Word Guessing Game](https://github.com/kunjgit/GameZone/tree/main/Games/Word_Guessing_Game) | [Ludo Game](https://github.com/kunjgit/GameZone/tree/main/Games/Ludo_Game) | [Piano Game](https://github.com/kunjgit/GameZone/tree/main/Games/Piano) | [Atari Breakout](https://github.com/kunjgit/GameZone/tree/main/Games/Atari_Breakout) | [Dinosaur Game](https://github.com/kunjgit/GameZone/tree/main/Games/Chrome_Dinosaur_Game) | [Guess The Colour by RGB Game](https://github.com/kunjgit/GameZone/tree/main/Games/Colour_Guessing_Game) | diff --git a/assets/images/Bulls_And_Cows_New.png b/assets/images/Bulls_And_Cows_New.png new file mode 100644 index 0000000000..a0c74dc9e2 Binary files /dev/null and b/assets/images/Bulls_And_Cows_New.png differ