function ambush() {

    alienOnes.forEach(alienOne => alienOne.isWhacked = false);
    alienTwos.forEach(alienTwo => alienTwo.isWhacked = false);
    const popOutTime = randomTime(1700, 1400);
    const plant = pickRandomPlant(plants);
    const popOutTimeTwo = randomTime(1700, 1300);
    const plantTwo = pickRandomPlant(plants);

    if(gameActive) {
    plant.classList.add("up");
    setTimeout(()=>{
        alienOneAttack.call(plant);
    }, 670);
    setTimeout(() => {
        plant.classList.remove("up");
        if(!timeUp) { 
            ambush();
        }
    }, popOutTime);
  }

    // This part of the ambush function calls in a second alien if on Hard Level

if(levelHard && gameActive){
    if (plant === plantTwo) {
        pickRandomPlant(plants);
    }
    plantTwo.children[1].isAmbushing = Math.random() < 0.33;
    if(plantTwo.children[1].isAmbushing) {
        setTimeout(()=> {
        plantTwo.classList.add("up-two");
        setTimeout(()=>{
            alienTwoAttack.call(plantTwo);
        }, 670);
        setTimeout(() => {
        plantTwo.classList.remove("up-two");
      }, popOutTimeTwo);
    }, 300);
      }
     }
    }
// This function controls each space ambush by the aliens
This function controls each space ambush by the aliens
This function controls each space ambush by the aliens
function ambush() {
    alienOnes.forEach(alienOne => alienOne.isWhacked = false);
    alienTwos.forEach(alienTwo => alienTwo.isWhacked = false);
    const popOutTime = randomTime(1700, 1400);
    const plant = pickRandomPlant(plants);
    const popOutTimeTwo = randomTime(1700, 1300);
    const plantTwo = pickRandomPlant(plants);
    if(gameActive) {
    plant.classList.add("up");
    setTimeout(()=>{
        alienOneAttack.call(plant);
    }, 670);
    setTimeout(() => {
        plant.classList.remove("up");
        if(!timeUp) { 
            ambush();
        }
    }, popOutTime);
  }
if(levelHard && gameActive){
    if (plant === plantTwo) {
        pickRandomPlant(plants);
    }
    plantTwo.children[1].isAmbushing = Math.random() < 0.33;
    if(plantTwo.children[1].isAmbushing) {
        setTimeout(()=> {
        plantTwo.classList.add("up-two");
        setTimeout(()=>{
            alienTwoAttack.call(plantTwo);
        }, 670);
        setTimeout(() => {
        plantTwo.classList.remove("up-two");
      }, popOutTimeTwo);
    }, 300);
      }
     }
    }
function ambush ( ) { alienOnes . forEach ( alienOne => alienOne . isWhacked = false ) ; alienTwos . forEach ( alienTwo => alienTwo . isWhacked = false ) ; const popOutTime = randomTime ( 1700 , 1400 ) ; const plant = pickRandomPlant ( plants ) ; const popOutTimeTwo = randomTime ( 1700 , 1300 ) ; const plantTwo = pickRandomPlant ( plants ) ; if ( gameActive ) { plant . classList . add ( "up" ) ; setTimeout ( ( ) => { alienOneAttack . call ( plant ) ; } , 670 ) ; setTimeout ( ( ) => { plant . classList . remove ( "up" ) ; if ( ! timeUp ) { ambush ( ) ; } } , popOutTime ) ; } if ( levelHard && gameActive ) { if ( plant === plantTwo ) { pickRandomPlant ( plants ) ; } plantTwo . children [ 1 ] . isAmbushing = Math . random ( ) < 0.33 ; if ( plantTwo . children [ 1 ] . isAmbushing ) { setTimeout ( ( ) => { plantTwo . classList . add ( "up-two" ) ; setTimeout ( ( ) => { alienTwoAttack . call ( plantTwo ) ; } , 670 ) ; setTimeout ( ( ) => { plantTwo . classList . remove ( "up-two" ) ; } , popOutTimeTwo ) ; } , 300 ) ; } } }
This function controls each space ambush by the aliens
This function controls each space ambush by the aliens
// This part of the ambush function calls in a second alien if on Hard Level