| 392 | } |
| 393 | |
| 394 | handleMouseDown(row, col) { |
| 395 | if (this.state.toDelete) { |
| 396 | let agentToDelete = this.state.map[row][col].agent; |
| 397 | if (agentToDelete === -1) return; |
| 398 | let agents = this.state.agents; |
| 399 | agents.splice(agentToDelete - 1, 1); |
| 400 | let map = this.state.map; |
| 401 | for (let i = 0; i < map.length; i++) { |
| 402 | for (let j = 0; j < map[i].length; j++) { |
| 403 | if (!map[i][j].isWall) { |
| 404 | map[i][j].isStart = false; |
| 405 | map[i][j].isGoal = false; |
| 406 | map[i][j].agent = -1; |
| 407 | map[i][j].color = ""; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | for (let i = 0; i < agents.length; i++) { |
| 412 | let agent = agents[i]; |
| 413 | for (let x = agent.SR; x < agent.SR + agent.height; x++) { |
| 414 | for (let y = agent.SC; y < agent.SC + agent.width; y++) { |
| 415 | map[x][y].isStart = true; |
| 416 | map[x][y].agent = i + 1; |
| 417 | map[x][y].color = agent.color; |
| 418 | } |
| 419 | } |
| 420 | for (let x = agent.GR; x < agent.GR + agent.height; x++) { |
| 421 | for (let y = agent.GC; y < agent.GC + agent.width; y++) { |
| 422 | map[x][y].isStart = true; |
| 423 | map[x][y].agent = i + 1; |
| 424 | map[x][y].color = agent.color; |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | this.setState({ map: map, agents: agents, numAgents: agents.length, toDelete: false }); |
| 429 | } else if (this.state.startToAdd) { |
| 430 | if (!this.state.map[row][col].isWall && this.state.map[row][col].agent === -1) { |
| 431 | var map = this.state.map; |
| 432 | map[row][col].agent = this.state.numAgents + 1; |
| 433 | map[row][col].isStart = true; |
| 434 | map[row][col].color = this.state.colorToAdd; |
| 435 | this.setState({ |
| 436 | addedSRowClick: row, |
| 437 | addedSColClick: col, |
| 438 | addedHeightByClick: 1, |
| 439 | addedWidthByClick: 1, |
| 440 | map: map, |
| 441 | isMousePressed: true, |
| 442 | }); |
| 443 | } |
| 444 | } else if (this.state.goalToAdd) { |
| 445 | if (!this.state.map[row][col].isWall && this.state.map[row][col].agent === -1) { |
| 446 | var map = this.state.map; |
| 447 | for (let x = row; x < row + this.state.addedHeightByClick; x++) { |
| 448 | for (let y = col; y < col + this.state.addedWidthByClick; y++) { |
| 449 | if ( |
| 450 | x >= this.state.numRow || |
| 451 | y >= this.state.numCol || |