Snake game using Vanilla Javascript

Indie Dev
Oct 23, 2021

--

Warm up a day by building classic games

For this snake game, I tried to separate code into 3 layers

  • UI: Render the Board/Food/CSS.
  • State Management: Manage the current Snake/Food/Board, update the state whenever user changes direction/move
  • Game Loop

For the state management, I follow the Redux style. Whenever the state changes, it will notify to the listeners (UI rendering)

Then we will implement the logic of the snake reducer

The UI renderer can be any library you want — React/Vanilla Javascript.

In the Game Loop, we will wrap everything to get the game ready

With this approach, we can replace the Game/UI by the React or Veu or any UI library that you want — even a console.

I am following the clean architecture here.

  • The snakeReducer is the Domain business.
  • The store is infrastructure
  • The UI/Game is the outside world

--

--

Indie Dev
Indie Dev

No responses yet