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

Added new game #3932

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/pr_close_greet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
const commentBody = `Thank you @${commentAuthor} , for your valuable time and contribution in our GameZone 💗. \n It’s our GameZone, so Let’s build this GameZone altogether !!🤝\n Hoping to see you soon with another PR again 😇 \n Wishing you all the best for your journey into Open Source🚀
`;
await github.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
console.log(`Commented on the closed PR: ${commentBody}.`);
console.log(`Commented on the closed PR: ${commentBody}.`);
41 changes: 41 additions & 0 deletions Games/Black_jackk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


Welcome to the Blackjack Game! This is a command-line based implementation of the classic casino game Blackjack, also known as 21. The objective of the game is to beat the dealer by having a hand value closer to 21 without exceeding it.


## Screenshot
![alt text](<Screenshot 2024-05-21 165650.png>)

Rules:
Card Values: Number cards (2-10) are worth their face value, face cards (Jack, Queen, King) are worth 10, and Aces can be worth 1 or 11.

Objective: Beat the dealer by having a hand value closer to 21 without exceeding 21.

Gameplay:
Both the player and the dealer are dealt two cards initially.

The player’s cards are both face up, while the dealer has one card face up and one card face down.

The player can choose to "Hit" (take another card) or "Stand" (end their turn).

If the player’s hand exceeds 21, they "bust" and lose the game.

After the player stands, the dealer reveals their face-down card and hits until their hand is 17 or higher.

If the dealer busts, the player wins. If neither busts, the hand closer to 21 wins.


Gameplay:
Starting the Game:

Run the game script.
The initial hand is dealt, and the current hand values are displayed.
Player's Turn:

Choose to "Hit" to take another card or "Stand" to end your turn.
Dealer's Turn:

The dealer reveals their hidden card and draws until their hand value is 17 or higher.
Outcome:

The result of the game is displayed (Win, Lose, or Draw), and you are prompted to play again.
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/Black_jackk/assets/10-C.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/Black_jackk/assets/10-D.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/Black_jackk/assets/10-H.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/Black_jackk/assets/10-S.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/Black_jackk/assets/2-C.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/Black_jackk/assets/2-D.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/Black_jackk/assets/2-H.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/Black_jackk/assets/2-S.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/Black_jackk/assets/3-C.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/Black_jackk/assets/3-D.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/Black_jackk/assets/3-H.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/Black_jackk/assets/3-S.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/Black_jackk/assets/4-C.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/Black_jackk/assets/4-D.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/Black_jackk/assets/4-H.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/Black_jackk/assets/4-S.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/Black_jackk/assets/5-C.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/Black_jackk/assets/5-D.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/Black_jackk/assets/5-H.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/Black_jackk/assets/5-S.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/Black_jackk/assets/6-C.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/Black_jackk/assets/6-D.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/Black_jackk/assets/6-H.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/Black_jackk/assets/6-S.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/Black_jackk/assets/7-C.png
Binary file added Games/Black_jackk/assets/7-D.png
Binary file added Games/Black_jackk/assets/7-H.png
Binary file added Games/Black_jackk/assets/7-S.png
Binary file added Games/Black_jackk/assets/8-C.png
Binary file added Games/Black_jackk/assets/8-D.png
Binary file added Games/Black_jackk/assets/8-H.png
Binary file added Games/Black_jackk/assets/8-S.png
Binary file added Games/Black_jackk/assets/9-C.png
Binary file added Games/Black_jackk/assets/9-D.png
Binary file added Games/Black_jackk/assets/9-H.png
Binary file added Games/Black_jackk/assets/9-S.png
Binary file added Games/Black_jackk/assets/A-C.png
Binary file added Games/Black_jackk/assets/A-D.png
Binary file added Games/Black_jackk/assets/A-H.png
Binary file added Games/Black_jackk/assets/A-S.png
Binary file added Games/Black_jackk/assets/BACK.png
Binary file added Games/Black_jackk/assets/J-B.png
Binary file added Games/Black_jackk/assets/J-C.png
Binary file added Games/Black_jackk/assets/J-D.png
Binary file added Games/Black_jackk/assets/J-H.png
Binary file added Games/Black_jackk/assets/J-R.png
Binary file added Games/Black_jackk/assets/J-S.png
Binary file added Games/Black_jackk/assets/K-C.png
Binary file added Games/Black_jackk/assets/K-D.png
Binary file added Games/Black_jackk/assets/K-H.png
Binary file added Games/Black_jackk/assets/K-S.png
Binary file added Games/Black_jackk/assets/Q-C.png
Binary file added Games/Black_jackk/assets/Q-H.png
Binary file added Games/Black_jackk/assets/Q-S.png
Binary file added Games/Black_jackk/assets/blackjack.jpg
27 changes: 27 additions & 0 deletions Games/Black_jackk/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Black Jack</title>
<link rel="stylesheet" href="style.css">

</head>

<body>
<h2>Dealer: <span id="dealer-sum"></span></h2>
<div id="dealer-cards">
<img id="hidden" src="./cards/BACK.png">
</div>

<h2>You: <span id="your-sum"></span></h2>
<div id="your-cards"></div>

<br>
<button id="hit">Hit</button>
<button id="stay">Stay</button>
<p id="results"></p>

<script src="script.js"></script>
</body>
</html>
148 changes: 148 additions & 0 deletions Games/Black_jackk/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

let dealerSum = 0;
let yourSum = 0;

let dealerAceCount = 0;
let yourAceCount = 0;

let hidden;
let deck;

let canHit = true; //allows the player (you) to draw while yourSum <= 21

window.onload = function() {
buildDeck();
shuffleDeck();
startGame();
}

function buildDeck() {
let values = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
let types = ["C", "D", "H", "S"];
deck = [];

for (let i = 0; i < types.length; i++) {
for (let j = 0; j < values.length; j++) {
deck.push(values[j] + "-" + types[i]); //A-C -> K-C, A-D -> K-D
}
}
// console.log(deck);
}

function shuffleDeck() {
for (let i = 0; i < deck.length; i++) {
let j = Math.floor(Math.random() * deck.length); // (0-1) * 52 => (0-51.9999)
let temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
console.log(deck);
}

function startGame() {
hidden = deck.pop();
dealerSum += getValue(hidden);
dealerAceCount += checkAce(hidden);
// console.log(hidden);
// console.log(dealerSum);
while (dealerSum < 17) {
//<img src="./cards/4-C.png">
let cardImg = document.createElement("img");
let card = deck.pop();
cardImg.src = "./assets/" + card + ".png";
dealerSum += getValue(card);
dealerAceCount += checkAce(card);
document.getElementById("dealer-cards").append(cardImg);
}
console.log(dealerSum);

for (let i = 0; i < 2; i++) {
let cardImg = document.createElement("img");
let card = deck.pop();
cardImg.src = "./assets/" + card + ".png";
yourSum += getValue(card);
yourAceCount += checkAce(card);
document.getElementById("your-cards").append(cardImg);
}

console.log(yourSum);
document.getElementById("hit").addEventListener("click", hit);
document.getElementById("stay").addEventListener("click", stay);

}

function hit() {
if (!canHit) {
return;
}

let cardImg = document.createElement("img");
let card = deck.pop();
cardImg.src = "./assets/" + card + ".png";
yourSum += getValue(card);
yourAceCount += checkAce(card);
document.getElementById("your-cards").append(cardImg);

if (reduceAce(yourSum, yourAceCount) > 21) { //A, J, 8 -> 1 + 10 + 8
canHit = false;
}

}

function stay() {
dealerSum = reduceAce(dealerSum, dealerAceCount);
yourSum = reduceAce(yourSum, yourAceCount);

canHit = false;
document.getElementById("hidden").src = "./assets/" + hidden + ".png";

let message = "";
if (yourSum > 21) {
message = "You Lose!";
}
else if (dealerSum > 21) {
message = "You win!";
}
//both you and dealer <= 21
else if (yourSum == dealerSum) {
message = "Tie!";
}
else if (yourSum > dealerSum) {
message = "You Win!";
}
else if (yourSum < dealerSum) {
message = "You Lose!";
}

document.getElementById("dealer-sum").innerText = dealerSum;
document.getElementById("your-sum").innerText = yourSum;
document.getElementById("results").innerText = message;
}

function getValue(card) {
let data = card.split("-"); // "4-C" -> ["4", "C"]
let value = data[0];

if (isNaN(value)) { //A J Q K
if (value == "A") {
return 11;
}
return 10;
}
return parseInt(value);
}

function checkAce(card) {
if (card[0] == "A") {
return 1;
}
return 0;
}

function reduceAce(playerSum, playerAceCount) {
while (playerSum > 21 && playerAceCount > 0) {
playerSum -= 10;
playerAceCount -= 1;
}
return playerSum;
}
28 changes: 28 additions & 0 deletions Games/Black_jackk/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
}

#dealer-cards img {
height: 175px;
width: 125px;
margin: 1px;
}

#your-cards img {
height: 175px;
width: 125px;
margin: 1px;
}

#hit {
width: 100px;
height: 50px;
font-size: 20px;
}

#stay {
width: 100px;
height: 50px;
font-size: 20px;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ This repository also provides one such platforms where contributers come over an
| 166 | [Shpere](https://github.com/kunjgit/GameZone/tree/main/Games/Shpere)|
| 167 | [Short Circuit](https://github.com/kunjgit/GameZone/tree/main/Games/Short%20Circuit)|
| 168 | [Dot Connect](https://github.com/kunjgit/GameZone/tree/main/Games/Dot_Connect)|
| * | [Black_jackk](https://github.com/kunjgit/GameZone/tree/main/Games/Black_jackk)|
</center>

| Game | Game | Game | Game | Game |
Expand Down Expand Up @@ -396,7 +397,6 @@ This repository also provides one such platforms where contributers come over an
| [Rock_paper_scissor](https://github.com/kunjgit/GameZone/tree/main/Games/Rock_paper_scissor) |
| [City_Builder_Game](https://github.com/kunjgit/GameZone/tree/main/Games/City_Builder_Game) |


main

</center>
Expand Down Expand Up @@ -462,4 +462,4 @@ Terms and conditions for use, reproduction and distribution are under the [Apach
</a>
</center>
<br>
<p align="right"><a href="#top">Back to top</a></p>
<p align="right"><a href="#top">Back to top</a></p>
Binary file added assets/images/Black_jackk.jpg
2 changes: 1 addition & 1 deletion assets/index_old.html
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,7 @@ <h3 class="project-title"><a href="https://github.com/kunjgit/GameZone/tree/main
<p class="project-category">Play and have fun!</p>
</a>
</li>

<li class="project-item active" data-filter-item data-category="open source">
<a href="../Games/DoraemonRun/index.html">

Expand All @@ -2707,7 +2708,6 @@ <h3 class="project-title"><a href="../Games/DoraemonRun/index.html"
</a>
</li>


</ul>

<!-- <body> -->
Expand Down
7 changes: 5 additions & 2 deletions assets/js/gamesData.json
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,11 @@
"gameUrl": "Dice_Roller",
"thumbnailUrl": "Dice_Roller.png"
},
"392":{
"392":{
"gameTitle": "Dot Connect",
"gameUrl": "Dot_Connect",
"thumbnailUrl": "Dot_Connect.png"
}
},



Loading