rewriting labyrinth game in javascript