function startGame() {
    const holeImgs = selectAll("[data-img='hole']");
    const moleImgs = selectAll("[data-img='mole']");
    const allImgs = selectAll("img");

    fieldActive = true;
    //Automatically raising the level
    (function raiseLevel() {
      if (runningGame) {
        level.value = currentLevel;
        setTimeout(() => {
          if (life.value > 0) {
            currentLevel++;
            levelUpAudio.play();
            raiseLevel();
          }
        }, levelDuration);
      }
    })();

    // **************************** Logic of one turn (= one mole attacks you) ****************************
    function oneTurn() {
      //time a mole peeks out of the hole
      peekTime = 350 + 1000 / currentLevel;
      //time until next mole shows up
      turnTime = 450 + 1000 / currentLevel;
      const random = Math.floor(Math.random() * fieldSize);

      //if a mole_hitted png is still in the field just overwrite it at the start of an instance
      moleImgs.filter(i =>
        i.src !== "img/mole.png" ? (i.src = "img/mole.png") : i
      );
      //if a shake class is still on a mole img remove it
      moleImgs.filter(i =>
        i.classList.contains("shake") ? i.classList.remove("shake") : i
      );

      //Show mole. Check if player has played/clicked, if not he couldn't have hitted a mole so minus a life. Check for remaining lives.
      function oneTurnCheck() {
        toggleVisibility(moleImgs[random]);
        if (!playerHasClicked) {
          loseAudio.play();
          life.value--;
          if (life.value === "0") {
            showGameOverCard();
          }
        }
        playerHasClicked = false;
      }

      // here we start one turn and test if hit is true or false, than we restart a new Instance of the Game
      toggleVisibility(moleImgs[random]);
      setTimeout(() => oneTurnCheck(), peekTime);
      setTimeout(() => {
        if (life.value > 0) {
          oneTurn();
        }
        startRetryButton.innerText = "Retry";
      }, peekTime + turnTime);
    }
    oneTurn();
  }
// **************************** Actual starting of the game function  ****************************

Actual starting of the game function
Actual starting of the game function
function startGame() {
    const holeImgs = selectAll("[data-img='hole']");
    const moleImgs = selectAll("[data-img='mole']");
    const allImgs = selectAll("img");
    fieldActive = true;
    (function raiseLevel() {
      if (runningGame) {
        level.value = currentLevel;
        setTimeout(() => {
          if (life.value > 0) {
            currentLevel++;
            levelUpAudio.play();
            raiseLevel();
          }
        }, levelDuration);
      }
    })();
    function oneTurn() {
      peekTime = 350 + 1000 / currentLevel;
      turnTime = 450 + 1000 / currentLevel;
      const random = Math.floor(Math.random() * fieldSize);
      moleImgs.filter(i =>
        i.src !== "img/mole.png" ? (i.src = "img/mole.png") : i
      );
      moleImgs.filter(i =>
        i.classList.contains("shake") ? i.classList.remove("shake") : i
      );
      function oneTurnCheck() {
        toggleVisibility(moleImgs[random]);
        if (!playerHasClicked) {
          loseAudio.play();
          life.value--;
          if (life.value === "0") {
            showGameOverCard();
          }
        }
        playerHasClicked = false;
      }
      toggleVisibility(moleImgs[random]);
      setTimeout(() => oneTurnCheck(), peekTime);
      setTimeout(() => {
        if (life.value > 0) {
          oneTurn();
        }
        startRetryButton.innerText = "Retry";
      }, peekTime + turnTime);
    }
    oneTurn();
  }
function startGame ( ) { const holeImgs = selectAll ( "[data-img='hole']" ) ; const moleImgs = selectAll ( "[data-img='mole']" ) ; const allImgs = selectAll ( "img" ) ; fieldActive = true ; ( function raiseLevel ( ) { if ( runningGame ) { level . value = currentLevel ; setTimeout ( ( ) => { if ( life . value > 0 ) { currentLevel ++ ; levelUpAudio . play ( ) ; raiseLevel ( ) ; } } , levelDuration ) ; } } ) ( ) ; function oneTurn ( ) { peekTime = 350 + 1000 / currentLevel ; turnTime = 450 + 1000 / currentLevel ; const random = Math . floor ( Math . random ( ) * fieldSize ) ; moleImgs . filter ( i => i . src !== "img/mole.png" ? ( i . src = "img/mole.png" ) : i ) ; moleImgs . filter ( i => i . classList . contains ( "shake" ) ? i . classList . remove ( "shake" ) : i ) ; function oneTurnCheck ( ) { toggleVisibility ( moleImgs [ random ] ) ; if ( ! playerHasClicked ) { loseAudio . play ( ) ; life . value -- ; if ( life . value === "0" ) { showGameOverCard ( ) ; } } playerHasClicked = false ; } toggleVisibility ( moleImgs [ random ] ) ; setTimeout ( ( ) => oneTurnCheck ( ) , peekTime ) ; setTimeout ( ( ) => { if ( life . value > 0 ) { oneTurn ( ) ; } startRetryButton . innerText = "Retry" ; } , peekTime + turnTime ) ; } oneTurn ( ) ; }
Actual starting of the game function
Actual starting of the game function
//Automatically raising the level
 // **************************** Logic of one turn (= one mole attacks you) ****************************
 //time a mole peeks out of the hole
 //time until next mole shows up
 //if a mole_hitted png is still in the field just overwrite it at the start of an instance
 //if a shake class is still on a mole img remove it
 //Show mole. Check if player has played/clicked, if not he couldn't have hitted a mole so minus a life. Check for remaining lives.
 // here we start one turn and test if hit is true or false, than we restart a new Instance of the Game
