server/services/gameService.js
// If player count is fulfilled, starts the game immediately
If player count is fulfilled, starts the game immediately
If player count is fulfilled starts the game immediately
joinGame(game, playerName) {
    if (!authService.validateUsername(playerName)) {
      return null;
    }
    if (game.isFull()) {
      return null;
    }
    let human = new HumanPlayer(playerName);
    game.addPlayer(human);
    if (game.isFull()) {
      this.startNewGame(game);
      game.players.filter(player => player !== human).forEach((player) => {
        socketService.emitToClient(player.socket, 'gameStarted', {
          game,
          player,
          playerIndex: game.players.indexOf(player)
        });
      });
    }
    else {
      socketService.emitToRoom('game', game.id, 'joinedPlayersChanged', { game: game });
    }
    socketService.emitToRoom('playRoom', 'playRoom', 'openGamesChanged', this.getOpenGames());
    socketService.sendChatMessage(game.id, null, `Player '${human.name}' joined the game!`);
    return { game: game, player: human };
  }
joinGame ( game , playerName ) { if ( ! authService . validateUsername ( playerName ) ) { return null ; } if ( game . isFull ( ) ) { return null ; } let human = new HumanPlayer ( playerName ) ; game . addPlayer ( human ) ; if ( game . isFull ( ) ) { this . startNewGame ( game ) ; game . players . filter ( player => player !== human ) . forEach ( ( player ) => { socketService . emitToClient ( player . socket , 'gameStarted' , { game , player , playerIndex : game . players . indexOf ( player ) } ) ; } ) ; } else { socketService . emitToRoom ( 'game' , game . id , 'joinedPlayersChanged' , { game : game } ) ; } socketService . emitToRoom ( 'playRoom' , 'playRoom' , 'openGamesChanged' , this . getOpenGames ( ) ) ; socketService . sendChatMessage ( game . id , null , ` ${ human . name } ` ) ; return { game : game , player : human } ; }
If player count is fulfilled, starts the game immediately
If player count is fulfilled starts the game immediately
// Notify other players