Skip to content

Instantly share code, notes, and snippets.

@ysfzrn
Created October 2, 2017 07:27
Show Gist options
  • Save ysfzrn/f3dce7cd01cd90a83c2034c5d14ba7e0 to your computer and use it in GitHub Desktop.
Save ysfzrn/f3dce7cd01cd90a83c2034c5d14ba7e0 to your computer and use it in GitHub Desktop.
// src/stores/gameStore.js
class GameStore {
...
@observable food = { x: 50, y: 50 }; //elmanın başlangıçta belireceği yer.
...
@action("make food")
handleMakeFood() {
const frameX = (boardWidth -10) / segmentRate;
const frameY = BoardHeight / segmentRate;
this.food.x = this.getRandomInt(0, frameX) * segmentRate;
this.food.y = this.getRandomInt(0, frameY) * segmentRate;
}
getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment