OneCompiler

Müzikli şans oyunu

1640
<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Mevlüt'ün Mekanı - Şansını Dene</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 0; padding: 0; background-color: #2c3e50; color: white; } header { background-color: #e74c3c; padding: 20px; font-size: 24px; font-weight: bold; } main { padding: 20px; } .game-section { margin: 20px auto; padding: 20px; background-color: #34495e; border-radius: 10px; width: 90%; max-width: 400px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); } button { background-color: #e67e22; color: white; border: none; padding: 10px 20px; font-size: 18px; border-radius: 5px; cursor: pointer; } button:hover { background-color: #d35400; } .result { font-size: 20px; margin-top: 20px; } .score { font-size: 18px; margin-top: 10px; } footer { margin-top: 30px; background-color: #34495e; padding: 10px; } </style> </head> <body> <header> Mevlüt'ün Mekanı - Şansını Dene! </header> <main> <section class="game-section"> <h2>Şansınızı Test Edin!</h2> <p>1 ile 10 arasında rastgele bir sayı seçiliyor. Bakalım kazanacak mısınız?</p> <button onclick="playGame()">Şansımı Dene</button> <div class="result" id="result"></div> <div class="score" id="score">Başlangıç Parası: 100 TL</div> <audio id="bg-music" loop> <source src="https://www.bensound.com/bensound-music/bensound-littleidea.mp3" type="audio/mp3"> Tarayıcınız sesi desteklemiyor. </audio> <button onclick="toggleMusic()">🎵 Müzik Aç/Kapat</button> </section> <section class="history-section"> <h3>Oyun Geçmişi</h3> <ul id="history"></ul> </section> </main> <footer> © 2024 Mevlüt'ün Mekanı. Tüm hakları saklıdır. </footer> <script> let balance = 100; // Başlangıç parası let history = []; // Oyun geçmişi const music = document.getElementById("bg-music"); let musicPlaying = false;
    function playGame() {
        const randomNumber = Math.floor(Math.random() * 10) + 1; // Rastgele sayı
        const userNumber = Math.floor(Math.random() * 10) + 1; // Kullanıcı tahmini

        const resultDiv = document.getElementById('result');
        const scoreDiv = document.getElementById('score');
        const historyList = document.getElementById('history');

        if (randomNumber === userNumber) {
            balance += 50; // Kazanınca 50 TL ekle
            resultDiv.innerHTML = `Tebrikler! Kazandınız. Sayı: ${randomNumber}`;
            resultDiv.style.color = 'green';
            history.push(`Kazandı (Tahmin: ${userNumber}, Doğru: ${randomNumber})`);
        } else {
            balance -= 10; // Kaybedince 10 TL çıkar
            resultDiv.innerHTML = `Üzgünüz, kaybettiniz. Sayı: ${randomNumber}, Tahmininiz: ${userNumber}`;
            resultDiv.style.color = 'red';
            history.push(`Kaybetti (Tahmin: ${userNumber}, Doğru: ${randomNumber})`);
        }

        // Güncel bakiye
        scoreDiv.innerHTML = `Kalan Paranız: ${balance} TL`;

        // Oyun geçmişini güncelle
        historyList.innerHTML = history.map(item => `<li>${item}</li>`).join('');

        // Bakiye kontrolü
        if (balance <= 0) {
            resultDiv.innerHTML = "Paranız bitti! Oyuna devam etmek için bakiye ekleyin.";
            resultDiv.style.color = 'red';
            document.querySelector("button").disabled = true; // Oyun butonunu devre dışı bırak
        }
    }

    function toggleMusic() {
        if (musicPlaying) {
            music.pause();
            musicPlaying = false;
        } else {
            music.play();
            musicPlaying = true;
        }
    }
</script>
</body> </html> ```