Skip to content
Snippets Groups Projects
Select Git revision
  • 550d435a2008fc0eef83cb0d30fdb53c32de264f
  • master default protected
2 results

graph-parcours-bellman.py

Blame
  • index.js 18.57 KiB
    const player = {
        host: false,
        playedCell: "",
        roomId: null,
        username: "",
        socketId: "",
        symbol: "X",
        turn: false,
        win: false
    };
    
    const socket = io();
    
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const roomId = urlParams.get('room');
    
    if (roomId) {
        document.getElementById('start').innerText = "Rejoindre";
    }
    
    const usernameInput = document.getElementById('username');
    
    const gameCard = document.getElementById('game-card');
    const userCard = document.getElementById('user-card');
    
    const restartArea = document.getElementById('restart-area');
    const waitingArea = document.getElementById('waiting-area');
    
    const roomsCard = document.getElementById('rooms-card');
    const roomsList = document.getElementById('rooms-list');
    
    const turnMsg = document.getElementById('turn-message');
    const linkToShare = document.getElementById('link-to-share');
    
    let ennemyUsername = "";
    
    socket.emit('get rooms');
    socket.on('list rooms', (rooms) => {
        let html = "";
    
        if (rooms.length > 0) {
            rooms.forEach(room => {
                if (room.players.length !== 2) {
                    html += `<li class="list-group-item d-flex justify-content-between">
                                <p class="p-0 m-0 flex-grow-1 fw-bold">Salon de ${room.players[0].username} - ${room.id}</p>
                                <button class="btn btn-sm btn-success join-room" data-room="${room.id}">Rejoindre</button>
                            </li>`;
                }
            });
        }
    
        if (html !== "") {
            roomsCard.classList.remove('d-none');
            roomsList.innerHTML = html;
    
            for (const element of document.getElementsByClassName('join-room')) {
                element.addEventListener('click', joinRoom, false)
            }
        }
    });
    
    $("#form").on('submit', function (e) {
        e.preventDefault();
    
        player.username = usernameInput.value;
    
        if (roomId) {
            player.roomId = roomId;
        } else {