Writing JS implementation of game