Jump to content

My first game! I wrote Snake with Javascript and HTML tables


cake
 Share

Recommended Posts

post-11540-0-63376300-1415492193.png

 

Hello!

I used to mess around with coding way back in high school but never really went anywhere with it.  I've decided to give it another shot and I'd like to make writing games into a serious hobby.  I've spent my free time over the last month teaching myself some basics and not-so-basics of javascript with the help of Eloquent Javascript.  I've just finished the Platform Game chapter, and figured I had enough knowledge to try writing a simple game from scratch.

So, here is my shot at writing Snake, using Javascript and DOM elements for graphics. 

 

SimpleSnake.zip

 

I would appreciate some feedback, especially on these specific points:

  • the game uses global variables which I'm quickly learning are very very not good practice.  This being my first game, I decided to keep it simple and just get the game to work without worrying about proper modularization, which I'm still having trouble understanding.  I'd like to write my next game properly though, and I'd appreciate some examples of how modularization is usually done for games.
  • I've used 'setInterval' to animate the game which seems crude, and obviously wouldn't work for a more complex game.  What are some more elegant ways of animating a game?  The Platform Game chapter of Eloquent JS demonstrates a method of game animation using 'requestAnimationFrame' that I haven't fully wrapped my head around yet.  Do most games use something similar to the animation code he used?
  • There's something about the amount of times I wrote 'this.' that looks wrong to me.  I feel like my Level object has too many variables and too many methods (including many that call other methods) but I'm unsure of how I would break things up more elegantly.

 

 

side note: sorry about the attached zip file, I know it's not the ideal way to share a game.  I've recently purchased a domain name, and now I'm in search of a good web-host I can use to upload games.  Any recommendations?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...