Created
October 2, 2017 07:36
-
-
Save ysfzrn/6abf01d3e86302d65b03f561ac0d5d6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//src/stores/gameStore.js | |
... | |
class GameStore{ | |
... | |
@action("Snake is moving") | |
handleMoveSnake =() => { | |
... | |
//isGameOver control | |
for(let i = 1; i < this.snake.slice().length; i++){ | |
if(this.snake[0].x === this.snake[i].x && this.snake[0].y === this.snake[i].y ){ | |
if( this.score > this.highScore ){ | |
AsyncStorage.setItem('snakeHighScore', JSON.stringify(this.score)); | |
} | |
cancelAnimationFrame(this.handleMoveSnake); | |
NavigationStore.handleChangeRoute('gameOverScreen'); | |
clearTimeout(globalID); | |
return; | |
} | |
} | |
globalID = setTimeout(()=>{ | |
requestAnimationFrame(this.handleMoveSnake); | |
}, 1000 / this.intervalRate); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment