diff --git a/Games/BlackJack/README.md b/Games/BlackJack/README.md new file mode 100644 index 0000000000..d6ed4acad4 --- /dev/null +++ b/Games/BlackJack/README.md @@ -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]() + +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. \ No newline at end of file diff --git a/Games/BlackJack/Screenshot 2024-05-21 165650.png b/Games/BlackJack/Screenshot 2024-05-21 165650.png new file mode 100644 index 0000000000..83f93f7307 Binary files /dev/null and b/Games/BlackJack/Screenshot 2024-05-21 165650.png differ diff --git a/Games/BlackJack/blackjack.css b/Games/BlackJack/blackjack.css new file mode 100644 index 0000000000..8ea2ebb9c7 --- /dev/null +++ b/Games/BlackJack/blackjack.css @@ -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; +} \ No newline at end of file diff --git a/Games/BlackJack/blackjack.js b/Games/BlackJack/blackjack.js new file mode 100644 index 0000000000..cb4904fe86 --- /dev/null +++ b/Games/BlackJack/blackjack.js @@ -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) { + // + let cardImg = document.createElement("img"); + let card = deck.pop(); + cardImg.src = "./cards/" + 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 = "./cards/" + 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 = "./cards/" + 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 = "./cards/" + 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; +} \ No newline at end of file diff --git a/Games/BlackJack/cards/10-C.png b/Games/BlackJack/cards/10-C.png new file mode 100644 index 0000000000..18af741dbd Binary files /dev/null and b/Games/BlackJack/cards/10-C.png differ diff --git a/Games/BlackJack/cards/10-D.png b/Games/BlackJack/cards/10-D.png new file mode 100644 index 0000000000..3bbc4e06bc Binary files /dev/null and b/Games/BlackJack/cards/10-D.png differ diff --git a/Games/BlackJack/cards/10-H.png b/Games/BlackJack/cards/10-H.png new file mode 100644 index 0000000000..3eb83d72c8 Binary files /dev/null and b/Games/BlackJack/cards/10-H.png differ diff --git a/Games/BlackJack/cards/10-S.png b/Games/BlackJack/cards/10-S.png new file mode 100644 index 0000000000..0b3d29475d Binary files /dev/null and b/Games/BlackJack/cards/10-S.png differ diff --git a/Games/BlackJack/cards/2-C.png b/Games/BlackJack/cards/2-C.png new file mode 100644 index 0000000000..291ed975f2 Binary files /dev/null and b/Games/BlackJack/cards/2-C.png differ diff --git a/Games/BlackJack/cards/2-D.png b/Games/BlackJack/cards/2-D.png new file mode 100644 index 0000000000..4deee7cc84 Binary files /dev/null and b/Games/BlackJack/cards/2-D.png differ diff --git a/Games/BlackJack/cards/2-H.png b/Games/BlackJack/cards/2-H.png new file mode 100644 index 0000000000..75a014f364 Binary files /dev/null and b/Games/BlackJack/cards/2-H.png differ diff --git a/Games/BlackJack/cards/2-S.png b/Games/BlackJack/cards/2-S.png new file mode 100644 index 0000000000..1ce0ffe8b8 Binary files /dev/null and b/Games/BlackJack/cards/2-S.png differ diff --git a/Games/BlackJack/cards/3-C.png b/Games/BlackJack/cards/3-C.png new file mode 100644 index 0000000000..076ab318aa Binary files /dev/null and b/Games/BlackJack/cards/3-C.png differ diff --git a/Games/BlackJack/cards/3-D.png b/Games/BlackJack/cards/3-D.png new file mode 100644 index 0000000000..8ee0b4b902 Binary files /dev/null and b/Games/BlackJack/cards/3-D.png differ diff --git a/Games/BlackJack/cards/3-H.png b/Games/BlackJack/cards/3-H.png new file mode 100644 index 0000000000..8e74673f82 Binary files /dev/null and b/Games/BlackJack/cards/3-H.png differ diff --git a/Games/BlackJack/cards/3-S.png b/Games/BlackJack/cards/3-S.png new file mode 100644 index 0000000000..f9e06b4f01 Binary files /dev/null and b/Games/BlackJack/cards/3-S.png differ diff --git a/Games/BlackJack/cards/4-C.png b/Games/BlackJack/cards/4-C.png new file mode 100644 index 0000000000..8be9e08922 Binary files /dev/null and b/Games/BlackJack/cards/4-C.png differ diff --git a/Games/BlackJack/cards/4-D.png b/Games/BlackJack/cards/4-D.png new file mode 100644 index 0000000000..70e82e839b Binary files /dev/null and b/Games/BlackJack/cards/4-D.png differ diff --git a/Games/BlackJack/cards/4-H.png b/Games/BlackJack/cards/4-H.png new file mode 100644 index 0000000000..ceecbfe02f Binary files /dev/null and b/Games/BlackJack/cards/4-H.png differ diff --git a/Games/BlackJack/cards/4-S.png b/Games/BlackJack/cards/4-S.png new file mode 100644 index 0000000000..95abe3e737 Binary files /dev/null and b/Games/BlackJack/cards/4-S.png differ diff --git a/Games/BlackJack/cards/5-C.png b/Games/BlackJack/cards/5-C.png new file mode 100644 index 0000000000..bde9777696 Binary files /dev/null and b/Games/BlackJack/cards/5-C.png differ diff --git a/Games/BlackJack/cards/5-D.png b/Games/BlackJack/cards/5-D.png new file mode 100644 index 0000000000..bb9252558a Binary files /dev/null and b/Games/BlackJack/cards/5-D.png differ diff --git a/Games/BlackJack/cards/5-H.png b/Games/BlackJack/cards/5-H.png new file mode 100644 index 0000000000..d923456fe8 Binary files /dev/null and b/Games/BlackJack/cards/5-H.png differ diff --git a/Games/BlackJack/cards/5-S.png b/Games/BlackJack/cards/5-S.png new file mode 100644 index 0000000000..53a1aad26c Binary files /dev/null and b/Games/BlackJack/cards/5-S.png differ diff --git a/Games/BlackJack/cards/6-C.png b/Games/BlackJack/cards/6-C.png new file mode 100644 index 0000000000..a9660a0372 Binary files /dev/null and b/Games/BlackJack/cards/6-C.png differ diff --git a/Games/BlackJack/cards/6-D.png b/Games/BlackJack/cards/6-D.png new file mode 100644 index 0000000000..78a80ad06a Binary files /dev/null and b/Games/BlackJack/cards/6-D.png differ diff --git a/Games/BlackJack/cards/6-H.png b/Games/BlackJack/cards/6-H.png new file mode 100644 index 0000000000..361643efc3 Binary files /dev/null and b/Games/BlackJack/cards/6-H.png differ diff --git a/Games/BlackJack/cards/6-S.png b/Games/BlackJack/cards/6-S.png new file mode 100644 index 0000000000..40242a718b Binary files /dev/null and b/Games/BlackJack/cards/6-S.png differ diff --git a/Games/BlackJack/cards/7-C.png b/Games/BlackJack/cards/7-C.png new file mode 100644 index 0000000000..9d6b54554f Binary files /dev/null and b/Games/BlackJack/cards/7-C.png differ diff --git a/Games/BlackJack/cards/7-D.png b/Games/BlackJack/cards/7-D.png new file mode 100644 index 0000000000..6ad5f15b51 Binary files /dev/null and b/Games/BlackJack/cards/7-D.png differ diff --git a/Games/BlackJack/cards/7-H.png b/Games/BlackJack/cards/7-H.png new file mode 100644 index 0000000000..19b89a2e7e Binary files /dev/null and b/Games/BlackJack/cards/7-H.png differ diff --git a/Games/BlackJack/cards/7-S.png b/Games/BlackJack/cards/7-S.png new file mode 100644 index 0000000000..b9f1b93d33 Binary files /dev/null and b/Games/BlackJack/cards/7-S.png differ diff --git a/Games/BlackJack/cards/8-C.png b/Games/BlackJack/cards/8-C.png new file mode 100644 index 0000000000..cec743cbcd Binary files /dev/null and b/Games/BlackJack/cards/8-C.png differ diff --git a/Games/BlackJack/cards/8-D.png b/Games/BlackJack/cards/8-D.png new file mode 100644 index 0000000000..ed1295121d Binary files /dev/null and b/Games/BlackJack/cards/8-D.png differ diff --git a/Games/BlackJack/cards/8-H.png b/Games/BlackJack/cards/8-H.png new file mode 100644 index 0000000000..fb39723cb1 Binary files /dev/null and b/Games/BlackJack/cards/8-H.png differ diff --git a/Games/BlackJack/cards/8-S.png b/Games/BlackJack/cards/8-S.png new file mode 100644 index 0000000000..b6b3b3813d Binary files /dev/null and b/Games/BlackJack/cards/8-S.png differ diff --git a/Games/BlackJack/cards/9-C.png b/Games/BlackJack/cards/9-C.png new file mode 100644 index 0000000000..2174db58e1 Binary files /dev/null and b/Games/BlackJack/cards/9-C.png differ diff --git a/Games/BlackJack/cards/9-D.png b/Games/BlackJack/cards/9-D.png new file mode 100644 index 0000000000..0b933fb0e6 Binary files /dev/null and b/Games/BlackJack/cards/9-D.png differ diff --git a/Games/BlackJack/cards/9-H.png b/Games/BlackJack/cards/9-H.png new file mode 100644 index 0000000000..7b196d6dc0 Binary files /dev/null and b/Games/BlackJack/cards/9-H.png differ diff --git a/Games/BlackJack/cards/9-S.png b/Games/BlackJack/cards/9-S.png new file mode 100644 index 0000000000..3c3b5ffbc6 Binary files /dev/null and b/Games/BlackJack/cards/9-S.png differ diff --git a/Games/BlackJack/cards/A-C.png b/Games/BlackJack/cards/A-C.png new file mode 100644 index 0000000000..42bf5ec94d Binary files /dev/null and b/Games/BlackJack/cards/A-C.png differ diff --git a/Games/BlackJack/cards/A-D.png b/Games/BlackJack/cards/A-D.png new file mode 100644 index 0000000000..79cd3b8a80 Binary files /dev/null and b/Games/BlackJack/cards/A-D.png differ diff --git a/Games/BlackJack/cards/A-H.png b/Games/BlackJack/cards/A-H.png new file mode 100644 index 0000000000..b42212405c Binary files /dev/null and b/Games/BlackJack/cards/A-H.png differ diff --git a/Games/BlackJack/cards/A-S.png b/Games/BlackJack/cards/A-S.png new file mode 100644 index 0000000000..103f56d1a8 Binary files /dev/null and b/Games/BlackJack/cards/A-S.png differ diff --git a/Games/BlackJack/cards/BACK.png b/Games/BlackJack/cards/BACK.png new file mode 100644 index 0000000000..2e02e052c9 Binary files /dev/null and b/Games/BlackJack/cards/BACK.png differ diff --git a/Games/BlackJack/cards/J-B.png b/Games/BlackJack/cards/J-B.png new file mode 100644 index 0000000000..000b640bff Binary files /dev/null and b/Games/BlackJack/cards/J-B.png differ diff --git a/Games/BlackJack/cards/J-C.png b/Games/BlackJack/cards/J-C.png new file mode 100644 index 0000000000..5e003be2d4 Binary files /dev/null and b/Games/BlackJack/cards/J-C.png differ diff --git a/Games/BlackJack/cards/J-D.png b/Games/BlackJack/cards/J-D.png new file mode 100644 index 0000000000..131a97731b Binary files /dev/null and b/Games/BlackJack/cards/J-D.png differ diff --git a/Games/BlackJack/cards/J-H.png b/Games/BlackJack/cards/J-H.png new file mode 100644 index 0000000000..bf342bcb29 Binary files /dev/null and b/Games/BlackJack/cards/J-H.png differ diff --git a/Games/BlackJack/cards/J-R.png b/Games/BlackJack/cards/J-R.png new file mode 100644 index 0000000000..55b3ef9ba5 Binary files /dev/null and b/Games/BlackJack/cards/J-R.png differ diff --git a/Games/BlackJack/cards/J-S.png b/Games/BlackJack/cards/J-S.png new file mode 100644 index 0000000000..f539c19c6c Binary files /dev/null and b/Games/BlackJack/cards/J-S.png differ diff --git a/Games/BlackJack/cards/K-C.png b/Games/BlackJack/cards/K-C.png new file mode 100644 index 0000000000..68e57747d7 Binary files /dev/null and b/Games/BlackJack/cards/K-C.png differ diff --git a/Games/BlackJack/cards/K-D.png b/Games/BlackJack/cards/K-D.png new file mode 100644 index 0000000000..e21d6a0a4a Binary files /dev/null and b/Games/BlackJack/cards/K-D.png differ diff --git a/Games/BlackJack/cards/K-H.png b/Games/BlackJack/cards/K-H.png new file mode 100644 index 0000000000..1d3c468d8e Binary files /dev/null and b/Games/BlackJack/cards/K-H.png differ diff --git a/Games/BlackJack/cards/K-S.png b/Games/BlackJack/cards/K-S.png new file mode 100644 index 0000000000..2edbbc1484 Binary files /dev/null and b/Games/BlackJack/cards/K-S.png differ diff --git a/Games/BlackJack/cards/Q-C.png b/Games/BlackJack/cards/Q-C.png new file mode 100644 index 0000000000..7be5f9a96a Binary files /dev/null and b/Games/BlackJack/cards/Q-C.png differ diff --git a/Games/BlackJack/cards/Q-D.png b/Games/BlackJack/cards/Q-D.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Games/BlackJack/cards/Q-H.png b/Games/BlackJack/cards/Q-H.png new file mode 100644 index 0000000000..21839e681a Binary files /dev/null and b/Games/BlackJack/cards/Q-H.png differ diff --git a/Games/BlackJack/cards/Q-S.png b/Games/BlackJack/cards/Q-S.png new file mode 100644 index 0000000000..7983d034dd Binary files /dev/null and b/Games/BlackJack/cards/Q-S.png differ diff --git a/Games/BlackJack/cards/blackjack.jpg b/Games/BlackJack/cards/blackjack.jpg new file mode 100644 index 0000000000..6ac3ac7726 Binary files /dev/null and b/Games/BlackJack/cards/blackjack.jpg differ diff --git a/Games/BlackJack/index.html b/Games/BlackJack/index.html new file mode 100644 index 0000000000..62061b2584 --- /dev/null +++ b/Games/BlackJack/index.html @@ -0,0 +1,25 @@ + + + + + + Black Jack + + + + + +

Dealer:

+
+ +
+ +

You:

+
+ +
+ + +

+ + \ No newline at end of file diff --git a/assets/index_old.html b/assets/index_old.html index 9a98c8b0d3..eebe2698c1 100644 --- a/assets/index_old.html +++ b/assets/index_old.html @@ -2707,6 +2707,27 @@

+
  • + + +
    +
    + Eye +
    + + BlackJack +
    + +

    141. BlackJack

    + +

    BlackJack

    + + +
  • +