Skip to content
View 7895352194's full-sized avatar

Block or report 7895352194

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
7895352194/README.md

!DOCTYPE html>

<title>Memory Matching Game</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
    #game-board {
        display: grid;
        grid-template-columns: repeat(4, 100px);
        grid-gap: 10px;
    }

    .card {
        width: 100px;
        height: 100px;
        background-color: #f0f0f0;
        border: 1px solid #ccc;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 32px;
        cursor: pointer;
        border-radius: 8px;
    }

    .card.flipped {
        background-color: #fff;
        color: #333;
    }

    #score {
        font-size: 24px;
        margin-bottom: 20px;
    }

    #restart {
        padding: 10px 20px;
        background-color: #4CAF50;
        color: white;
        border: none;
        cursor: pointer;
        border-radius: 5px;
        font-size: 16px;
    }

    #restart:hover {
        background-color: #45a049;
    }
</style>
<div>
    <div id="score">Score: 0</div>
    <div id="game-board"></div>
    <button id="restart">Restart</button>
</div>

<script>
    const board = document.getElementById('game-board');
    const scoreDisplay = document.getElementById('score');
    const restartButton = document.getElementById('restart');
    let cards = [];
    let flippedCards = [];
    let score = 0;

    // List of symbols (or numbers/letters) for the cards
    const symbols = ['πŸ–€', '❀️', '🩡', '🩷', '🀎', 'πŸ’œ', 'πŸ’š', '❀️‍πŸ”₯'];

    // Double the array to create pairs
    let cardSymbols = [...symbols, ...symbols];
    
    // Shuffle function
    function shuffle(array) {
        for (let i = array.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [array[i], array[j]] = [array[j], array[i]]; // Swap elements
        }
    }

    // Create the game board with cards
    function createBoard() {
        shuffle(cardSymbols);
        board.innerHTML = '';

        cardSymbols.forEach((symbol, index) => {
            const card = document.createElement('div');
            card.classList.add('card');
            card.dataset.symbol = symbol;
            card.dataset.index = index;

            card.addEventListener('click', flipCard);

            board.appendChild(card);
            cards.push(card);
        });
    }

    // Flip a card
    function flipCard(event) {
        const card = event.target;

        // Don't flip the card if it's already flipped or matched
        if (card.classList.contains('flipped') || flippedCards.length === 2) return;

        card.textContent = card.dataset.symbol;
        card.classList.add('flipped');
        flippedCards.push(card);

        if (flippedCards.length === 2) {
            checkMatch();
        }
    }

    // Check if two flipped cards match
    function checkMatch() {
        const [card1, card2] = flippedCards;

        if (card1.dataset.symbol === card2.dataset.symbol) {
            score++;
            scoreDisplay.textContent = `Score: ${score}`;
            flippedCards = [];
            if (score === symbols.length) {
                setTimeout(() => {
                    alert('You Win! Congratulations!');
                    resetGame();
                }, 500);
            }
        } else {
            setTimeout(() => {
                card1.classList.remove('flipped');
                card2.classList.remove('flipped');
                card1.textContent = '';
                card2.textContent = '';
                flippedCards = [];
            }, 1000);
        }
    }

    // Reset the game
    function resetGame() {
        score = 0;
        scoreDisplay.textContent = `Score: ${score}`;
        flippedCards = [];
        cards = [];
        cardSymbols = [...symbols, ...symbols];
        createBoard();
    }

    // Start the game
    restartButton.addEventListener('click', resetGame);
    resetGame(); // Start the game on page load
</script>

Popular repositories Loading

  1. By-RDX-PRAJAPATI By-RDX-PRAJAPATI Public

    1

  2. 7895352194 7895352194 Public

    Config files for my GitHub profile.

  3. Phishing Phishing Public

    Vvvvvv

  4. PARADOXX- PARADOXX- Public

    ls

  5. RDX-HUG-X RDX-HUG-X Public

  6. Low-price- Low-price- Public

    Online shopping