CodingTrain / CodingTrain/Suggestion-Box

7.6 Clicking on Objects and 51.1 A* Pathfinding algorithm

Open
#716 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
570
Forks
85
PR merge metrics
No merged PRs in 30d

Description

![1 1](https://user-images.githubusercontent.com/19712296/32986122-3218443c-cc98-11e7-93f2-48bdf957ef8a.png)
Hi, my question is how do you click on a single cell in a say 120 x 160 grid?

I have 2 functions. One is activated when clicking on the grid:

```
function mousePressed(){
for (var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
grid[i][j].clicked();
}
}
}
```
The other function activates for each cell:
```
this.clicked = function() {
var d = dist(mouseX, mouseY, this.i, this.j);
if(d < 1){
console.log("f", this.f);
}
}
```

Is there an efficient way to go about this? I can't wrap my head around how to solve this.. I'd appreciate any feedback, please. Thank you.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.