Akademi Cilik
Ustazah Najwa Annuriy
Mari Belajar Mengaji, Solat & Hadis Bersama Ustazah!
Mari Belajar Mengaji, Solat & Hadis Bersama Ustazah!
Setiap gambarajah dilengkapi dengan kedudukan tepat dan audio bacaan.
<!DOCTYPE html>
<html lang="ms">
<head>
<meta charset="UTF-8">
<title>Dam Ular Kanak-Kanak</title>
<style>
/* Gaya Visual Game */
body { font-family: 'Arial', sans-serif; display: flex; flex-direction: column; align-items: center; background-color: #f0f8ff; }
#board {
display: grid;
grid-template-columns: repeat(10, 50px);
grid-template-rows: repeat(10, 50px);
border: 5px solid #333;
background-color: #fff;
}
.cell {
width: 50px; height: 50px; border: 1px solid #ddd;
display: flex; align-items: center; justify-content: center; font-size: 12px; position: relative;
}
#player {
width: 30px; height: 30px; background-color: red; border-radius: 50%;
position: absolute; transition: all 0.5s ease; z-index: 10;
}
.controls { margin-top: 20px; }
button { padding: 10px 20px; font-size: 16px; cursor: pointer; background-color: #4CAF50; color: white; border: none; border-radius: 5px; }
.info { margin-top: 10px; font-weight: bold; }
</style>
</head>
<body>
<h1>🐍 Dam Ular Cilik 🪜</h1>
<div id="board">
<div id="player"></div>
</div>
<div class="controls">
<button onclick="rollDice()">Baling Dadu 🎲</button>
<div class="info" id="status">Tekan butang untuk mula!</div>
</div>
<script>
const board = document.getElementById('board');
const playerElement = document.getElementById('player');
const statusText = document.getElementById('status');
let playerPos = 1;
// Definisi Ular dan Tangga {mula: tamat}
const snakesAndLadders = {
3: 22, // Tangga
5: 8, // Tangga
11: 26, // Tangga
20: 29, // Tangga
17: 4, // Ular
19: 7, // Ular
27: 1, // Ular
21: 9 // Ular
};
// Bina Papan 10x10
function createBoard() {
for (let i = 100; i >= 1; i--) {
const cell = document.createElement('div');
cell.className = 'cell';
cell.id = 'cell-' + i;
cell.innerText = i;
// Warna khas untuk petak ular/tangga
if (snakesAndLadders[i] > i) cell.style.backgroundColor = "#d4edda"; // Tangga
if (snakesAndLadders[i] < i) cell.style.backgroundColor = "#f8d7da"; // Ular
board.appendChild(cell);
}
}
// Update Posisi Pemain di Skrin
function updateUI() {
const targetCell = document.getElementById('cell-' + playerPos);
const rect = targetCell.getBoundingClientRect();
const boardRect = board.getBoundingClientRect();
playerElement.style.left = (targetCell.offsetLeft + 10) + 'px';
playerElement.style.top = (targetCell.offsetTop + 10) + 'px';
}
// Fungsi Baling Dadu
function rollDice() {
const dice = Math.floor(Math.random() * 6) + 1;
statusText.innerText = "Anda dapat: " + dice;
playerPos += dice;
if (playerPos >= 100) {
playerPos = 100;
statusText.innerText = "TAHNIAH! ANDA MENANG! 🎉";
}
// Semak Ular atau Tangga
if (snakesAndLadders[playerPos]) {
const oldPos = playerPos;
playerPos = snakesAndLadders[playerPos];
statusText.innerText += (playerPos > oldPos) ? " | Wah, naik tangga! 🪜" : " | Alamak, kena telan ular! 🐍";
}
updateUI();
}
createBoard();
updateUI();
</script>
</body>
</html>