Javascript Snake

April 21st, 2008 by patorjk

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.




Posted in General News, Software

7 Responses

  1. Awesome AnDrEw

    Snake is always entertaining, and I remember your Flash-based version, which was pretty cool.

  2. patorjk

    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.

  3. Awesome AnDrEw

    Why can’t you make a change to it? Unless you obfuscated it you can still decompile it and retrieve all the ActionScript bytecode.

  4. patorjk

    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.

  5. Awesome AnDrEw

    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.

  6. patorjk

    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.

  7. Awesome AnDrEw

    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).

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Subscribe without commenting