npm install
npm start
Then open localhost:8080.
Use the LEFT, UP, RIGHT, DOWN arrow keys to control the direction of the snake
- Game will not stop till the snake is killed.
- Snake will be killed if it hits any side of the walls or its own body.
- Each time food is captured the snake grows and the score increases.
The APP starts in main.js
by importing dependencies and initializing them.
Later we loop the game and kill it if the rules are not followed.
All the modules basically export public-consuming APIs.
- Board - this basically deals with drawing repsonsibility for the APP. Any thing that needs to be drawn will be delegated to this module.
- Snake - deals with the state management of the Snake at any given time.
- Food - deals with the state management of the food, responsible creating food
- helpers - these functions abstract out certain logic which does not involve any module dependency.
- utils - any code that may be used across.
- config - this takes care of providing for the initializing the modules, may come from any JSON later
- constants - app wide constants
- Logger - used to display score
- Unless any context binding is needed, functions are written as arrows
- Generate dynamically a snake body each time a game starts (now its a constant).
- Increase the pace when the score increases.
- can we avoid setInterval? any other mechanism to loop the game.