function tileSetup() {
  const tileArray = document.querySelectorAll('.tile');
  tileArray.forEach((tile, index) => {
    tile.id = `tile-${index}`;

    // inexplicably, Chrome Android browser does not like it when some background image positions are set to 100%.
    // therefore capping this to 99.6%, which seems to display ok
    const backgroundPositionX = ((index % 5) * 99.6) / 4;
    const backgroundPositionY = (Math.floor(index / 5) * 99.6) / 4;
    tile.style.backgroundPosition = `${backgroundPositionX}% ${backgroundPositionY}%`;

    tileState['tileLoc'][tile.id] = index;
    gameWonState['tileLoc'][tile.id] = index;

    tile.querySelector('.number').innerText = index + 1;

    tile.addEventListener('mousedown', startSwipe);
    tile.addEventListener('touchstart', startSwipe);
  });

  //TODO: make choice of tile to remove user-customisable
  deleteTile('tile-24');
}
// Position the image in the right place on each tile to reassemble it on the grid, and enable click events on the tiles
Position the image in the right place on each tile to reassemble it on the grid, and enable click events on the tiles
Position the image in the right place on each tile to reassemble it on the grid and enable click events on the tiles
function tileSetup() {
  const tileArray = document.querySelectorAll('.tile');
  tileArray.forEach((tile, index) => {
    tile.id = `tile-${index}`;
    const backgroundPositionX = ((index % 5) * 99.6) / 4;
    const backgroundPositionY = (Math.floor(index / 5) * 99.6) / 4;
    tile.style.backgroundPosition = `${backgroundPositionX}% ${backgroundPositionY}%`;
    tileState['tileLoc'][tile.id] = index;
    gameWonState['tileLoc'][tile.id] = index;
    tile.querySelector('.number').innerText = index + 1;
    tile.addEventListener('mousedown', startSwipe);
    tile.addEventListener('touchstart', startSwipe);
  });
  deleteTile('tile-24');
}
function tileSetup ( ) { const tileArray = document . querySelectorAll ( '.tile' ) ; tileArray . forEach ( ( tile , index ) => { tile . id = ` ${ index } ` ; const backgroundPositionX = ( ( index % 5 ) * 99.6 ) / 4 ; const backgroundPositionY = ( Math . floor ( index / 5 ) * 99.6 ) / 4 ; tile . style . backgroundPosition = ` ${ backgroundPositionX } ${ backgroundPositionY } ` ; tileState [ 'tileLoc' ] [ tile . id ] = index ; gameWonState [ 'tileLoc' ] [ tile . id ] = index ; tile . querySelector ( '.number' ) . innerText = index + 1 ; tile . addEventListener ( 'mousedown' , startSwipe ) ; tile . addEventListener ( 'touchstart' , startSwipe ) ; } ) ; deleteTile ( 'tile-24' ) ; }
Position the image in the right place on each tile to reassemble it on the grid, and enable click events on the tiles
Position the image in the right place on each tile to reassemble it on the grid and enable click events on the tiles
// inexplicably, Chrome Android browser does not like it when some background image positions are set to 100%. // therefore capping this to 99.6%, which seems to display ok //TODO: make choice of tile to remove user-customisable