Add reset button

This commit is contained in:
2022-01-05 22:10:04 +01:00
parent 0e8eb7b767
commit c7f82769e3
4 changed files with 32 additions and 1 deletions

View File

@@ -31,14 +31,18 @@ class Backend {
getAvailableMoves(position) {
return post_json("http://localhost:3000/get_moves/", position);
}
reset() {
return post_json("http://localhost:3000/reset/");
}
}
class Chess {
constructor() {
this.backend = new Backend();
this.canvas = new visuals.Canvas();
this.button = document.createElement("button");
this.autoplay = false;
this.button = document.createElement("button");
this.button.innerHTML = "Autoplay Off";
this.button.onclick = () => {
this.autoplay = !this.autoplay;
@@ -47,6 +51,15 @@ class Chess {
];
};
document.body.appendChild(this.button);
this.resetButton = document.createElement("button");
this.resetButton.innerHTML = "Reset";
this.resetButton.onclick = () => {
this.backend.reset();
this.updateState();
};
document.body.appendChild(this.resetButton);
this.configVis = new visuals.ConfigVis(this.backend.getConfig());
this.configVis.draw(this.canvas);
this.activeSquares = new visuals.ActiveSquares();