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

adding Bulls_And_Cows_New #4878

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
24 changes: 24 additions & 0 deletions Games/Bulls_And_Cows_New/README.MD
Original file line number Diff line number Diff line change
@@ -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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Games/Bulls_And_Cows_New/assets/arcade_game.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions Games/Bulls_And_Cows_New/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Cracker Game</title>
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>
<body>
<div class="container">
<div class="header-bar">
<h1>Bulls And Cows</h1>
<div style="text-align:center;
font-size: 30px; "><a href="https://kunjgit.github.io/GameZone/"><i style="color:white;" class="fas fa-home home-icon"></i></a></div>

</div>
<div id="output-panel"></div>
<input type="text" id="guess-input" placeholder="e.g. 1234" onkeyup="if (event.keyCode == 13) document.getElementById('submit-btn').click()">
<button id="submit-btn" onclick="evaluateGuess()">Submit</button>
<div id="guess-log"></div>
<div id="game-rules">
<ul>
<li><strong>Bulls:</strong> Correct digit in the correct position.</li>
<li><strong>Cows:</strong> Correct digit in the wrong position.</li>
</ul>
<strong>How to Play:</strong>
<ul>
<li>You have 7 chances to guess the entire 4-digit number.</li>
<li>You will be awarded points based on the number of guesses it took to win.</li>
<li>1 guess - 70 points, 2 guesses - 60 points,..., 7 guesses - 10 points.</li>
<li>If you cannot guess the number in 7 attempts, you will score 0 points.</li>

<li>Keep guessing until you crack the code!</li>
</ul>
</div>
</div>

<div id="modal" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<p id="modal-message"></p>
</div>
</div>

<script src="./script.js"></script>
</body>
</html>
95 changes: 95 additions & 0 deletions Games/Bulls_And_Cows_New/script.js
Original file line number Diff line number Diff line change
@@ -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 = `<strong>Attempt History:</strong><br>${attemptLog.join("<br>")}`;

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);
196 changes: 196 additions & 0 deletions Games/Bulls_And_Cows_New/style.css
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
Binary file added assets/images/Bulls_And_Cows_New.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading