🎮 Tic-Tac-Toe P2P Game

Play with friends using WebRTC peer-to-peer connection

How to Play (P2P Connection):

  1. Player 1: Click "Create Game" → Copy the invitation code
  2. Player 2: Click "Join Game" → Paste invitation → You'll get an ANSWER code
  3. Player 2: Copy the answer code and send it to Player 1
  4. Player 1: Click "Complete Connection" → Paste the answer code
  5. Both players should now be connected! Start playing and chatting.
Initializing...
0 peers

Connection

Connected Players:

  • No players connected

Game Board

Waiting for connection...

💬 Chat with Your Opponent

0
`; } // Handle page visibility changes (pause game when tab is hidden) document.addEventListener('visibilitychange', () => { if (document.hidden) { console.log('[TicTacToe Page] Page hidden, pausing game'); } else { console.log('[TicTacToe Page] Page visible, resuming game'); } }); // Handle beforeunload (warn about leaving active game) window.addEventListener('beforeunload', (event) => { // Check if there's an active game const gameContainer = document.getElementById('tic-tac-toe-container'); const roomControls = gameContainer?.querySelector('#room-controls'); if (roomControls && roomControls.style.display !== 'none') { event.preventDefault(); event.returnValue = 'You have an active game. Are you sure you want to leave?'; return event.returnValue; } });