sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

placing "flags" on tiles #206

Closed RyanCLuis closed 9 months ago

RyanCLuis commented 9 months ago

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

i have created the way to make my "flag" button toggle on and off, but when i toggle it on and click on a tile, it doesnt produce the "Flag".

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


function renderBoard() {
    document.getElementById("mind-count").innerText = minds
    document.getElementById("head").addEventListener("click", setHead)
    // 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.removeEventListener("click", tileClicked)
            document.getElementById("tiles").append(tile)
            row.push(tile)
        }
        board.push(row)
    }
    console.log(board)
}

function setHead() {
    if (headEn) {
        headEn = false
        document.getElementById("head").style.backgroundColor = "green"
    } 
    else {
        headEn = true
        document.getElementById("head").style.backgroundColor = "#ff83ff"
    }
}

function tileClicked() {
    let tile = this
    if (headEn) {
        if (tile.innerText === "") {
            tile.innerText = "https://i.imgur.com/KS651NW.gif"
        } 
        else if (tile.innerText === "https://i.imgur.com/KS651NW.gif") {
            tile.innerText = ""
        }
    }
}

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

no error message, but here is a picture to demonstrate image image image

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

must be something in my code that isn't triggering, calling the wrong event maybe.....

What things have you already tried to solve the problem?

ive tried repositioning of the functions, made sure im calling the right parameters

Paste a link to your repository here

https://github.com/RyanCLuis/Minesweeper

nayaba commented 9 months ago

My first question is, do you mean to be removing the eventListener in your tiles loop?

RyanCLuis commented 9 months ago

i mean when i use my eventListener i can toggle my button as shown in the pictures, what im trying to do is when i toggle on the button you can click a square and when it does it places that emoji on the tile and it cant be clicked on, unless you take it off