Not to be unappreciative of this cool demo, but here's a snake game I wrote a while ago that clocks in at 41 "commented lines" of code, and minifies to under 1KB of code whilst including setting up the DOM and CSS (which is counted separately here), and features such as pausing and aging food:
I really like this whole concept of using small projects like this and the spreadsheet thing to create simple, yet elegant apps.
I wonder if this could be a good method for teaching technologies like CSS, JS, and HTML? If you think about it, there isn't a lot of code here, so it would be easy for a student to go through it line by line and end up learning a lot.
There's an annoying bug where you lose if you tap the button to go opposite the direction in which you're heading. e.g. if you're heading right and you tap left, you lose.
There is a bug where if you move into a space where your tail was but no longer is, you die. Essentially, the check for gameover needs to be after you move the snake.
27 comments
[ 4.4 ms ] story [ 36.5 ms ] threadProof of concept apps in few lines of code might be cool, but the devil is in the details. The last 10% takes 90% of the time.
http://chengsun.github.io/snake.html
I wonder if this could be a good method for teaching technologies like CSS, JS, and HTML? If you think about it, there isn't a lot of code here, so it would be easy for a student to go through it line by line and end up learning a lot.
Demo: http://tomocchino.github.io/react-snake/
Source (150 lines): https://github.com/tomocchino/react-snake/blob/master/src/sn...
[1] http://facebook.github.io/react/blog/2013/07/02/react-v0-4-a...
You can also take the advantage of getDefaultProps() instead of doing `this.props.something || 12` everywhere.
Easy one line fix for this: need to check if new dx / dy is opposite the old dx / dy and use the old one if so.
I also added another fix to disallow moving twice during one cycle.This one has three operations in one line:
My attempt, 31 lines (although some of them are quite long :) http://jsfiddle.net/8Rqcy/5/
Has score counting, restarts, walls, you can't go back on yourself, and speed increases.