Skip to content

Instantly share code, notes, and snippets.

@ysfzrn
Created October 2, 2017 07:36
Show Gist options
  • Save ysfzrn/6abf01d3e86302d65b03f561ac0d5d6f to your computer and use it in GitHub Desktop.
Save ysfzrn/6abf01d3e86302d65b03f561ac0d5d6f to your computer and use it in GitHub Desktop.
//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