DEV Community

Discussion on: Learn Javascript through a Game

Collapse
stealthmusic profile image
Jan Wedel

Great game you did there and nice post! Snake was the big thing on the first Nokia phones I used and I learned programming by changing the code of Nibbles, a snake clone shipped with QBasic.

A couple of minor ideas to improve the readability of the code:
A function that check collisions should probably not be called “die” or “eat”. I would suggest to create an abstraction that allows something like that:

if( snake.collidesWith(food) )        {snake.eat(food)}
Enter fullscreen mode Exit fullscreen mode

This may appear as an unnecessary separation but separation of concerns really help to maintain and read code.

Collapse
soupaul profile image
Souparno Paul Author • Edited

True. I thought about writing a function for collisions but decided against using the formal term. Collision detection is a big part of game development and I hope to address it in a different article. Great that you created the game using QBasic, which coincidentally also turns out to be the first programming language I learnt.