🎮ArcadeLab

Block Bali Blast - Khusus Kamu!

by PlasmaRanger79
182 lines6.2 KB
▶ Play
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Block Bali Blast - Khusus Kamu!</title>
    <style>
        body {
            background: url('https://images.unsplash.com/photo-1583328558452-023c19d82848?q=80&w=1000&auto=format&fit=crop') no-repeat center center fixed;
            background-size: cover;
            font-family: Arial, sans-serif;
            text-align: center;
            color: white;
            margin: 0;
            padding: 20px;
        }
        .game-container {
            display: inline-block;
            background-color: rgba(0, 0, 0, 0.7);
            padding: 20px;
            border-radius: 15px;
            border: 3px solid #ffd700;
        }
        #game-board {
            display: grid;
            grid-template-columns: repeat(8, 50px);
            grid-gap: 5px;
            margin: 20px 0;
        }
        .block {
            width: 50px;
            height: 50px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
        }
        .score {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="game-container">
        <h1>Block Bali Blast 🇮🇩</h1>
        <div class="score">Skor: <span id="score">0</span></div>
        <div id="game-board"></div>
    </div>

    <script>
        const boardSize = 8;
        const colors = ['#e74c3c', '#f1c40f', '#2ecc71', '#3498db', '#8e44ad'];
        const symbols = ['🌸', '⚙️', '🍃', '🌊', '🐦'];
        let board = [];
        let score = 0;
        let selectedBlock = null;

        function initBoard() {
            const gameBoard = document.getElementById('game-board');
            gameBoard.innerHTML = '';
            board = [];
            for (let i = 0; i < boardSize; i++) {
                board[i] = [];
                for (let j = 0; j < boardSize; j++) {
                    const type = Math.floor(Math.random() * colors.length);
                    board[i][j] = { type, matched: false };
                    const block = document.createElement('div');
                    block.classList.add('block');
                    block.style.backgroundColor = colors[type];
                    block.textContent = symbols[type];
                    block.dataset.row = i;
                    block.dataset.col = j;
                    block.addEventListener('click', selectBlock);
                    gameBoard.appendChild(block);
                }
            }
        }

        function selectBlock(e) {
            const row = parseInt(e.target.dataset.row);
            const col = parseInt(e.target.dataset.col);
            if (selectedBlock) {
                swapBlocks(selectedBlock.row, selectedBlock.col, row, col);
                if (checkMatches()) {
                    updateScore();
                    removeMatchedBlocks();
                    fillEmptySpaces();
                    selectedBlock = null;
                } else {
                    swapBlocks(selectedBlock.row, selectedBlock.col, row, col);
                    selectedBlock = null;
                }
            } else {
                selectedBlock = { row, col };
                e.target.style.border = '2px solid white';
            }
        }

        function swapBlocks(r1, c1, r2, c2) {
            const temp = board[r1][c1];
            board[r1][c1] = board[r2][c2];
            board[r2][c2] = temp;
            updateBoardVisual();
        }

        function updateBoardVisual() {
            const blocks = document.querySelectorAll('.block');
            blocks.forEach(block => {
                const row = parseInt(block.dataset.row);
                const col = parseInt(block.dataset.col);
                const type = board[row][col].type;
                block.style.backgroundColor = colors[type];
                block.textContent = symbols[type];
                block.style.border = 'none';
            });
        }

        function checkMatches() {
            let hasMatch = false;
            for (let i = 0; i < boardSize; i++) {
                for (let j = 0; j < boardSize; j++) {
                    if (j <= boardSize - 3 && 
                        board[i][j].type === board[i][j+1].type && 
                        board[i][j].type === board[i][j+2].type) {
                        board[i][j].matched = true;
                        board[i][j+1].matched = true;
                        board[i][j+2].matched = true;
                        hasMatch = true;
                    }
                    if (i <= boardSize - 3 && 
                        board[i][j].type === board[i+1][j].type && 
                        board[i][j].type === board[i+2][j].type) {
                        board[i][j].matched = true;
                        board[i+1][j].matched = true;
                        board[i+2][j].matched = true;
                        hasMatch = true;
                    }
                }
            }
            return hasMatch;
        }

        function removeMatchedBlocks() {
            for (let i = 0; i < boardSize; i++) {
                for (let j = 0; j < boardSize; j++) {
                    if (board[i][j].matched) {
                        score += 10;
                        board[i][j] = { type: Math.floor(Math.random() * colors.length), matched: false };
                    }
                }
            }
            updateBoardVisual();
        }

        function fillEmptySpaces() {
            for (let j = 0; j < boardSize; j++) {
                let emptyRow = boardSize - 1;
                for (let i = boardSize - 1; i >= 0; i--) {
                    if (!board[i][j].matched) {
                        const temp = board[i][j];
                        board[i][j] = board[emptyRow][j];
                        board[emptyRow][j] = temp;
                        emptyRow--;
                    }
                }
            }
            updateBoardVisual();
        }

        function updateScore() {
            document.getElementById('score').textContent = score;
        }

        initBoard();
    </script>
</body>
</html>

Game Source: Block Bali Blast - Khusus Kamu!

Creator: PlasmaRanger79

Libraries: none

Complexity: moderate (182 lines, 6.2 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: block-bali-blast-khusus-kamu-plasmaranger79" to link back to the original. Then publish at arcadelab.ai/publish.