@ -0,0 +1,74 @@ |
|||
<!DOCTYPE html> |
|||
|
|||
<html> |
|||
|
|||
<head> |
|||
|
|||
<meta charset="utf-8"> |
|||
|
|||
<title>casino 77</title> |
|||
|
|||
<link rel="stylesheet" type="text/css" href="styles.css"> |
|||
</head> |
|||
<body> |
|||
|
|||
|
|||
|
|||
|
|||
<img class=logo src="image/logo.png"> |
|||
|
|||
<a href="Index.html"> |
|||
<img class=accueil src="image/accueil.png"> |
|||
</a> |
|||
|
|||
|
|||
<div class="loader"> |
|||
|
|||
<span class="lettre">7</span> |
|||
|
|||
<span class="lettre">7</span> |
|||
|
|||
<span class="lettre">7</span> |
|||
</div> |
|||
|
|||
<h2 class="h2bj">BLACK JACK</h2> |
|||
|
|||
<div class="bjform"> |
|||
<h3>Dealer: <span id="dealer-sum"></span></h3> |
|||
<div id="dealer-cards"> |
|||
<img id="hidden" src="./cards/BACK.png"> |
|||
</div> |
|||
|
|||
<h3>You: <span id="your-sum"></span></h3> |
|||
<div id="your-cards"></div> |
|||
|
|||
<br> |
|||
<div class="buttonhs"> |
|||
<button id="hit">Hit</button> |
|||
<button id="stay">Stay</button> |
|||
</div> |
|||
<p id="results"></p> |
|||
</div> |
|||
|
|||
<div class="reload"> |
|||
<input type="button" onclick='window.location.reload(false)' value="Rafraichir" /> |
|||
</div> |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
<div class="bg"></div> |
|||
|
|||
<script src="loading.js"></script> |
|||
<script src="bj.js"></script> |
|||
|
|||
</body> |
|||
</html> |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 203 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 255 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 242 KiB |
After Width: | Height: | Size: 257 KiB |
After Width: | Height: | Size: 260 KiB |
After Width: | Height: | Size: 273 KiB |
After Width: | Height: | Size: 197 KiB |
After Width: | Height: | Size: 279 KiB |
After Width: | Height: | Size: 191 KiB |
After Width: | Height: | Size: 238 KiB |
After Width: | Height: | Size: 201 KiB |
@ -0,0 +1,151 @@ |
|||
var dealerSum = 0; |
|||
var yourSum = 0; |
|||
|
|||
var dealerAceCount = 0; |
|||
var yourAceCount = 0; |
|||
|
|||
var hidden; |
|||
var deck; |
|||
|
|||
var canHit = true; |
|||
|
|||
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]); |
|||
} |
|||
} |
|||
// console.log(deck);
|
|||
} |
|||
|
|||
function shuffleDeck() { |
|||
for (let i = 0; i < deck.length; i++) { |
|||
let j = Math.floor(Math.random() * deck.length); |
|||
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 = "./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) { |
|||
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 = "Tu as perdu!"; |
|||
} |
|||
else if (dealerSum > 21) { |
|||
message = "Tu as gagné!"; |
|||
} |
|||
//both you and dealer <= 21
|
|||
else if (yourSum == dealerSum) { |
|||
message = "Egalite!"; |
|||
} |
|||
else if (yourSum > dealerSum) { |
|||
message = "Tu as gagné!"; |
|||
} |
|||
else if (yourSum < dealerSum) { |
|||
message = "Tu as perdu!"; |
|||
} |
|||
|
|||
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; |
|||
} |
|||
|
|||
var refresh = window.getElementById('refresh'); |
|||
refresh.addEventListener('click', location.reload(), false); |
|||
|
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 795 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 203 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 255 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 242 KiB |
After Width: | Height: | Size: 257 KiB |
After Width: | Height: | Size: 260 KiB |
After Width: | Height: | Size: 273 KiB |
After Width: | Height: | Size: 197 KiB |
After Width: | Height: | Size: 279 KiB |
After Width: | Height: | Size: 191 KiB |
After Width: | Height: | Size: 238 KiB |
After Width: | Height: | Size: 201 KiB |