(box)
| 141 | } |
| 142 | |
| 143 | handleClickBox(box) { |
| 144 | return function () { |
| 145 | const nextdoorBoxes = box.getNextdoorBoxes(); |
| 146 | const blankBox = nextdoorBoxes.find( |
| 147 | (nextdoorBox) => this.state.grid[nextdoorBox.y][nextdoorBox.x] === 0 |
| 148 | ); |
| 149 | if (blankBox) { |
| 150 | const newGrid = [...this.state.grid]; |
| 151 | swapBoxes(newGrid, box, blankBox); |
| 152 | |
| 153 | if (isSolved(newGrid)) { |
| 154 | clearInterval(this.tickId); |
| 155 | this.setState({ |
| 156 | status: 'won', |
| 157 | grid: newGrid, |
| 158 | move: this.state.move + 1, |
| 159 | }); |
| 160 | } else { |
| 161 | this.setState({ |
| 162 | grid: newGrid, |
| 163 | move: this.state.move + 1, |
| 164 | }); |
| 165 | } |
| 166 | } |
| 167 | }.bind(this); |
| 168 | } |
| 169 | |
| 170 | render() { |
| 171 | const { grid, move, time, status } = this.state; |
no test coverage detected