()
| 217 | } |
| 218 | |
| 219 | playAnimation() { |
| 220 | this.setState({ isAnimationFinished: false }); |
| 221 | var finishTime = 0; |
| 222 | const paths = this.state.paths; |
| 223 | for (var t = 0; t < paths.length; t++) { |
| 224 | finishTime = Math.max(finishTime, paths[t].length); |
| 225 | } |
| 226 | for (let t = 0; t < finishTime; t++) { |
| 227 | setTimeout(() => { |
| 228 | let map = this.state.map; |
| 229 | for (let i = 0; i < map.length; i++) { |
| 230 | for (let j = 0; j < map[i].length; j++) { |
| 231 | map[i][j].isStart = false; |
| 232 | map[i][j].agent = -1; |
| 233 | map[i][j].color = ""; |
| 234 | } |
| 235 | } |
| 236 | for (let i = 0; i < paths.length; i++) { |
| 237 | let loc = this.decodeLocation(paths[i][paths[i].length > t ? t : paths[i].length - 1]); |
| 238 | map[loc.r][loc.c].isStart = true; |
| 239 | map[loc.r][loc.c].agent = i + 1; |
| 240 | map[loc.r][loc.c].color = this.state.agents[i].color; |
| 241 | } |
| 242 | this.setState({ map: map }); |
| 243 | }, 1000 * t * this.state.speed); |
| 244 | } |
| 245 | setTimeout( |
| 246 | () => this.setState({ isAnimationFinished: true }), |
| 247 | 1000 * finishTime * this.state.speed |
| 248 | ); |
| 249 | } |
| 250 | |
| 251 | changeMapRow(e) { |
| 252 | let t = parseInt(e.target.value); |
no test coverage detected