Snake game with solver API for JS beginners to learn programming. Start node solvehere.js
to see a random function performing.
default: false
You can set this to either true or false to toggle the display of the grid in the console. Devmode makes sure the grid doesn't get displayed so you can output your console log by hand.
default: 20
Time between gamesteps in ms.
###game.setInputFunction(function inputFunction)
Should be called with an inputFunction that returns either "r", "l", "u" or "d" for right, left, up, down respectively. inputFunction will receive a game object as a parameter, with the following properties:
int width
int height
array grid
Array of Arrays, with each parent array representing a row and containing another array of column fields.
Fields will be either 0, 1 or 2, representing nothing, a piece of your snake and a piece of fruit respectively.
array snake
Array of objects: {x: xPosition, y: yPosition}. The earliest entry is the tail, the last the head.
Changes made to this object will not result in changes to the game.
Should be called when you want to do something when one of the following events happens:
- beforeStep
- afterStep
- afterInit
- failed
Will receive the same game object as your inputFunction.
Clears all event listeners for the given event.
Initializes the game board with height and width (both >=20).
Starts the game.
Pauses the game.
Will log all messages you provide it with to display under Log data, in case you want to display log data while showing the grid. Messages will be collected per gamestep and displayed as follows:
message1 | message2 | message3[| nextmessage ]
Clears the console, draws the gameboard.