]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
buttons with all directions
authorVladislav Skukov <v.skukov@gmail.com>
Sun, 19 May 2019 04:31:22 +0000 (09:31 +0500)
committerVladislav Skukov <v.skukov@gmail.com>
Sun, 19 May 2019 04:31:22 +0000 (09:31 +0500)
src/Game.js
src/GameController.js

index c4d46e2f00f4732d1ff589000fb1c53ae04d3cfc..5ddf95ea92c76a3dadf2b6d37f253c0369e67d8b 100644 (file)
@@ -52,8 +52,47 @@ export class Game extends Component {
     });
   };
 
-  move = () => {
-    this.gameController.goForward().then(() => {
+  moveNorth = () => {
+    this.gameController.goNorth().then(() => {
+      this.setState({
+        tips: this.handleVarlamov(this.gameController.tips())
+      })
+    }).catch(error => {
+      this.notification.show(
+        'Что-то сломалось, зовите разраба',
+        error && JSON.stringify(error)
+      );
+    });
+  };
+
+  moveWest = () => {
+    this.gameController.goWest().then(() => {
+      this.setState({
+        tips: this.handleVarlamov(this.gameController.tips())
+      })
+    }).catch(error => {
+      this.notification.show(
+        'Что-то сломалось, зовите разраба',
+        error && JSON.stringify(error)
+      );
+    });
+  };
+
+  moveSouth = () => {
+    this.gameController.goSouth().then(() => {
+      this.setState({
+        tips: this.handleVarlamov(this.gameController.tips())
+      })
+    }).catch(error => {
+      this.notification.show(
+        'Что-то сломалось, зовите разраба',
+        error && JSON.stringify(error)
+      );
+    });
+  };
+
+  moveEast = () => {
+    this.gameController.goEast().then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips())
       })
@@ -111,8 +150,23 @@ export class Game extends Component {
                   </Button>
                 </div>
                 <div className="Get-button">
-                  <Button onClick={this.move} size="medium">
-                    Пройти дальше
+                  <Button onClick={this.moveWest} size="medium">
+                    Пройти к западу
+                  </Button>
+                </div>
+                <div className="Get-button">
+                  <Button onClick={this.moveNorth} size="medium">
+                    Пройти к северу
+                  </Button>
+                </div>
+                <div className="Get-button">
+                  <Button onClick={this.moveSouth} size="medium">
+                    Пройти к югу
+                  </Button>
+                </div>
+                <div className="Get-button">
+                  <Button onClick={this.moveEast} size="medium">
+                    Пройти к востоку
                   </Button>
                 </div>
               </div>
index 7ad696e3d0b5c1d8a92b52d2951c53ffd2a47a3a..0546f29fc8bc708d20ff3b411bb02b306dbf0e12 100644 (file)
@@ -18,12 +18,30 @@ export class GameController {
     });
   }
 
-  goForward() {
+  goNorth() {
+    return api.post(`/games/${this.gameId}/move/north`).then(json => {
+      this._tips = json.data.tips;
+    })
+  }
+
+  goWest() {
+    return api.post(`/games/${this.gameId}/move/west`).then(json => {
+      this._tips = json.data.tips;
+    })
+  }
+
+  goSouth() {
     return api.post(`/games/${this.gameId}/move/south`).then(json => {
       this._tips = json.data.tips;
     })
   }
 
+  goEast() {
+    return api.post(`/games/${this.gameId}/move/east`).then(json => {
+      this._tips = json.data.tips;
+    })
+  }
+
   tips() {
     if(!this._tips) {
       return [];