FunSnake

Snake Game using F# & FunScript

Controls: 'a': Left / 'w': Top / 's': Down / 'd': Right
Press any direction key ('a','w','s','d') to start

FunSnake is the snake game written in F # and converted to javascript using FunScript. Thanks to F # the game logic is written in about 150 lines of code that are clear and concise thanks to the expressiveness of the language

Code extracts

The next Gist shows some interesting pieces of code. Complete source code can be found in GitHub.

  • The KeyboardEventsStartGame code, contains the main function where keyboard event listener are handled and the first call to the recursive update function.
  • In the next code, SnakeMove, are the functions that move the snake to the next position
  • Finally, the SnakeUpdateGame shows then update function that move the snake, create the food and detect collisions with the walls or itsef.