memperbarui UI
This commit is contained in:
parent
642010ba79
commit
044095e267
397
html.php
397
html.php
@ -1,68 +1,411 @@
|
|||||||
<?php
|
<?php
|
||||||
|
include 'koneksi.php';
|
||||||
session_start();
|
session_start();
|
||||||
// If not logged in, redirect to login
|
// If not logged in, redirect to login
|
||||||
if (!isset($_SESSION['username'])) {
|
if (!isset($_SESSION['username'])) {
|
||||||
header('Location: loginn.php');
|
header('Location: loginn.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch latest balance from database
|
||||||
|
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
||||||
|
$res = mysqli_query($conn, "SELECT balance FROM users WHERE username = '$username'");
|
||||||
|
if ($res && mysqli_num_rows($res) > 0) {
|
||||||
|
$row = mysqli_fetch_assoc($res);
|
||||||
|
$_SESSION['balance'] = (int)$row['balance'];
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="id">
|
<html lang="id">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
<title>Blackjack [21] - OCA GameHub</title>
|
<title>Blackjack Pro - OCA GameHub</title>
|
||||||
|
|
||||||
|
<!-- Fonts -->
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
<link rel="stylesheet" href="cliff.css" />
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg-color: #0a3a1a; /* Fallback */
|
||||||
|
--panel-bg: rgba(0, 60, 20, 0.6);
|
||||||
|
--accent: #00FF00;
|
||||||
|
--accent-hover: #00CC00;
|
||||||
|
--danger: #FF6B6B;
|
||||||
|
--text-main: #e8ffe8;
|
||||||
|
--text-highlight: #00FF00;
|
||||||
|
--text-muted: #88FF88;
|
||||||
|
--card-bg: #ffffff;
|
||||||
|
--gold: #f59e0b;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
background: linear-gradient(135deg, #0a3a1a 0%, #0d5a2a 50%, #0f7a3a 100%);
|
||||||
|
font-family: 'Outfit', sans-serif;
|
||||||
|
color: var(--text-main);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 1000px;
|
||||||
|
background: rgba(0, 40, 10, 0.4);
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
-webkit-backdrop-filter: blur(12px);
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||||
|
border-radius: 24px;
|
||||||
|
padding: 30px;
|
||||||
|
box-shadow: 0 0 40px rgba(0, 255, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-top {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text-highlight);
|
||||||
|
text-shadow: 0 0 15px rgba(0, 255, 0, 0.5);
|
||||||
|
background: none;
|
||||||
|
-webkit-background-clip: unset;
|
||||||
|
-webkit-text-fill-color: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-badge {
|
||||||
|
background: rgba(0, 255, 0, 0.15);
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 50px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--text-highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-link {
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 14px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-topup {
|
||||||
|
background: linear-gradient(135deg, #00FF00, #00CC00);
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
.btn-topup:hover {
|
||||||
|
box-shadow: 0 0 20px rgba(0, 255, 0, 0.6);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
.btn-logout { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
|
||||||
|
.btn-logout:hover { background: var(--danger); color: white; box-shadow: 0 0 15px rgba(255, 107, 107, 0.4); }
|
||||||
|
|
||||||
|
.game-stats {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
background: rgba(0, 0, 0, 0.25);
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.1);
|
||||||
|
padding: 15px 20px;
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
|
||||||
|
.stat-value { font-size: 20px; font-weight: 700; color: var(--gold); }
|
||||||
|
|
||||||
|
.bet-controls {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="number"] {
|
||||||
|
background: rgba(0, 100, 0, 0.2);
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.3);
|
||||||
|
color: var(--text-highlight);
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
width: 100px;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="number"]:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #00FF00;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Game Board */
|
||||||
|
main {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-section {
|
||||||
|
background: rgba(0, 20, 5, 0.3);
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 20px;
|
||||||
|
min-height: 300px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
font-size: 14px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hand {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
min-height: 140px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Card Styling */
|
||||||
|
.card {
|
||||||
|
width: 90px;
|
||||||
|
height: 130px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 12px;
|
||||||
|
color: #333;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 10px;
|
||||||
|
font-family: system-ui, sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 24px;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
|
||||||
|
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
|
||||||
|
animation: dealCard 0.4s ease-out backwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card:hover { transform: translateY(-10px) scale(1.05); z-index: 10; }
|
||||||
|
|
||||||
|
@keyframes dealCard {
|
||||||
|
from { opacity: 0; transform: translateY(-50px) scale(0.5); }
|
||||||
|
to { opacity: 1; transform: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.card.red { color: #e11d48; }
|
||||||
|
.card.back {
|
||||||
|
background: linear-gradient(135deg, #052e16 0%, #14532d 100%);
|
||||||
|
color: transparent;
|
||||||
|
border: 2px solid rgba(0,255,0,0.2);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.card.back::after {
|
||||||
|
content: "♠";
|
||||||
|
color: rgba(0,255,0,0.2);
|
||||||
|
font-size: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.values {
|
||||||
|
margin-top: auto;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
border: 1px solid rgba(0, 255, 0, 0.2);
|
||||||
|
padding: 5px 15px;
|
||||||
|
border-radius: 50px;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Action Buttons */
|
||||||
|
.actions-container {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-game {
|
||||||
|
padding: 12px 30px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.1s, filter 0.2s;
|
||||||
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
|
||||||
|
font-family: 'Outfit', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-game:active { transform: scale(0.95); }
|
||||||
|
.btn-hit {
|
||||||
|
background: linear-gradient(to bottom, #00FF00, #00CC00);
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
.btn-stand { background: linear-gradient(to bottom, #ef4444, #dc2626); }
|
||||||
|
.btn-double { background: linear-gradient(to bottom, #f59e0b, #d97706); }
|
||||||
|
.btn-bet {
|
||||||
|
background: linear-gradient(to bottom, #00FF00, #00CC00);
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
.btn-secondary {
|
||||||
|
background: rgba(0, 255, 0, 0.1);
|
||||||
|
color: var(--text-highlight);
|
||||||
|
border: 1px solid var(--text-highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-game:hover { filter: brightness(1.1); transform: translateY(-2px); box-shadow: 0 0 15px rgba(0, 255, 0, 0.3); }
|
||||||
|
.btn-game:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(1); transform: none; box-shadow: none;}
|
||||||
|
|
||||||
|
#message {
|
||||||
|
height: 40px;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 700;
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.win { color: #4ade80; text-shadow: 0 0 20px rgba(74, 222, 128, 0.5); }
|
||||||
|
.lose { color: #f87171; text-shadow: 0 0 20px rgba(248, 113, 113, 0.5); }
|
||||||
|
|
||||||
|
footer {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 40px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
main { grid-template-columns: 1fr; }
|
||||||
|
.header-top { flex-direction: column; gap: 15px; }
|
||||||
|
.game-stats { flex-direction: column; gap: 15px; align-items: stretch; }
|
||||||
|
.bet-controls { justify-content: center; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="table" role="application" aria-label="Blackjack tanpa iklan">
|
|
||||||
|
<div class="table" role="application" aria-label="Blackjack Game">
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1> Blackjack [21] </h1>
|
<div class="header-top">
|
||||||
<div class="controls">
|
<h1>Blackjack [21]</h1>
|
||||||
<div style="display:flex;gap:12px;align-items:center;margin-bottom:8px;">
|
<div class="user-actions">
|
||||||
<div>Signed in as: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></div>
|
<div class="user-badge">
|
||||||
<a href="topup.php" style="text-decoration:none;padding:6px 10px;background:#3b82f6;color:#fff;border-radius:6px;">Top Up</a>
|
User: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
||||||
<a href="logout.php" style="text-decoration:none;padding:6px 10px;background:#ef4444;color:#fff;border-radius:6px;">Logout</a>
|
</div>
|
||||||
|
<a href="topup.php" class="btn-link btn-topup">Top Up</a>
|
||||||
|
<a href="logout.php" class="btn-link btn-logout">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
</div>
|
||||||
<div class="chip">Bank: <span id="balance"><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></span></div>
|
|
||||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
<div class="game-stats">
|
||||||
|
<div class="stat-group">
|
||||||
|
<div class="stat-item">
|
||||||
|
<span class="stat-label">Bank</span>
|
||||||
|
<span class="stat-value" id="balance"><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></span>
|
||||||
|
</div>
|
||||||
|
<div class="stat-item">
|
||||||
|
<span class="stat-label">Taruhan Saat Ini</span>
|
||||||
|
<span class="stat-value" id="current-bet">0</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bet">
|
|
||||||
<input id="bet-input" type="number" min="1" value="50" />
|
<div class="bet-controls">
|
||||||
<button id="bet-btn">Pasang Taruhan</button>
|
<input id="bet-input" type="number" min="1" value="50" placeholder="Bet" />
|
||||||
<button id="new-round" class="secondary"> Reset </button>
|
<button id="bet-btn" class="btn-game btn-bet">Pasang Taruhan</button>
|
||||||
|
<button id="new-round" class="btn-game btn-secondary">Reset</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div class="board" id="dealer-area">
|
<!-- Dealer Area -->
|
||||||
<div class="section-title">Dealer</div>
|
<div class="board-section" id="dealer-area">
|
||||||
|
<div class="section-title">Dealer's Hand</div>
|
||||||
<div class="hand" id="dealer-hand"></div>
|
<div class="hand" id="dealer-hand"></div>
|
||||||
<div class="values" id="dealer-value"></div>
|
<div class="values" id="dealer-value"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="board" id="player-area">
|
<!-- Player Area -->
|
||||||
<div class="section-title">Pemain</div>
|
<div class="board-section" id="player-area">
|
||||||
|
<div class="section-title">Your Hand</div>
|
||||||
<div class="hand" id="player-hand"></div>
|
<div class="hand" id="player-hand"></div>
|
||||||
<div class="values" id="player-value"></div>
|
<div class="values" id="player-value"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="actions" id="action-buttons">
|
<!-- Action Area -->
|
||||||
<button id="hit">Hit</button>
|
<div class="actions-container">
|
||||||
<button id="stand">Stand</button>
|
<div id="message"></div>
|
||||||
<button id="double">Double</button>
|
<div class="action-buttons" id="action-buttons">
|
||||||
|
<button id="hit" class="btn-game btn-hit">Hit</button>
|
||||||
|
<button id="stand" class="btn-game btn-stand">Stand</button>
|
||||||
|
<button id="double" class="btn-game btn-double">Double</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="message" id="message"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
OCA GameHub - <code> Blackjack_[21] - </code> Semoga menang bosq
|
OCA GameHub © 2025 - <span style="opacity:0.6">Semoga menang bosq!</span>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="ody git.js"></script>
|
<script src="ody git.js?v=<?php echo time(); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
213
ody git.js
213
ody git.js
@ -1,12 +1,12 @@
|
|||||||
// SET MESSAGE (WIN/LOSE)
|
// SET MESSAGE (WIN/LOSE)
|
||||||
function setMessage(text, status){
|
function setMessage(text, status) {
|
||||||
messageEl.textContent = text;
|
messageEl.textContent = text;
|
||||||
messageEl.className = status; // 'win', 'lose', atau '' (tie)
|
messageEl.className = status; // 'win', 'lose', atau '' (tie)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple Blackjack implementation
|
// Simple Blackjack implementation
|
||||||
const SUITS = ['♠','♥','♦','♣'];
|
const SUITS = ['♠', '♥', '♦', '♣'];
|
||||||
const RANKS = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
|
const RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
|
||||||
|
|
||||||
// DOM
|
// DOM
|
||||||
const dealerHandEl = document.getElementById('dealer-hand');
|
const dealerHandEl = document.getElementById('dealer-hand');
|
||||||
@ -27,64 +27,65 @@ let deck = [];
|
|||||||
let dealer = [];
|
let dealer = [];
|
||||||
let player = [];
|
let player = [];
|
||||||
let dealerHidden = true;
|
let dealerHidden = true;
|
||||||
let balance = 1000;
|
// Initialize balance from the HTML (PHP output)
|
||||||
|
let balance = parseInt(document.getElementById('balance').innerText.replace(/[^\d]/g, '')) || 0;
|
||||||
let currentBet = 0;
|
let currentBet = 0;
|
||||||
let inRound = false;
|
let inRound = false;
|
||||||
|
|
||||||
function makeDeck(){
|
function makeDeck() {
|
||||||
deck = [];
|
deck = [];
|
||||||
for(const s of SUITS){
|
for (const s of SUITS) {
|
||||||
for(const r of RANKS){
|
for (const r of RANKS) {
|
||||||
deck.push({suit:s,rank:r});
|
deck.push({ suit: s, rank: r });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shuffle(){
|
function shuffle() {
|
||||||
for(let i=deck.length-1;i>0;i--){
|
for (let i = deck.length - 1; i > 0; i--) {
|
||||||
const j = Math.floor(Math.random()*(i+1));
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
[deck[i],deck[j]] = [deck[j],deck[i]];
|
[deck[i], deck[j]] = [deck[j], deck[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cardValue(card){
|
function cardValue(card) {
|
||||||
const r = card.rank;
|
const r = card.rank;
|
||||||
if(r==='A') return [1,11];
|
if (r === 'A') return [1, 11];
|
||||||
if(['J','Q','K'].includes(r)) return [10];
|
if (['J', 'Q', 'K'].includes(r)) return [10];
|
||||||
return [parseInt(r,10)];
|
return [parseInt(r, 10)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function handValues(hand){
|
function handValues(hand) {
|
||||||
let totals = [0];
|
let totals = [0];
|
||||||
for(const c of hand){
|
for (const c of hand) {
|
||||||
const vals = cardValue(c);
|
const vals = cardValue(c);
|
||||||
const newTotals = [];
|
const newTotals = [];
|
||||||
for(const t of totals){
|
for (const t of totals) {
|
||||||
for(const v of vals){ newTotals.push(t+v); }
|
for (const v of vals) { newTotals.push(t + v); }
|
||||||
}
|
}
|
||||||
totals = Array.from(new Set(newTotals));
|
totals = Array.from(new Set(newTotals));
|
||||||
}
|
}
|
||||||
const valid = totals.filter(t=>t<=21);
|
const valid = totals.filter(t => t <= 21);
|
||||||
if(valid.length) return Math.max(...valid);
|
if (valid.length) return Math.max(...valid);
|
||||||
return Math.min(...totals);
|
return Math.min(...totals);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderHand(el,hand,hideFirst=false){
|
function renderHand(el, hand, hideFirst = false) {
|
||||||
el.innerHTML='';
|
el.innerHTML = '';
|
||||||
hand.forEach((c,i)=>{
|
hand.forEach((c, i) => {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.className='card'+(c.suit==='♥'||c.suit==='♦'?' red':'');
|
div.className = 'card' + (c.suit === '♥' || c.suit === '♦' ? ' red' : '');
|
||||||
|
|
||||||
if(hideFirst && i===0){
|
if (hideFirst && i === 0) {
|
||||||
div.className='card back';
|
div.className = 'card back';
|
||||||
div.textContent='HIDEN';
|
div.textContent = 'HIDEN';
|
||||||
} else {
|
} else {
|
||||||
const top = document.createElement('div');
|
const top = document.createElement('div');
|
||||||
top.textContent = c.rank + ' ' + c.suit;
|
top.textContent = c.rank + ' ' + c.suit;
|
||||||
const bot = document.createElement('div');
|
const bot = document.createElement('div');
|
||||||
bot.style.alignSelf='flex-end';
|
bot.style.alignSelf = 'flex-end';
|
||||||
bot.textContent = c.rank + ' ' + c.suit;
|
bot.textContent = c.rank + ' ' + c.suit;
|
||||||
div.appendChild(top);
|
div.appendChild(top);
|
||||||
div.appendChild(bot);
|
div.appendChild(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,25 +93,25 @@ function renderHand(el,hand,hideFirst=false){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateUI(){
|
function updateUI() {
|
||||||
renderHand(dealerHandEl,dealer,dealerHidden);
|
renderHand(dealerHandEl, dealer, dealerHidden);
|
||||||
renderHand(playerHandEl,player,false);
|
renderHand(playerHandEl, player, false);
|
||||||
dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: '+handValues(dealer);
|
dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: ' + handValues(dealer);
|
||||||
playerValueEl.textContent = 'Nilai: '+handValues(player);
|
playerValueEl.textContent = 'Nilai: ' + handValues(player);
|
||||||
balanceEl.textContent = balance;
|
balanceEl.textContent = balance.toLocaleString('id-ID'); // Format with dots
|
||||||
currentBetEl.textContent = currentBet;
|
currentBetEl.textContent = currentBet.toLocaleString('id-ID');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRound(){
|
function startRound() {
|
||||||
if(inRound) return;
|
if (inRound) return;
|
||||||
|
|
||||||
const bet = Number(betInput.value) || 0;
|
const bet = Number(betInput.value) || 0;
|
||||||
if(bet <=0 || bet > balance){ alert(' BANK TIDAK CUKUP! '); return; }
|
if (bet <= 0 || bet > balance) { alert(' BANK TIDAK CUKUP! '); return; }
|
||||||
|
|
||||||
currentBet = bet;
|
currentBet = bet;
|
||||||
balance -= bet;
|
balance -= bet;
|
||||||
inRound=true;
|
inRound = true;
|
||||||
dealerHidden=true;
|
dealerHidden = true;
|
||||||
|
|
||||||
setMessage('', ''); // RESET MESSAGE
|
setMessage('', ''); // RESET MESSAGE
|
||||||
|
|
||||||
@ -121,12 +122,12 @@ function startRound(){
|
|||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
// NATURAL BLACKJACK
|
// NATURAL BLACKJACK
|
||||||
if(handValues(player)===21){
|
if (handValues(player) === 21) {
|
||||||
dealerHidden=false;
|
dealerHidden = false;
|
||||||
updateUI();
|
updateUI();
|
||||||
const dealerVal = handValues(dealer);
|
const dealerVal = handValues(dealer);
|
||||||
|
|
||||||
if(dealerVal===21){
|
if (dealerVal === 21) {
|
||||||
balance += currentBet;
|
balance += currentBet;
|
||||||
setMessage('Tie (seri).', '');
|
setMessage('Tie (seri).', '');
|
||||||
} else {
|
} else {
|
||||||
@ -135,44 +136,44 @@ function startRound(){
|
|||||||
setMessage('Blackjack! You Win!', 'win');
|
setMessage('Blackjack! You Win!', 'win');
|
||||||
}
|
}
|
||||||
|
|
||||||
inRound=false;
|
inRound = false;
|
||||||
currentBet=0;
|
currentBet = 0;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerHit(){
|
function playerHit() {
|
||||||
if(!inRound) return;
|
if (!inRound) return;
|
||||||
|
|
||||||
player.push(deck.pop());
|
player.push(deck.pop());
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
if(handValues(player) > 21){
|
if (handValues(player) > 21) {
|
||||||
dealerHidden=false;
|
dealerHidden = false;
|
||||||
setMessage('Bust! You Lose!', 'lose');
|
setMessage('Bust! You Lose!', 'lose');
|
||||||
inRound=false;
|
inRound = false;
|
||||||
currentBet=0;
|
currentBet = 0;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerStand(){
|
function playerStand() {
|
||||||
if(!inRound) return;
|
if (!inRound) return;
|
||||||
|
|
||||||
dealerHidden=false;
|
dealerHidden = false;
|
||||||
|
|
||||||
while(handValues(dealer)<17){
|
while (handValues(dealer) < 17) {
|
||||||
dealer.push(deck.pop());
|
dealer.push(deck.pop());
|
||||||
}
|
}
|
||||||
|
|
||||||
const pv = handValues(player);
|
const pv = handValues(player);
|
||||||
const dv = handValues(dealer);
|
const dv = handValues(dealer);
|
||||||
|
|
||||||
if(dv>21 || pv>dv){
|
if (dv > 21 || pv > dv) {
|
||||||
balance += currentBet*2;
|
balance += currentBet * 2;
|
||||||
setMessage('You Win!', 'win');
|
setMessage('You Win!', 'win');
|
||||||
|
|
||||||
} else if(pv===dv){
|
} else if (pv === dv) {
|
||||||
balance += currentBet;
|
balance += currentBet;
|
||||||
setMessage('Tie (seri).', '');
|
setMessage('Tie (seri).', '');
|
||||||
|
|
||||||
@ -180,26 +181,26 @@ function playerStand(){
|
|||||||
setMessage('You Lose!', 'lose');
|
setMessage('You Lose!', 'lose');
|
||||||
}
|
}
|
||||||
|
|
||||||
inRound=false;
|
inRound = false;
|
||||||
currentBet=0;
|
currentBet = 0;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerDouble(){
|
function playerDouble() {
|
||||||
if(!inRound) return;
|
if (!inRound) return;
|
||||||
if(balance < currentBet){ alert('Bank tidak cukup untuk double.'); return; }
|
if (balance < currentBet) { alert('Bank tidak cukup untuk double.'); return; }
|
||||||
|
|
||||||
balance -= currentBet;
|
balance -= currentBet;
|
||||||
currentBet *= 2;
|
currentBet *= 2;
|
||||||
|
|
||||||
player.push(deck.pop());
|
player.push(deck.pop());
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
if(handValues(player)>21){
|
if (handValues(player) > 21) {
|
||||||
dealerHidden=false;
|
dealerHidden = false;
|
||||||
setMessage('Bust! You Lose!', 'lose');
|
setMessage('Bust! You Lose!', 'lose');
|
||||||
inRound=false;
|
inRound = false;
|
||||||
currentBet=0;
|
currentBet = 0;
|
||||||
updateUI();
|
updateUI();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -213,25 +214,25 @@ hitBtn.addEventListener('click', playerHit);
|
|||||||
standBtn.addEventListener('click', playerStand);
|
standBtn.addEventListener('click', playerStand);
|
||||||
doubleBtn.addEventListener('click', playerDouble);
|
doubleBtn.addEventListener('click', playerDouble);
|
||||||
|
|
||||||
newRoundBtn.addEventListener('click', ()=>{
|
newRoundBtn.addEventListener('click', () => {
|
||||||
if(inRound && !confirm('Masih dalam ronde. Reset?')) return;
|
if (inRound && !confirm('Masih dalam ronde. Reset?')) return;
|
||||||
balance = 1000;
|
// Do NOT reset balance to 1000. Balance persists.
|
||||||
currentBet=0;
|
currentBet = 0;
|
||||||
inRound=false;
|
inRound = false;
|
||||||
dealer=[];
|
dealer = [];
|
||||||
player=[];
|
player = [];
|
||||||
deck=[];
|
deck = [];
|
||||||
dealerHidden=true;
|
dealerHidden = true;
|
||||||
setMessage('Bank di-reset.', '');
|
setMessage('Meja di-reset.', '');
|
||||||
updateUI();
|
updateUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
// KEYBOARD
|
// KEYBOARD
|
||||||
window.addEventListener('keydown', e=>{
|
window.addEventListener('keydown', e => {
|
||||||
if(e.key==='h') playerHit();
|
if (e.key === 'h') playerHit();
|
||||||
if(e.key==='s') playerStand();
|
if (e.key === 's') playerStand();
|
||||||
if(e.key==='d') playerDouble();
|
if (e.key === 'd') playerDouble();
|
||||||
if(e.key==='Enter') startRound();
|
if (e.key === 'Enter') startRound();
|
||||||
});
|
});
|
||||||
|
|
||||||
updateUI();
|
updateUI();
|
||||||
@ -265,35 +266,35 @@ function hideTopUpModal() {
|
|||||||
// Fungsi untuk memproses top up
|
// Fungsi untuk memproses top up
|
||||||
function processTopUp() {
|
function processTopUp() {
|
||||||
const amount = Number(topUpInput.value) || 0;
|
const amount = Number(topUpInput.value) || 0;
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
alert('Masukkan jumlah top up yang valid!');
|
alert('Masukkan jumlah top up yang valid!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amount > 1000000) {
|
if (amount > 1000000) {
|
||||||
alert('Maksimal top up adalah 1.000.000!');
|
alert('Maksimal top up adalah 1.000.000!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulasi proses top up (dalam implementasi nyata, ini akan terhubung ke payment gateway)
|
// Simulasi proses top up (dalam implementasi nyata, ini akan terhubung ke payment gateway)
|
||||||
balance += amount;
|
balance += amount;
|
||||||
topUpAmount += amount;
|
topUpAmount += amount;
|
||||||
|
|
||||||
// Tambahkan ke riwayat top up
|
// Tambahkan ke riwayat top up
|
||||||
topUpHistory.push({
|
topUpHistory.push({
|
||||||
amount: amount,
|
amount: amount,
|
||||||
date: new Date().toLocaleString('id-ID'),
|
date: new Date().toLocaleString('id-ID'),
|
||||||
balanceAfter: balance
|
balanceAfter: balance
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
updateUI();
|
updateUI();
|
||||||
updateTopUpHistory();
|
updateTopUpHistory();
|
||||||
|
|
||||||
// Tampilkan pesan sukses
|
// Tampilkan pesan sukses
|
||||||
setMessage(`Top up berhasil! +${amount.toLocaleString('id-ID')}`, 'win');
|
setMessage(`Top up berhasil! +${amount.toLocaleString('id-ID')}`, 'win');
|
||||||
|
|
||||||
// Sembunyikan modal
|
// Sembunyikan modal
|
||||||
hideTopUpModal();
|
hideTopUpModal();
|
||||||
}
|
}
|
||||||
@ -301,17 +302,17 @@ function processTopUp() {
|
|||||||
// Fungsi untuk memperbarui riwayat top up
|
// Fungsi untuk memperbarui riwayat top up
|
||||||
function updateTopUpHistory() {
|
function updateTopUpHistory() {
|
||||||
if (!topUpHistoryEl) return;
|
if (!topUpHistoryEl) return;
|
||||||
|
|
||||||
topUpHistoryEl.innerHTML = '';
|
topUpHistoryEl.innerHTML = '';
|
||||||
|
|
||||||
if (topUpHistory.length === 0) {
|
if (topUpHistory.length === 0) {
|
||||||
topUpHistoryEl.innerHTML = '<p class="no-history">Belum ada riwayat top up</p>';
|
topUpHistoryEl.innerHTML = '<p class="no-history">Belum ada riwayat top up</p>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tampilkan maksimal 5 riwayat terbaru
|
// Tampilkan maksimal 5 riwayat terbaru
|
||||||
const recentHistory = topUpHistory.slice(-5).reverse();
|
const recentHistory = topUpHistory.slice(-5).reverse();
|
||||||
|
|
||||||
recentHistory.forEach(record => {
|
recentHistory.forEach(record => {
|
||||||
const historyItem = document.createElement('div');
|
const historyItem = document.createElement('div');
|
||||||
historyItem.className = 'history-item';
|
historyItem.className = 'history-item';
|
||||||
@ -361,22 +362,22 @@ window.addEventListener('keydown', e => {
|
|||||||
|
|
||||||
// Modifikasi fungsi updateUI untuk menampilkan informasi top up
|
// Modifikasi fungsi updateUI untuk menampilkan informasi top up
|
||||||
const originalUpdateUI = updateUI;
|
const originalUpdateUI = updateUI;
|
||||||
updateUI = function() {
|
updateUI = function () {
|
||||||
originalUpdateUI();` []`
|
originalUpdateUI(); ` []`
|
||||||
updateTopUpBalance();
|
updateTopUpBalance();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modifikasi fungsi newRound untuk reset saldo yang tidak mempengaruhi riwayat top up
|
// Modifikasi fungsi newRound untuk reset saldo yang tidak mempengaruhi riwayat top up
|
||||||
const originalNewRound = newRoundBtn.onclick;
|
const originalNewRound = newRoundBtn.onclick;
|
||||||
newRoundBtn.onclick = function() {
|
newRoundBtn.onclick = function () {
|
||||||
if (inRound && !confirm('Masih dalam ronde. Reset?')) return;
|
if (inRound && !confirm('Masih dalam ronde. Reset?')) return;
|
||||||
|
|
||||||
// Reset saldo tapi pertahankan riwayat top up
|
// Reset saldo tapi pertahankan riwayat top up
|
||||||
const currentTopUpAmount = topUpAmount;
|
const currentTopUpAmount = topUpAmount;
|
||||||
balance = 1000 + currentTopUpAmount;
|
balance = 1000 + currentTopUpAmount;
|
||||||
currentBet = 0;
|
currentBet = 0;
|
||||||
inRound = false;
|
inRound = false;
|
||||||
dealer = [];
|
dealer = [];
|
||||||
player = [];
|
player = [];
|
||||||
deck = [];
|
deck = [];
|
||||||
dealerHidden = true;
|
dealerHidden = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user