Javascript Snake
During my senior year of high school I took an independent study course in C++. Originally it had been a full fledged C++ course with a teacher and everything, but since only 4 students signed up, they had us all do independent study projects instead. Independent study courses at my school worked by allowing you to work by yourself to create some project that you would then present to some committee to show that you had learned some stuff.
The only problem with this was that we had no text books, no access to any compilers of any kind, and no authority figure who really knew anything about computers. The lady who was in charge of the school’s computer labs (referred to behind her back as “The Troll Lady”) was mean and irrational.
She forbid us to use the c++ compilers that were available in the upstairs computer lab because they were “too old” (we weren’t even allowed access to that lab). We also weren’t allowed to install stuff on the computers in the downstairs lab. So we were basically left with no way to do anything c++ related at school, unless we wanted to sit and read the books we had purchased ourselves. To make things worse, we didn’t really get along. Since our school was more arts/drama oriented, the kids who were good at computers tended to be kind of snobby. The kind that would call you an idiot for not knowing some obscure unix fact.
I digress though. The only reason I mention all of this is because this is when I discovered the game of Snake. Since I couldn’t do anything programming-related, I’d just sit and play Flash or Java games for the first hour and a half of the school day (we had block scheduling).
Basically I’d come in, watch Flash videos from NewGrounds, and then horse around on the different internet games I was able to find. Snake ended up being my favorite. I honestly sucked at it then and still suck at it now, but it was pretty mindless and actually pretty fun. Years later I’d implement my own version in Flash (which used to be featured at this site).
Anyway, a couple of days ago I was working on some other Javascript project for this site when I randomly started thinking about the olden days. After remembering how much I loved Snake I thought to myself “Hrm, I bet I could write a version of Snake entirely in Javascript”. Since Snake is such a simple game, I decided to run with the idea and try and crank out a Javascript version as quick as possible. You can see what I’ve got so far by following the below link:
http://patorjk.com/games/snake
That is fresh from my hard drive, and it’s a really bare bones version. I hope to add a couple more features and to optimize it some over the next week. Since Javascript is interpreted, the game may be a little jumpy on some of your computers (let me know if you have any major problems). When it’s totally done I’ll probably also post the source as a Javascript example. You could peak at it right now if you wanted, but it’s in a not-ready-for-prime-time state right now.
As an aside, under the hood the snake is a linked list. I googled “Javascript linked list” for some quick linked list code and came across this link, which is actually pretty nifty. It’s worth a look if it’s been a while since you’ve done anything with linked lists.
TAAG
TAAG was updated with a couple of fonts (they all start with “JS”) and I fixed up the feature that allows you to share messages you create with others.
Snake is always entertaining, and I remember your Flash-based version, which was pretty cool.
Thanks. The Flash version actually still works over at archive.org. I thought about posting it here, but then decided against it since I knew that not being able to ever make a change to it might make me a little crazy.
Why can’t you make a change to it? Unless you obfuscated it you can still decompile it and retrieve all the ActionScript bytecode.
I could, but if it doesn’t return my original code, reading the decompiled code would be a pain in the butt. That is an intriguing option though, I may look into it.
Have you tried flasm? I’ve never really done too much work with Flash or ActionScript, and I know that these days a lot of people obfuscate their code so it is more difficult to properly decompile, but on every Flash file I have viewed with the tool I was able to retrieve each statement without any difficulty.
Hrm, it doesn’t look like it’s a real decompiler, I’ll look into it more though. It sounds interesting from the tidbits I read on it.
There’s always the SoThink SWF decompiler, which will allow you to export all the objects as well (audio, video, sprites, ActionScript, et cetera), but it’s not free (wink wink).
you could really learn modern javascript programming. Instead of using milions of div’s you can use only number of divs required to construct a snake and apply them position: absolute. Then you can move them around with top and left css style. the primer is my website.
btw, noone really cares about the old days. new days are here, and they are here to stay
tramak – I can’t decide whether you’re trying to be helpful or whether you’re trying to be a dick. The way you worded your comment seems a little condescending. I appreciate friendly advice, but I’m not really sure that’s what the aim of your comment is.
What is your definition of “modern javascript programming”? And what is your main issue, that I have a set up where each block of the snake is its own div (pulled from a pool of 2,000 divs – not millions) rather than having a set up where the snake is drawn with the least number of divs?
I picked the implementation I did because I knew it’d be easy to implement and work with. Other than a possible improvement in load time (which I don’t think is that bad currently), I don’t really see a compelling reason to go back and change how the snake is drawn.
I should also add that my snake is much more responsive than your snake. Try creating a stair case effect with the snakes for the full length of the board (rapidly pressing the Left Arrow and then the Up Arrow). I can easily create the effect with my snake, but I cannot get your snake to do it for the full length of the board.
I love playing your Snake game and Snake games in general. It’s a simple concept but really addictive just like other classic games from Space Invaders to Pacman. Modern games are rubbish! LOL
Hi
Very ver Thanks For Play Snake
But
please give me link for Project’s Javascript Snake
Please Send Email me
jave games are so cool eventhough they do not have fancy graphics.~*`
java games are cool because they need very little resources and the graphics are good too.,**