MCPcopy
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / handleClickBox

Method handleClickBox

assets/js/15puzzle.js:143–168  ·  view source on GitHub ↗
(box)

Source from the content-addressed store, hash-verified

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;

Callers 1

renderMethod · 0.95

Calls 4

setStateMethod · 0.95
swapBoxesFunction · 0.85
isSolvedFunction · 0.85
getNextdoorBoxesMethod · 0.80

Tested by

no test coverage detected