-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
256686c
commit c071ae7
Showing
8 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
**Description** | ||
It is a game where the user takes turns to guess a four digit number generated by the computer | ||
|
||
**Rules** | ||
Guess a 4-digit code where each digit is unique. | ||
You'll receive feedback after each guess: | ||
Bulls: Correct digit in the correct position. | ||
Cows: Correct digit in the wrong position. | ||
Keep guessing until you get 4 bulls! |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Bulls and Cows Game</title> | ||
<link rel="stylesheet" href="./styles.css"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" /> | ||
</head> | ||
<body> | ||
<div class="wrapper"> | ||
<div class="navbar"> | ||
<h1>Bulls and Cows Game</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="console"></div> | ||
<input type="text" id="try" placeholder="e.g. 1234" onkeyup="if (event.keyCode == 13) document.getElementById('submit').click()"> | ||
<button id="submit" onclick="check()">Submit</button> | ||
<div id="history"></div> | ||
<div id="rules"> | ||
<strong>Rules:</strong> | ||
<ul> | ||
<li>Guess a 4-digit code where each digit is unique.</li> | ||
<li>You'll receive feedback after each guess:</li> | ||
|
||
<li><strong>Bulls:</strong> Correct digit in the correct position.</li> | ||
<li><strong>Cows:</strong> Correct digit in the wrong position.</li> | ||
|
||
<li>Keep guessing until you get 4 bulls!</li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
let secretCode = generateRandomCode(); | ||
let guesses = []; | ||
|
||
function generateRandomCode() { | ||
const uniqueDigits = new Set(); | ||
while (uniqueDigits.size < 4) { | ||
uniqueDigits.add(Math.floor(Math.random() * 10)); | ||
} | ||
return Array.from(uniqueDigits).join(""); | ||
} | ||
|
||
function check() { | ||
const guess = document.getElementById("try").value; | ||
let bulls = 0; | ||
let cows = 0; | ||
|
||
for (let i = 0; i < 4; i++) { | ||
if (guess[i] === secretCode[i]) { | ||
bulls++; | ||
} else if (secretCode.includes(guess[i]) && guess[i] !== secretCode[i]) { | ||
cows++; | ||
} | ||
} | ||
|
||
const result = `${bulls} bull${bulls !== 1 ? "s" : ""} and ${cows} cow${cows !== 1 ? "s" : ""}`; | ||
const guessInfo = `Your guess: ${guess} - ${result}`; | ||
guesses.push(guessInfo); | ||
|
||
document.getElementById("console").innerText = guessInfo; | ||
document.getElementById("history").innerHTML = `<strong>Guess History:</strong><br>${guesses.join("<br>")}`; | ||
|
||
if (bulls === 4) { | ||
alert("Congratulations, you guessed it!"); | ||
// Reset the game | ||
secretCode = generateRandomCode(); | ||
guesses = []; | ||
document.getElementById("try").value = ""; // Clear the guess input | ||
document.getElementById("console").innerText = ""; | ||
document.getElementById("history").innerHTML = ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
html, body { | ||
height: 100%; | ||
margin: 0; | ||
text-align: center; | ||
} | ||
.wrapper { | ||
background-color: lightgrey; | ||
height: 100%; | ||
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; | ||
} | ||
.navbar{ | ||
display: flex; | ||
background-color: black; | ||
color: white; | ||
padding-top: 1em; | ||
padding-bottom: 1em; | ||
position: relative; | ||
top: 0; | ||
justify-content: space-between; | ||
padding-inline: 5vh; | ||
align-items: center; | ||
} | ||
h1 { | ||
|
||
|
||
} | ||
#console { | ||
text-align: left; | ||
} | ||
#try { | ||
width: 150px; | ||
margin: 2em; | ||
} | ||
li{ | ||
list-style: none; | ||
margin-top: 3px; | ||
/* width: fit-content; */ | ||
} | ||
#history { | ||
margin-top: 1em; | ||
|
||
} | ||
#rules { | ||
margin-top: 1em; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
gap: 4px; | ||
|
||
} | ||
|
||
ul{ | ||
display: flex; | ||
flex-direction: column; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters