Closed irishjack490 closed 9 months ago
I'm not seeing any code here that is placing the mines on any cached elements, do you have any code like that?
Ah, I don't, let me work on that.. tks for steering me in that direction
My apologies on the delay, I was able to manually allocate the mines. I went ahead and created the boxes via JavaScript. I did a loop to create a row and then used another loop to create column and gave it the Id of box. I then was able to set mines based on coordinates of my choosing. I clicked on a square where I designated mines, it worked. I am a bit lost on trying to get the random mines to allocate, could you take a look? here is what I have for them right now (here is my git:https://github.com/irishjack490/Project-1---Browser-Based-Game/blob/main/main.js)
function setMines () { while(setMines < numberOfMines){ const row = Math.floor(Math.random () rows); const column = Math.floor(Math.random () columns); if(!board[row][column].isMine){ board[row][column].isMine=true; setMines++; }
function for box clicked
function boxClicked () { let box = this; if (minesLocation.isMine) { alert("GAMER OVER"); gameOver = true; return; } Thanks so much
So the first thing I'm noticing is that we have a counter inside of the setMines
function. That counter is also the variable setMines
. Do we perhaps need to declare another variable to be our counter?
I will try that, if I run into other issues. I will open a new one. Thank you so much, should I close this issue?
What's the problem you're trying to solve?
I am trying to allocate mines for minesweeper manually (I am planning to change it to random function later). First I want to test if it works. I am able to click on the box and the color will change to gray which is fine. But I can't seem to find a way to allocate mines
Post any code you think might be relevant (one fenced block per file)
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?
I think the problem is the array
What things have you already tried to solve the problem?
changed the array values to just numbers
Paste a link to your repository here
https://github.com/irishjack490/Project-1---Browser-Based-Game
Thank you!!