ok
This commit is contained in:
parent
c17ddbd203
commit
38914b6389
18
html.php
18
html.php
@ -28,6 +28,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['bank_method'])) {
|
||||
$topup_success = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle balance update from game
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_balance'])) {
|
||||
$new_balance = (int)$_POST['update_balance'];
|
||||
if ($new_balance >= 0) {
|
||||
$_SESSION['balance'] = $new_balance;
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['status' => 'success', 'balance' => $_SESSION['balance']]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="id">
|
||||
@ -371,12 +382,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['bank_method'])) {
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="ody git.js"></script>
|
||||
<script>
|
||||
// Initialize balance from server
|
||||
// Initialize balance from server BEFORE loading game script
|
||||
const serverBalance = <?php echo (int)$_SESSION['balance']; ?>;
|
||||
let gameBalance = serverBalance;
|
||||
|
||||
</script>
|
||||
<script src="ody git.js"></script>
|
||||
<script>
|
||||
// Update display on load
|
||||
function updateBalanceDisplay() {
|
||||
document.getElementById('balance').textContent = gameBalance.toLocaleString('id-ID');
|
||||
|
||||
29
ody git.js
29
ody git.js
@ -27,10 +27,17 @@ let deck = [];
|
||||
let dealer = [];
|
||||
let player = [];
|
||||
let dealerHidden = true;
|
||||
let balance = 1000;
|
||||
let balance = 0; // Will be initialized from server
|
||||
let currentBet = 0;
|
||||
let inRound = false;
|
||||
|
||||
// Initialize balance from global gameBalance (set in html.php)
|
||||
if (typeof gameBalance !== 'undefined') {
|
||||
balance = gameBalance;
|
||||
} else {
|
||||
balance = 1000; // Fallback
|
||||
}
|
||||
|
||||
function makeDeck(){
|
||||
deck = [];
|
||||
for(const s of SUITS){
|
||||
@ -97,8 +104,20 @@ function updateUI(){
|
||||
renderHand(playerHandEl,player,false);
|
||||
dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: '+handValues(dealer);
|
||||
playerValueEl.textContent = 'Nilai: '+handValues(player);
|
||||
balanceEl.textContent = balance;
|
||||
currentBetEl.textContent = currentBet;
|
||||
balanceEl.textContent = balance.toLocaleString('id-ID');
|
||||
currentBetEl.textContent = currentBet.toLocaleString('id-ID');
|
||||
}
|
||||
|
||||
// Function to update balance on server
|
||||
function updateBalanceOnServer() {
|
||||
fetch('html.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'update_balance=' + balance
|
||||
})
|
||||
.catch(err => console.log('Balance update sent'));
|
||||
}
|
||||
|
||||
function startRound(){
|
||||
@ -138,6 +157,7 @@ function startRound(){
|
||||
inRound=false;
|
||||
currentBet=0;
|
||||
updateUI();
|
||||
updateBalanceOnServer();
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,6 +173,7 @@ function playerHit(){
|
||||
inRound=false;
|
||||
currentBet=0;
|
||||
updateUI();
|
||||
updateBalanceOnServer();
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,6 +204,7 @@ function playerStand(){
|
||||
inRound=false;
|
||||
currentBet=0;
|
||||
updateUI();
|
||||
updateBalanceOnServer();
|
||||
}
|
||||
|
||||
function playerDouble(){
|
||||
@ -201,6 +223,7 @@ function playerDouble(){
|
||||
inRound=false;
|
||||
currentBet=0;
|
||||
updateUI();
|
||||
updateBalanceOnServer();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user