| 492 | } |
| 493 | |
| 494 | handleMouseEnter(row, col) { |
| 495 | if (this.state.startToAdd && this.state.isMousePressed) { |
| 496 | if (!this.state.map[row][col].isWall) { |
| 497 | var map = this.state.map; |
| 498 | for ( |
| 499 | let x = Math.min(row, this.state.addedSRowClick); |
| 500 | x <= Math.max(row, this.state.addedSRowClick); |
| 501 | x++ |
| 502 | ) { |
| 503 | for ( |
| 504 | let y = Math.min(col, this.state.addedSColClick); |
| 505 | y <= Math.max(col, this.state.addedSColClick); |
| 506 | y++ |
| 507 | ) { |
| 508 | if ( |
| 509 | map[x][y].isWall || |
| 510 | (map[x][y].agent !== -1 && map[x][y].agent !== this.state.numAgents + 1) |
| 511 | ) { |
| 512 | return; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | for (let i = 0; i < map.length; i++) { |
| 517 | for (let j = 0; j < map[i].length; j++) { |
| 518 | if (map[i][j].agent === this.state.numAgents + 1) { |
| 519 | map[i][j].isStart = false; |
| 520 | map[i][j].agent = -1; |
| 521 | map[i][j].color = ""; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | for ( |
| 526 | let x = Math.min(row, this.state.addedSRowClick); |
| 527 | x <= Math.max(row, this.state.addedSRowClick); |
| 528 | x++ |
| 529 | ) { |
| 530 | for ( |
| 531 | let y = Math.min(col, this.state.addedSColClick); |
| 532 | y <= Math.max(col, this.state.addedSColClick); |
| 533 | y++ |
| 534 | ) { |
| 535 | map[x][y].agent = this.state.numAgents + 1; |
| 536 | map[x][y].isStart = true; |
| 537 | map[x][y].color = this.state.colorToAdd; |
| 538 | } |
| 539 | } |
| 540 | this.setState({ |
| 541 | addedHeightByClick: Math.abs(row - this.state.addedSRowClick) + 1, |
| 542 | addedWidthByClick: Math.abs(col - this.state.addedSColClick) + 1, |
| 543 | map: map, |
| 544 | }); |
| 545 | } |
| 546 | } else if (this.state.isMousePressed) { |
| 547 | this.updateWall(row, col); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | handleMouseUp(row, col) { |