Evet / Hayır
body {
text-align: center;
margin: 0;
font-family: Arial, sans-serif;
position: relative;
height: 100vh;
overflow: hidden;
background-color: white;
transition: background-color 0.3s ease;
display: flex;
flex-direction: column;
justify-content: center;
}
#timer {
position: fixed;
top: 10px;
left: 50%;
transform: translateX(-50%);
font-size: 24px;
font-weight: bold;
background: #222;
color: #fff;
padding: 8px 20px;
border-radius: 8px;
z-index: 1100;
user-select: none;
}
button {
padding: 15px 30px;
font-size: 20px;
margin: 20px;
position: absolute;
cursor: pointer;
user-select: none;
}
#evetBtn {
left: 40%;
top: 40%;
}
#hayirBtn {
left: 55%;
top: 40%;
transition: 0.3s ease;
}
/* Toast stil */
#toast {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 4px;
padding: 16px;
position: fixed;
top: 60px;
left: 50%;
transform: translateX(-50%);
font-size: 18px;
z-index: 1000;
opacity: 0;
transition: opacity 0.5s ease, visibility 0.5s;
user-select: none;
}
#toast.show {
visibility: visible;
opacity: 1;
}
/* Yeni soru alani */
#question {
position: fixed;
bottom: 10px;
width: 100%;
text-align: center;
font-size: 22px;
font-weight: bold;
color: #222;
user-select: none;
}
Evet
Hayır
const hayirBtn = document.getElementById(‘hayirBtn’);
const evetBtn = document.getElementById(‘evetBtn’);
const toast = document.getElementById(‘toast’);
const timerDiv = document.getElementById(‘timer’);
let timeLeft = 30; // 30 saniye
let timerInterval = null;
let gameEnded = false;
// Süreyi başlat
function startTimer() {
clearInterval(timerInterval);
timeLeft = 30;
gameEnded = false;
timerDiv.textContent = `Süre: ${timeLeft}`;
timerInterval = setInterval(() => {
if (timeLeft > 0) {
timeLeft–;
timerDiv.textContent = `Süre: ${timeLeft}`;
} else {
clearInterval(timerInterval);
if (!gameEnded) {
gameEnded = true;
showToast(‘OMAAR KAZANDI’);
}
}
}, 1000);
}
// Hayır butonu hareketi
hayirBtn.addEventListener(‘mouseover’, () => {
const maxX = window.innerWidth – hayirBtn.offsetWidth;
const maxY = window.innerHeight – hayirBtn.offsetHeight – 10;
const x = Math.floor(Math.random() * maxX);
const y = Math.floor(Math.random() * maxY);
hayirBtn.style.left = x + ‘px’;
hayirBtn.style.top = y + ‘px’;
});
// Hayır buton tıklama
hayirBtn.addEventListener(‘click’, () => {
if (gameEnded) return; // oyun bittiyse tıklama yok
gameEnded = true;
clearInterval(timerInterval);
showToast(‘Harika, tıklamayı başardın!’);
});
// Evet buton tıklama: eğer oyun bitti ise yeniden başlat, değilse arkaplan değişimi
evetBtn.addEventListener(‘click’, () => {
if (gameEnded) {
startTimer(); // oyunu yeniden başlat
document.body.style.backgroundColor = ‘white’; // resetle
} else {
startBackgroundColorChange(5);
}
});
// Toast gösterme fonksiyonu
function showToast(message) {
toast.textContent = message;
toast.classList.add(‘show’);
setTimeout(() => {
toast.classList.remove(‘show’);
}, 3000);
}
// Rastgele renk üret
function getRandomColor() {
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
return `rgb(${r},${g},${b})`;
}
// Arka plan renk değişimi fonksiyonu
function startBackgroundColorChange(durationSeconds) {
let elapsed = 0;
const totalIntervals = durationSeconds * 10; // 100ms aralık için (5s = 50 kez)
const interval = setInterval(() => {
document.body.style.backgroundColor = getRandomColor();
elapsed++;
if (elapsed >= totalIntervals) {
clearInterval(interval);
document.body.style.backgroundColor = ‘white’; // eski haline dön
}
}, 100);
}
// Oyunu başlat
startTimer();