Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
spbRusty authored Aug 22, 2024
1 parent 90b107f commit 4153983
Showing 1 changed file with 73 additions and 35 deletions.
108 changes: 73 additions & 35 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
let playerScore = 0;
let computerScore = 0;
let roundsPlayed = 0;

function getRandomCard() {
const cards = ['rock', 'scissors', 'paper'];
const randomIndex = Math.floor(Math.random() * cards.length);
Expand All @@ -20,46 +24,80 @@ function determineWinner(playerChoice, computerChoice) {
}
}

function updateScoreboard() {
const scoreboard = document.getElementById('result-message');
scoreboard.innerHTML = `Счёт: Вы - ${playerScore}, Компьютер - ${computerScore}<br>Раунд ${roundsPlayed + 1}`;
}

function checkGameWinner() {
if (playerScore === 2 || computerScore === 2) {
const resultText = playerScore === 2 ? "Вы выиграли матч!" : "Вы проиграли матч!";
const resultMessage = document.getElementById('result-message');
resultMessage.textContent = resultText;
const nextRoundButton = document.getElementById('next-round-button');
nextRoundButton.textContent = 'Новая игра';
nextRoundButton.onclick = resetGame;
return true;
}
return false;
}

function playGame(playerChoice) {
const computerChoice = getRandomCard();
const computerChoice = getRandomCard();
roundsPlayed++;

// Показать выбранную компьютером карту
const topRowCards = document.querySelectorAll('#top-row .card');
topRowCards.forEach(card => {
if (card.getAttribute('data-type') === computerChoice) {
card.textContent = computerChoice === 'rock' ? 'Камень' : computerChoice === 'scissors' ? 'Ножницы' : 'Бумага';
card.style.color = '#fff';
card.style.backgroundColor = '#8fa5b6';
card.classList.add('revealed');
}
});
// Показать выбранную компьютером карту
const topRowCards = document.querySelectorAll('#top-row .card');
topRowCards.forEach(card => {
if (card.getAttribute('data-type') === computerChoice) {
card.textContent = computerChoice === 'rock' ? 'Камень' : computerChoice === 'scissors' ? 'Ножницы' : 'Бумага';
card.style.color = '#fff';
card.style.backgroundColor = '#8fa5b6';
card.classList.add('revealed');
}
});

const resultText = determineWinner(playerChoice, computerChoice);
const resultText = determineWinner(playerChoice, computerChoice);
if (resultText === "Вы выиграли!") {
playerScore++;
} else if (resultText === "Вы проиграли!") {
computerScore++;
}

// Добавляем задержку перед показом модального окна
setTimeout(() => {
const resultMessage = document.getElementById('result-message');
resultMessage.textContent = resultText;
const resultModal = document.getElementById('result-modal');
resultModal.classList.remove('hidden');
}, 600); // Задержка 600 мс для завершения анимации переворота карты
setTimeout(() => {
updateScoreboard();
const resultModal = document.getElementById('result-modal');
resultModal.classList.remove('hidden');

const nextRoundButton = document.getElementById('next-round-button');
nextRoundButton.onclick = startNextRound;

if (!checkGameWinner()) {
nextRoundButton.textContent = 'Дальше';
}
}, 600); // Задержка для завершения анимации переворота карты
}

function resetGame() {
// Скрыть модальное окно
const resultModal = document.getElementById('result-modal');
resultModal.classList.add('hidden');
function startNextRound() {
const resultModal = document.getElementById('result-modal');
resultModal.classList.add('hidden');

// Сброс карт
const topRowCards = document.querySelectorAll('#top-row .card');
topRowCards.forEach(card => {
card.textContent = '';
card.style.color = 'transparent';
card.style.backgroundColor = '#777';
card.classList.remove('revealed');
card.style.transform = 'rotateY(180deg)'; // Обратный переворот карты
setTimeout(() => {
card.style.transform = '';
}, 10); // Небольшая задержка для сброса анимации
});
const topRowCards = document.querySelectorAll('#top-row .card');
topRowCards.forEach(card => {
card.textContent = '';
card.style.color = 'transparent';
card.style.backgroundColor = '#777';
card.classList.remove('revealed');
card.style.transform = 'rotateY(180deg)';
setTimeout(() => {
card.style.transform = '';
}, 10);
});
}

function resetGame() {
playerScore = 0;
computerScore = 0;
roundsPlayed = 0;
startNextRound();
}

0 comments on commit 4153983

Please sign in to comment.