Skip to content

Instantly share code, notes, and snippets.

@nyurik
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyurik/0b68755ed1651105cabf to your computer and use it in GitHub Desktop.
Save nyurik/0b68755ed1651105cabf to your computer and use it in GitHub Desktop.

Write a simple game similar to snake.

Gameplay

When a user opens the page in their browser, it should display an empty playing field with a board, current score (0), a start button, and a list of top ten past scores.

  • The game field is surrounded by a border
  • The snake starts in a fixed position (e.g. the center or one of the corners of the game field)
  • The snake grows indefinitely, with its tail fixed at the starting position
  • The direction of the snake is controlled with the arrow keys
  • There are no items to "eat" on the field, just an empty space with the growing snake
  • The game ends when the snake hits the field's border or its own tail
  • There should be a button to start/restart the game
  • There should be some point system, e.g. the length the snake has grown shown to the player
  • There should be a table of the top 10 scores somewhere on the screen

Implementation Details

  • Keep it very simple
  • It should be playable on modern mobile browsers (Chrome, Firefox).
  • No server-side code is needed.
  • Please do NOT use canvas - all layout should be done with HTML elements like table cell or divs.
  • Use JavaScript (not CoffeeScript, TypeScript or other languages that compile to JavaScript).
  • Keep the code light. You can use basic JavaScript libraries (jQuery/Zepto), but not any libraries designed for games.
  • The assignment will be evaluated on the visual style of the game, playability, how well you structure your code, good use of OOP and data structures, and overall HTML5 and CSS usage.
  • Start simple and leave improvements for later. You should be able to have something working in 2-3 hours.
  • Try to write the code in such a way that it's modular and easily testeable (you can do a bit of TDD too), e.g. try to separate the game logic from the UI.
  • The best scores should be persisted in the local storage

Bonus Points

If you have some extra time, there could be two snakes on the same field at once, controlled by two different sets of keys (e.g. arrows vs ASDW keys), which would let two players compete. Other potential improvements may even include an AI to compete with the human player.

Licensing

Your code submission should be licensed as CC-BY, MIT/BSD, or other similar open source license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment