Jocaa91 commited on
Commit
4e5ade9
·
verified ·
1 Parent(s): e95ed5f

I click on the Vs computer button but nothing happens. Is it possible to play against a real machine or AI - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +48 -6
index.html CHANGED
@@ -373,6 +373,34 @@
373
 
374
  selectedBtn.classList.remove('bg-indigo-100', 'text-indigo-800');
375
  selectedBtn.classList.add('bg-indigo-600', 'text-white');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  }
377
 
378
  function addPlayer() {
@@ -403,13 +431,23 @@
403
  function removePlayer(button) {
404
  const playerDiv = button.parentNode;
405
  const playerInputs = document.getElementById('playerInputs');
 
 
 
 
 
 
406
 
407
- if (playerInputs.children.length > 1) {
408
  playerDiv.remove();
409
 
410
- // Disable remove button if there's only one player left
411
- if (playerInputs.children.length === 1) {
412
- playerInputs.querySelector('button').disabled = true;
 
 
 
 
413
  }
414
  }
415
  }
@@ -422,11 +460,15 @@
422
  gameState.players = [];
423
  const playerNames = document.querySelectorAll('.player-name');
424
  playerNames.forEach(input => {
425
- const name = input.value.trim() || `Player ${gameState.players.length + 1}`;
 
 
 
426
  gameState.players.push({
427
  name: name,
428
  score: 0,
429
- completedCategories: 0
 
430
  });
431
  });
432
 
 
373
 
374
  selectedBtn.classList.remove('bg-indigo-100', 'text-indigo-800');
375
  selectedBtn.classList.add('bg-indigo-600', 'text-white');
376
+
377
+ // Clear existing players
378
+ const playerInputs = document.getElementById('playerInputs');
379
+ playerInputs.innerHTML = '';
380
+
381
+ // Add human player
382
+ const humanDiv = document.createElement('div');
383
+ humanDiv.className = 'flex items-center';
384
+ humanDiv.innerHTML = `
385
+ <input type="text" placeholder="Player 1" class="player-name flex-1 border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500">
386
+ <button class="ml-2 text-red-500 hover:text-red-700" onclick="removePlayer(this)" disabled>
387
+ <i class="fas fa-times"></i>
388
+ </button>
389
+ `;
390
+ playerInputs.appendChild(humanDiv);
391
+
392
+ // Add computer player if in computer mode
393
+ if (mode === 'computer') {
394
+ const computerDiv = document.createElement('div');
395
+ computerDiv.className = 'flex items-center';
396
+ computerDiv.innerHTML = `
397
+ <input type="text" value="Computer" readonly class="player-name flex-1 border border-gray-300 rounded px-3 py-2 bg-gray-100">
398
+ <button class="ml-2 text-red-500 hover:text-red-700" onclick="removePlayer(this)">
399
+ <i class="fas fa-times"></i>
400
+ </button>
401
+ `;
402
+ playerInputs.appendChild(computerDiv);
403
+ }
404
  }
405
 
406
  function addPlayer() {
 
431
  function removePlayer(button) {
432
  const playerDiv = button.parentNode;
433
  const playerInputs = document.getElementById('playerInputs');
434
+ const playerName = playerDiv.querySelector('.player-name').value;
435
+
436
+ // Don't allow removing the last human player
437
+ const humanPlayers = Array.from(playerInputs.children).filter(div =>
438
+ !div.querySelector('.player-name').value.includes('Computer')
439
+ );
440
 
441
+ if (humanPlayers.length > 1 || playerName.includes('Computer')) {
442
  playerDiv.remove();
443
 
444
+ // Disable remove buttons if only one human player left
445
+ const remainingHumanPlayers = Array.from(playerInputs.children).filter(div =>
446
+ !div.querySelector('.player-name').value.includes('Computer')
447
+ );
448
+
449
+ if (remainingHumanPlayers.length === 1) {
450
+ remainingHumanPlayers[0].querySelector('button').disabled = true;
451
  }
452
  }
453
  }
 
460
  gameState.players = [];
461
  const playerNames = document.querySelectorAll('.player-name');
462
  playerNames.forEach(input => {
463
+ let name = input.value.trim();
464
+ if (!name) {
465
+ name = input.hasAttribute('readonly') ? 'Computer' : `Player ${gameState.players.length + 1}`;
466
+ }
467
  gameState.players.push({
468
  name: name,
469
  score: 0,
470
+ completedCategories: 0,
471
+ isComputer: name.includes('Computer')
472
  });
473
  });
474