sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

Audio issue #250

Closed RyanCLuis closed 9 months ago

RyanCLuis commented 9 months ago

What's the problem you're trying to solve?

with the code i have, it plays both audio file when i want it to (ie when i hit a tile and when a 🧠 is hit) as well as when i am placing a 🥴 the sounds dont play. When i add a if statement (ie , if (gameOver) {return} ) so you cant keep clicking a tile and hear the sound. it bugs my 🧠 sound to where i cant hear it.

Post any code you think might be relevant (one fenced block per file)

this is the first block before i add the gameOver function and audio is working

function playMusic () {
    let tile = event.target // gets selected tile
    // checkes to see if head emoji is selected
    if (tile.innerText === "🥴") {
        return
    }
    if (tile.innerText === "🧠") {
        let audio = new Audio("soundEffects/splat.mp3")
        audio.play()
    } else {
        let audio = new Audio("soundEffects/gun.mp3")
        audio.play()
    }
}

this is the eventListener to play the audio

function renderBoard() {
    document.getElementById("mind-count").innerText = minds
    document.getElementById("head").addEventListener("click", setHead)
    setMinds()
    // populate my tiles using a for loop
    for (let r = 0;r < rows; r++) {
        let row = []
        for (let c = 0; c < columns; c++) {
            // making a div tag in HTML
            let tile = document.createElement("div")
            tile.id = `${r}-${c}`
            tile.addEventListener("click", tileClicked)
            // this is an event listener to play music on tile click
            tile.addEventListener("click", playMusic)
            document.getElementById("tiles").append(tile)
            row.push(tile)
        }
        board.push(row)
    }
}
function playMusic () {
    if (gameOver) {
        return
    }
    let tile = event.target // gets selected tile
    // checkes to see if head emoji is selected
    if (tile.innerText === "🥴") {
        return
    }
    if (tile.innerText === "🧠") {
        let audio = new Audio("soundEffects/splat.mp3")
        audio.play()
    } else {
        let audio = new Audio("soundEffects/gun.mp3")
        audio.play()
    }
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

What is your best guess as to the source of the problem?

Na

What things have you already tried to solve the problem?

i tried making a new function called playBrainAudio and having it pass through the revealMinds function but still nothing

Paste a link to your repository here

https://github.com/RyanCLuis/Minesweeper/tree/v2

RyanCLuis commented 9 months ago

okay did some rearranging and have this

function playMusic () {
    let tile = event.target // gets selected tile
    // checkes to see if head emoji is selected
    if (tile.innerText === "🥴") {
        return
    }
    if (tile.innerText === "🧠") {
        let audio = new Audio("soundEffects/splat.mp3")
        audio.play()
    } if (gameOver) {
        return
    } else {
        let audio = new Audio("soundEffects/gun.mp3")
        audio.play()
    }
}

and with this everything plays and stops except when i hit the 🧠 it still plays audio but all other tiles dont, how do i get all audio to stop playing

RyanCLuis commented 9 months ago

neverminded, fixed the issue after messing with it! I tried moving the gameOver function around and was getting different results i didn't want, so i decided to make a new function the when a mind was revealed it played an audio and i called upon that function in the realMinds function