Posted in Uncategorized

JS Post 2 – Retro Snake Game ⊙_ʘ

I have always had a liking to the snake game maybe it is cause it is pretty easy to program? I know programming the game is pretty simple and here is something that I did on a whim. not much but it was satisfactory?

It uses arrow keys to control the snake movement, as far as I have managed to play the snake movement and growth is logical. And when the snake dies the scores are displayed along with an option to play again which I felt was good enough.Maybe I’ll add another script here that makes use of a mouse click?

But that was not all that I wanted. Cause when I went around searching for retro snake game, this gif popped up and wow I never knew that one can possibly win a Snake game. (I am not sure if I have added code for the boss level player in my snake game…)

This gif had me thinking and no matter what angle I look at it I don’t think it was a human that played and even if it wasn’t a human the way that the snake moved about in about 3 places during the game made me realize that it would be easier to presume that a human played than the alternative that it was coded.

According to a number of comments the final screen reads:

“And now we’ll show you a cartoon. Connecting to server … No connection. Thanks. Everybody’s free to go.”

I hope my thoughts are clearly conveyed. I want to code an algorithm to crack a snake game (at the moment language dependent until I get a grip on the flow of things.). And I say I want to cause I haven’t done one… yet. I know I have been mentioning about my exams too frequently (that are still going on ,unfortunately..*sigh)  , But it was because of that ,that I willed myself to stop thinking about a way to solve a snake game using AI like the one in this site.

ლ(ಥ  ಥ )ლ

Okay so that being provided, here’s something similar to last time that I made for the blog:

.
.
.

Click anywhere on the blog page !!! 
(almost anywhere I think?It works on touch screen devices also!!!)

☜(ಥಥ)☞

// <![CDATA[ var smokeyness=200; // how much smoke is on the screen (more will slow the script down) var density=80; // how 'big' is the smoke var swide=800; var shigh=600; var toke=new Array(); var tokex=new Array(); var tokedx=new Array(); var tokey=new Array(); var nicotine=new Array(); var mousedown=false; var x=400; var y=300; var sleft=sdown=0; var ie_version=(navigator.appVersion.indexOf("MSIE")!=-1)?parseFloat(navigator.appVersion.split("MSIE")[1]):false; function addLoadEvent(funky) { var oldonload=window.onload; if (typeof(oldonload)!='function') window.onload=funky; else window.onload=function() { if (oldonload) oldonload(); funky(); } } addLoadEvent(puff); function puff() { if (document.getElementById) { var i, fag; for (i=0; i<smokeyness; i++) { fag=document.createElement("div"); toke[i]=fag.style; toke[i].position="absolute"; toke[i].backgroundColor="transparent"; toke[i].font="bold "+density+"px Tahoma, Geneva, sans-serif"; toke[i].color="rgba(234,234,234,0.033)"; toke[i].zIndex="9999"; toke[i].pointerEvents="none"; toke[i].visibility="hidden"; fag.appendChild(document.createTextNode(String.fromCharCode('0x25CF'))); document.body.appendChild(fag); tokey[i]=false; } set_scroll(); set_width(); setInterval(drag, 50); }} function drag() { var c; if (mousedown) for (c=0; c<smokeyness; c++) if (tokey[c]===false) { toke[c].left=(tokex[c]=x-density/2)+"px"; toke[c].top=(tokey[c]=y-density)+"px"; toke[c].visibility="visible"; tokedx[c]=(c%2?1.5:-1.5)*Math.random(); nicotine[c]=80; break; } for (c=0; csdown-density*2 && tokex[i]>sleft && tokex[i]<sleft+swide-density && (nicotine[i]+=2)<256) { cancer=nicotine[i].toString(16); cancer="#"+cancer+cancer+cancer; if (ie_version && ie_version0) sw_min=document.documentElement.clientWidth; if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight; } if (typeof(self.innerWidth)==’number’ && self.innerWidth) { if (self.innerWidth>0 && self.innerWidth0 && self.innerHeight0 && document.body.clientWidth0 && document.body.clientHeight
Update:
Link to a video

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s