Changed around line 1
+ const setupSection = document.getElementById('setup');
+ const gameSection = document.getElementById('game');
+ const urinalRow = document.getElementById('urinalRow');
+ const urinalCountInput = document.getElementById('urinalCount');
+ const countDisplay = document.getElementById('countDisplay');
+ const startGameBtn = document.getElementById('startGame');
+ const nextRoundBtn = document.getElementById('nextRound');
+ const scoreDisplay = document.getElementById('score');
+ const feedbackDisplay = document.getElementById('feedback');
+
+ let score = 0;
+ let currentRound = 0;
+ let totalRounds = 5;
+ let urinalCount = 5;
+
+ urinalCountInput.addEventListener('input', () => {
+ urinalCount = parseInt(urinalCountInput.value);
+ countDisplay.textContent = urinalCount;
+ });
+
+ startGameBtn.addEventListener('click', () => {
+ setupSection.classList.add('hidden');
+ gameSection.classList.remove('hidden');
+ score = 0;
+ currentRound = 0;
+ scoreDisplay.textContent = score;
+ startNewRound();
+ });
+
+ function startNewRound() {
+ urinalRow.innerHTML = '';
+ const occupiedUrinals = generateOccupiedUrinals();
+
+ for (let i = 0; i < urinalCount; i++) {
+ const urinal = document.createElement('div');
+ urinal.classList.add('urinal');
+ if (occupiedUrinals.includes(i)) {
+ urinal.classList.add('occupied');
+ } else {
+ urinal.addEventListener('click', () => selectUrinal(i, occupiedUrinals));
+ }
+ urinalRow.appendChild(urinal);
+ }
+
+ nextRoundBtn.classList.add('hidden');
+ }
+
+ function generateOccupiedUrinals() {
+ const occupied = [];
+ const count = Math.floor(Math.random() * (urinalCount - 1)) + 1;
+
+ while (occupied.length < count) {
+ const index = Math.floor(Math.random() * urinalCount);
+ if (!occupied.includes(index)) {
+ occupied.push(index);
+ }
+ }
+
+ return occupied;
+ }
+
+ function selectUrinal(index, occupiedUrinals) {
+ const urinals = Array.from(urinalRow.children);
+ urinals[index].classList.add('selected');
+
+ const scoreChange = calculateScore(index, occupiedUrinals);
+ score += scoreChange;
+ scoreDisplay.textContent = score;
+
+ showFeedback(scoreChange);
+
+ setTimeout(() => {
+ currentRound++;
+ if (currentRound < totalRounds) {
+ startNewRound();
+ } else {
+ endGame();
+ }
+ }, 1000);
+ }
+
+ function calculateScore(index, occupiedUrinals) {
+ const adjacent = [index - 1, index + 1];
+ const isAdjacentOccupied = adjacent.some(i => occupiedUrinals.includes(i));
+
+ if (isAdjacentOccupied) {
+ return 1;
+ } else {
+ return 3;
+ }
+ }
+
+ function showFeedback(scoreChange) {
+ if (scoreChange === 3) {
+ feedbackDisplay.textContent = "Great choice! Maximum privacy.";
+ } else if (scoreChange === 1) {
+ feedbackDisplay.textContent = "Okay, but you're next to someone.";
+ }
+ }
+
+ function endGame() {
+ feedbackDisplay.textContent = `Game over! Final score: ${score}`;
+ nextRoundBtn.classList.remove('hidden');
+ nextRoundBtn.textContent = "Play Again";
+ nextRoundBtn.addEventListener('click', () => {
+ setupSection.classList.remove('hidden');
+ gameSection.classList.add('hidden');
+ }, { once: true });
+ }