./www/0000755000000000000000000000000012216074015010533 5ustar rootroot./www/cgi-bin/0000755000000000000000000000000012251404306012042 5ustar rootroot./www/cgi-bin/test.pl0000755000000000000000000000020712216074743013371 0ustar rootroot#!/usr/bin/perl use CGI; $req = new CGI; print $req->header(); print $req->start_html(); print $req->p(`id`); print $req->end_html(); ./www/cgi-bin/data/0000777000000000000000000000000012251404270012757 5ustar rootroot./www/cgi-bin/index.pl0000755000000000000000000000460212251404074013515 0ustar rootroot#!/usr/bin/perl use CGI; use CGI::Session; use DBI; use Digest::MD5; sub MD5 { $h = Digest::MD5->new; $h->add($_[0]); return $h->hexdigest; } sub Main { $title = "Personal Area"; $req = new CGI; $db = DBI->connect("dbi:mysql:snake", "daniel", "E9nENHbtkG"); if ($req->param('submit')) { $login = $req->param('login'); $password = MD5($req->param('password')); $sth = $db->prepare("SELECT * FROM users WHERE login = ? AND password = ?"); $sth->execute($login, $password); if ($sth->fetchrow_array()) { $session = new CGI::Session(); $session->param('login', $login); print $session->header(-location=>'index.pl'); } else { print $req->header(); print $req->start_html($title); print $req->h1('Wrong login/password!'); print $req->end_html(); } exit; } $session = CGI::Session->load(); if ($req->param('act') eq 'logout') { $session->delete(); print $session->header(-location=>'index.pl'); exit; } print $req->header(); print $req->start_html($title); if ($session->is_empty) { print $req->b('Auth please'); print $req->startform; print $req->textfield(-name=>'login'); print $req->br; print $req->textfield(-name=>'password'); print $req->br; print $req->submit(-name=>'submit', -value=>'OK', -action=>"index.pl", -method=>"POST"); print $req->endform; print $req->a({href => 'register.pl'}, "Register"); } else { $login = $session->param('login'); print $req->p('Hello, '.$login.'!'); if ($req->param('ip')) { $file = './data/'.MD5($login)."/".$req->param('ip'); if (-e $file) { open FILE, $file; $html = ''; while () { $html .= $_; } close(FILE); print $req->start_table({border=>1}); print $req->Tr($req->th(['Date', 'Score'])); print $html; print $req->end_table(); print $req->a({href=>'index.pl'}, 'Back'); } else { print $req->h1('Error'); } } else { print $req->p('Here you can view information about your games from any IP'); opendir DIR, './data/'.MD5($login); print $req->start_table({border=>1}); while ($file = readdir(DIR)) { if ($file =~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) { print $req->Tr($req->td([$req->a({href => "index.pl?ip=".$file}, $file)])); } } print $req->end_table(); print $req->br; print $req->a({href=>'index.pl?act=logout'}, 'Logout'); } } print $req->end_html(); } Main(); ./www/cgi-bin/save.pl0000755000000000000000000000143412251404171013342 0ustar rootroot#!/usr/bin/perl use CGI; use DBI; use Digest::MD5; sub MD5 { $h = Digest::MD5->new; $h->add($_[0]); return $h->hexdigest; } sub Main { $req = new CGI; $ip = $req->remote_host(); if ($req->http('HTTP_X_FORWARDED_FOR')) { $ip = $req->http('HTTP_X_FORWARDED_FOR'); } print $req->header(); print $req->start_html('Save score'); $hash = $req->param('hash'); $score = int($req->param('playerScore')); $nick = $req->param('playerName'); $key = "pc8XW2xUJcWMFVGkZ5PL"; if ($nick ne '' & MD5($score.$nick.$key) eq $hash) { $ok = 1; open(FILE, ">>", "./data/".MD5($nick)."/".$ip) || ($ok = 0); if ($ok) { $time = scalar localtime(); print FILE "".$time."".$score."\n"; close(FILE); } } print $req->end_html(); } Main(); ./www/cgi-bin/register.pl0000755000000000000000000000244712216075636014250 0ustar rootroot#!/usr/bin/perl use CGI; use DBI; use Digest::MD5; sub MD5 { $h = Digest::MD5->new; $h->add($_[0]); return $h->hexdigest; } sub Main { $title = "Personal Area"; $req = new CGI; $db = DBI->connect("dbi:mysql:snake", "daniel", "E9nENHbtkG"); print $req->header(); print $req->start_html($title); if ($req->param('submit')) { $login = $req->param('login'); $password = MD5($req->param('password')); if ($login ne '' & $password ne '') { $sth = $db->prepare("SELECT * FROM users WHERE login = ?"); $sth->execute($login); if ($sth->fetchrow_array()) { print $req->h1('Username already exists!'); } else { $sth = $db->prepare("INSERT INTO users VALUES (?, ?)"); $sth->execute($login, $password); mkdir './data/'.MD5($login); print $req->h1('Registered successfully!'); } } else { print $req->h1('Error'); } } else { print $req->b('Register'); print $req->startform; print $req->textfield(-name=>'login'); print $req->br; print $req->textfield(-name=>'password'); print $req->br; print $req->hidden(-name=>'act', -value=>'register'); print $req->submit(-name=>'submit', -value=>'ok', -action=>"index.pl", -method=>"POST"); print $req->endform; print $req->br; print $req->a({href => 'index.pl'}, "Back"); } print $req->end_html(); } Main(); ./www/css/0000755000000000000000000000000012022717562011331 5ustar rootroot./www/css/snake.css0000755000175000017500000000411012216002154014060 0ustar ubuntuubuntu/* JavaScript Snake By Patrick Gillespie http://patorjk.com/games/snake */ body { margin:0px; padding:0px; } #game-area { margin:0px; padding:0px; } #game-area:focus { outline: none; } a.snake-link, a.snake-link:link, a.snake-link:visited { color: #FCFC54; } a.snake-link:hover { color: #FfFf54; } .snake-panel-component { position: absolute; font-family: Verdana, arial, helvetica, sans-serif; font-size: 14px; color: #ffffff; text-align: center; background-color: #FC5454; padding: 8px; margin: 0px; } .snake-snakebody-block { margin: 0px; padding: 0px; background-color: #FF0000; position: absolute; border: 0px solid #000080; background-repeat: no-repeat; } .snake-snakebody-alive { background-image: url('./images/snakeblock.png'); } .snake-snakebody-dead { background-image: url('./images/deadblock.png'); } .snake-food-block { margin: 0px; padding: 0px; background-color: #FF0000; border: 0px solid #000080; position: absolute; } .snake-playing-field { margin: 0px; padding: 0px; position: absolute; background-color: #0000A8; border: 0px solid #0000A8; } .snake-game-container { margin: 0px; padding: 0px; border-width: 0px; border-style: none; zoom: 1; background-color: #FC5454; position: relative; } .snake-welcome-dialog { padding: 8px; margin: 0px; background-color: #000000; color: #ffffff; font-family: Verdana, arial, helvetica, sans-serif; font-size: 14px; position: absolute; top: 50%; left: 50%; width: 300px; height: 150px; margin-top: -100px; margin-left: -158px; text-align: center; display: block; } .snake-try-again-dialog { padding: 8px; margin: 0px; background-color: #000000; color: #ffffff; font-family: Verdana, arial, helvetica, sans-serif; font-size: 14px; position: absolute; top: 50%; left: 50%; width: 300px; height: 100px; margin-top: -75px; margin-left: -158px; text-align: center; display: none; }./www/css/images/0000755000175000017500000000000012022717562013526 5ustar ubuntuubuntu./www/css/images/snakeblock.png0000755000175000017500000000016712022717562016357 0ustar ubuntuubuntu‰PNG  IHDRыŠZgAMAБ ќa.IDAT8Ocd`XС@XёчObыЈfЂo4Рˆ*Hr АЁ`р#a… Ч Џ4IENDЎB`‚./www/css/images/deadblock_border.png0000755000175000017500000000016512022717562017506 0ustar ubuntuubuntu‰PNG  IHDRыŠZgAMAБ ќa,IDAT8OcќТ@6j>@й:Њ™„  0 Єt4Р†Z€cŒ<"о6Г ,ЁIENDЎB`‚./www/css/images/Thumbs.db0000755000175000017500000000700012022717562015277 0ustar ubuntuubuntuаЯрЁБс>ўџ ўџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџ§џџџўџџџўџџџўџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџRoot EntryџџџџџџџџРцЎsыВШ€1џџџџџџџџТCatalogџџџџџџџџџџџџ\џџџџџџџџџџџџ ўџџџўџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџ ЖџиџрJFIF``џлC     џлC   џР`"џФ џФЕ}!1AQa"q2‘Ё#BБСRб№$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™šЂЃЄЅІЇЈЉЊВГДЕЖЗИЙКТУФХЦЧШЩЪвгдежзийкстуфхцчшщъёђѓєѕіїјљњџФ џФЕw!1AQaq"2B‘ЁБС #3R№brб $4с%ё&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™šЂЃЄЅІЇЈЉЊВГДЕЖЗИЙКТУФХЦЧШЩЪвгдежзийктуфхцчшщъђѓєѕіїјљњџк ?§ ёЬ:ЬšЭСЖ“WXŠFА‹ G;‰йќYуšЩ—Oерв-пˆцО•ВФ5Ц"_NœŸўПЅP5†ЏoЄFыФs_Jw1 qˆ—гЇ'џЏEЭ†Б• Чuт9Џd;ƒ\b1§оњўдQ@ uaЋлщp$W^#žђCКG qˆЧїGњўд—ЖНОpнxŽ{ЗљЅ5ЦtqўyЂŠ/Ќ5{}>о(.МG=г|вЪу ўШуќуоBУXЗВЗŠ ЏOrFщЅ qўШуќуоŠ(дЌ5{{KhmЎМG<јн4СЎ1ŸюŒзќiu+ ^ {x-ЎМE<ин,сЎЯїFGљтŠ(5; ^m ЕКёђКYї\O ШщџжЎ‡ТіК…žЙkŸЋ]@!cs5љ—Ы-и(~љєэјбEџй``LžтœгВШrel_interstitial_loading.gif./www/css/images/deadblock.png0000755000175000017500000000036012022717562016146 0ustar ubuntuubuntu‰PNG  IHDRыŠZgAMAБŽ|ћQ“ cHRMz%€ƒљџ€шu0ъ`:—o—Љ™д{IDATxœbd`XС@.  >p@‚ /ˆ‰lk €(в @i Š4Ešˆ"ЭD‘f€ЂH3@QЄ €(в @i Š4Ešˆ"ЭD‘f€ЂH3@QЄ €))† ьy%r”IENDЎB`‚./www/index.htm0000755000000000000000000000077212216073057012372 0ustar rootroot Snake Game
./www/js/0000755000000000000000000000000012216072715011154 5ustar rootroot./www/js/md5.js0000755000175000017500000003001112216054061013117 0ustar ubuntuubuntu/* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for more info. */ /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ /* * These are the functions you'll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); } function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); } function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); } function hex_hmac_md5(k, d) { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } function b64_hmac_md5(k, d) { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } function any_hmac_md5(k, d, e) { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); } /* * Perform a simple self-test to see if the VM is working */ function md5_vm_test() { return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72"; } /* * Calculate the MD5 of a raw string */ function rstr_md5(s) { return binl2rstr(binl_md5(rstr2binl(s), s.length * 8)); } /* * Calculate the HMAC-MD5, of a key and some data (raw strings) */ function rstr_hmac_md5(key, data) { var bkey = rstr2binl(key); if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8); return binl2rstr(binl_md5(opad.concat(hash), 512 + 128)); } /* * Convert a raw string to a hex string */ function rstr2hex(input) { try { hexcase } catch(e) { hexcase=0; } var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var output = ""; var x; for(var i = 0; i < input.length; i++) { x = input.charCodeAt(i); output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt( x & 0x0F); } return output; } /* * Convert a raw string to a base-64 string */ function rstr2b64(input) { try { b64pad } catch(e) { b64pad=''; } var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var output = ""; var len = input.length; for(var i = 0; i < len; i += 3) { var triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i+2) : 0); for(var j = 0; j < 4; j++) { if(i * 8 + j * 6 > input.length * 8) output += b64pad; else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); } } return output; } /* * Convert a raw string to an arbitrary string encoding */ function rstr2any(input, encoding) { var divisor = encoding.length; var i, j, q, x, quotient; /* Convert to an array of 16-bit big-endian values, forming the dividend */ var dividend = Array(Math.ceil(input.length / 2)); for(i = 0; i < dividend.length; i++) { dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); } /* * Repeatedly perform a long division. The binary array forms the dividend, * the length of the encoding is the divisor. Once computed, the quotient * forms the dividend for the next step. All remainders are stored for later * use. */ var full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2))); var remainders = Array(full_length); for(j = 0; j < full_length; j++) { quotient = Array(); x = 0; for(i = 0; i < dividend.length; i++) { x = (x << 16) + dividend[i]; q = Math.floor(x / divisor); x -= q * divisor; if(quotient.length > 0 || q > 0) quotient[quotient.length] = q; } remainders[j] = x; dividend = quotient; } /* Convert the remainders to the output string */ var output = ""; for(i = remainders.length - 1; i >= 0; i--) output += encoding.charAt(remainders[i]); return output; } /* * Encode a string as utf-8. * For efficiency, this assumes the input is valid utf-16. */ function str2rstr_utf8(input) { var output = ""; var i = -1; var x, y; while(++i < input.length) { /* Decode utf-16 surrogate pairs */ x = input.charCodeAt(i); y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); i++; } /* Encode output as utf-8 */ if(x <= 0x7F) output += String.fromCharCode(x); else if(x <= 0x7FF) output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), 0x80 | ( x & 0x3F)); else if(x <= 0xFFFF) output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x & 0x3F)); else if(x <= 0x1FFFFF) output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x & 0x3F)); } return output; } /* * Encode a string as utf-16 */ function str2rstr_utf16le(input) { var output = ""; for(var i = 0; i < input.length; i++) output += String.fromCharCode( input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF); return output; } function str2rstr_utf16be(input) { var output = ""; for(var i = 0; i < input.length; i++) output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF); return output; } /* * Convert a raw string to an array of little-endian words * Characters >255 have their high-byte silently ignored. */ function rstr2binl(input) { var output = Array(input.length >> 2); for(var i = 0; i < output.length; i++) output[i] = 0; for(var i = 0; i < input.length * 8; i += 8) output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); return output; } /* * Convert an array of little-endian words to a string */ function binl2rstr(input) { var output = ""; for(var i = 0; i < input.length * 32; i += 8) output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); return output; } /* * Calculate the MD5 of an array of little-endian words, and a bit length. */ function binl_md5(x, len) { /* append padding */ x[len >> 5] |= 0x80 << ((len) % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); c = md5_ff(c, d, a, b, x[i+10], 17, -42063); b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); } return Array(a, b, c, d); } /* * These functions implement the four basic operations the algorithm uses. */ function md5_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); } function md5_ff(a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); } function md5_gg(a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); } function md5_hh(a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); } function md5_ii(a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safe_add(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } /* * Bitwise rotate a 32-bit number to the left. */ function bit_rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } ./www/js/snake.js0000755000175000017500000007214512216072715013557 0ustar ubuntuubuntuvar _0x515d=["\x61\x64\x64\x45\x76\x65\x6E\x74\x4C\x69\x73\x74\x65\x6E\x65\x72","\x61\x74\x74\x61\x63\x68\x45\x76\x65\x6E\x74","\x6F\x6E","\x72\x65\x6D\x6F\x76\x65\x45\x76\x65\x6E\x74\x4C\x69\x73\x74\x65\x6E\x65\x72","\x64\x65\x74\x61\x63\x68\x45\x76\x65\x6E\x74","\x53\x6E\x61\x6B\x65","\x65\x6C\x6D","\x65\x6C\x6D\x53\x74\x79\x6C\x65","\x72\x6F\x77","\x63\x6F\x6C","\x78\x50\x6F\x73","\x79\x50\x6F\x73","\x6E\x65\x78\x74","\x70\x72\x65\x76","\x63\x75\x72\x72\x65\x6E\x74\x53\x74\x79\x6C\x65","\x7A\x2D\x69\x6E\x64\x65\x78","\x73\x74\x79\x6C\x65","\x67\x65\x74\x43\x6F\x6D\x70\x75\x74\x65\x64\x53\x74\x79\x6C\x65","\x67\x65\x74\x50\x72\x6F\x70\x65\x72\x74\x79\x56\x61\x6C\x75\x65","\x64\x65\x66\x61\x75\x6C\x74\x56\x69\x65\x77","\x70\x6C\x61\x79\x69\x6E\x67\x42\x6F\x61\x72\x64","\x73\x6E\x61\x6B\x65\x42\x6F\x64\x79","\x62\x30","\x73\x74\x61\x72\x74\x52\x6F\x77","\x73\x74\x61\x72\x74\x43\x6F\x6C","\x67\x65\x74\x42\x6C\x6F\x63\x6B\x57\x69\x64\x74\x68","\x67\x65\x74\x42\x6C\x6F\x63\x6B\x48\x65\x69\x67\x68\x74","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64","\x67\x65\x74\x42\x6F\x61\x72\x64\x43\x6F\x6E\x74\x61\x69\x6E\x65\x72","\x6C\x65\x66\x74","\x70\x78","\x74\x6F\x70","\x73\x6E\x61\x6B\x65\x4C\x65\x6E\x67\x74\x68","\x73\x6E\x61\x6B\x65\x48\x65\x61\x64","\x73\x6E\x61\x6B\x65\x54\x61\x69\x6C","\x63\x6C\x61\x73\x73\x4E\x61\x6D\x65","","\x72\x65\x70\x6C\x61\x63\x65","\x20\x73\x6E\x61\x6B\x65\x2D\x73\x6E\x61\x6B\x65\x62\x6F\x64\x79\x2D\x61\x6C\x69\x76\x65","\x64\x69\x76","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x73\x6E\x61\x6B\x65\x2D\x73\x6E\x61\x6B\x65\x62\x6F\x64\x79\x2D\x62\x6C\x6F\x63\x6B","\x2D\x31\x30\x30\x30\x70\x78","\x77\x69\x64\x74\x68","\x68\x65\x69\x67\x68\x74","\x63\x6C\x6F\x6E\x65\x4E\x6F\x64\x65","\x6C\x65\x6E\x67\x74\x68","\x68\x61\x6E\x64\x6C\x65\x41\x72\x72\x6F\x77\x4B\x65\x79\x73","\x75\x6E\x73\x68\x69\x66\x74","\x67\x6F","\x67\x72\x69\x64","\x70\x6F\x70","\x68\x61\x6E\x64\x6C\x65\x44\x65\x61\x74\x68","\x67\x65\x74\x47\x72\x69\x64\x46\x6F\x6F\x64\x56\x61\x6C\x75\x65","\x65\x61\x74\x46\x6F\x6F\x64","\x73\x70\x6C\x69\x63\x65","\x62","\x66\x6F\x6F\x64\x45\x61\x74\x65\x6E","\x7A\x49\x6E\x64\x65\x78","\x20\x73\x6E\x61\x6B\x65\x2D\x73\x6E\x61\x6B\x65\x62\x6F\x64\x79\x2D\x64\x65\x61\x64","\x72\x65\x62\x69\x72\x74\x68","\x72\x65\x73\x65\x74","\x70\x75\x73\x68","\x63\x6F\x6E\x63\x61\x74","\x46\x6F\x6F\x64","\x72\x61\x6E\x64\x6F\x6D","\x66\x6C\x6F\x6F\x72","\x69\x64","\x73\x6E\x61\x6B\x65\x2D\x66\x6F\x6F\x64\x2D","\x73\x65\x74\x41\x74\x74\x72\x69\x62\x75\x74\x65","\x73\x6E\x61\x6B\x65\x2D\x66\x6F\x6F\x64\x2D\x62\x6C\x6F\x63\x6B","\x67\x65\x74\x46\x6F\x6F\x64\x45\x6C\x65\x6D\x65\x6E\x74","\x72\x61\x6E\x64\x6F\x6D\x6C\x79\x50\x6C\x61\x63\x65\x46\x6F\x6F\x64","\x42\x6F\x61\x72\x64","\x69\x6E\x6E\x65\x72\x57\x69\x64\x74\x68","\x6E\x75\x6D\x62\x65\x72","\x64\x6F\x63\x75\x6D\x65\x6E\x74\x45\x6C\x65\x6D\x65\x6E\x74","\x63\x6C\x69\x65\x6E\x74\x57\x69\x64\x74\x68","\x63\x6C\x69\x65\x6E\x74\x48\x65\x69\x67\x68\x74","\x62\x6F\x64\x79","\x69\x6E\x6E\x65\x72\x48\x65\x69\x67\x68\x74","\x70\x6C\x61\x79\x69\x6E\x67\x46\x69\x65\x6C\x64","\x73\x6E\x61\x6B\x65\x2D\x70\x6C\x61\x79\x69\x6E\x67\x2D\x66\x69\x65\x6C\x64","\x63\x6C\x69\x63\x6B","\x66\x6F\x63\x75\x73","\x73\x6E\x61\x6B\x65\x2D\x70\x61\x6E\x65\x6C\x2D\x63\x6F\x6D\x70\x6F\x6E\x65\x6E\x74","\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C","\x4C\x65\x6E\x67\x74\x68\x3A\x20\x31","\x6B\x65\x79\x75\x70","\x65\x76\x65\x6E\x74","\x63\x61\x6E\x63\x65\x6C\x42\x75\x62\x62\x6C\x65","\x73\x74\x6F\x70\x50\x72\x6F\x70\x61\x67\x61\x74\x69\x6F\x6E","\x70\x72\x65\x76\x65\x6E\x74\x44\x65\x66\x61\x75\x6C\x74","\x73\x6E\x61\x6B\x65\x2D\x67\x61\x6D\x65\x2D\x63\x6F\x6E\x74\x61\x69\x6E\x65\x72","\x73\x62\x57\x65\x6C\x63\x6F\x6D\x65","\x73\x6E\x61\x6B\x65\x2D\x77\x65\x6C\x63\x6F\x6D\x65\x2D\x64\x69\x61\x6C\x6F\x67","\x66\x75\x6C\x6C\x53\x63\x72\x65\x65\x6E","\x4F\x6E\x20\x57\x69\x6E\x64\x6F\x77\x73\x2C\x20\x70\x72\x65\x73\x73\x20\x46\x31\x31\x20\x74\x6F\x20\x70\x6C\x61\x79\x20\x69\x6E\x20\x46\x75\x6C\x6C\x20\x53\x63\x72\x65\x65\x6E\x20\x6D\x6F\x64\x65\x2E","\x57\x65\x6C\x63\x6F\x6D\x65\x21\x3C\x70\x3E\x3C\x2F\x70\x3E\x3C\x70\x3E\x59\x6F\x75\x20\x6E\x65\x65\x64\x20\x74\x6F\x20\x62\x65\x20\x72\x65\x67\x69\x73\x74\x65\x72\x65\x64\x20\x75\x73\x65\x72\x20\x74\x6F\x20\x62\x65\x20\x61\x62\x6C\x65\x20\x74\x6F\x20\x73\x61\x76\x65\x20\x67\x61\x6D\x65\x20\x72\x65\x73\x75\x6C\x74\x73\x20\x61\x6E\x64\x20\x6D\x61\x6E\x61\x67\x65\x20\x70\x65\x72\x73\x6F\x6E\x61\x6C\x20\x73\x74\x61\x74\x69\x73\x74\x69\x63\x73\x2E\x20\x3C\x62\x3E\x3C\x61\x20\x68\x72\x65\x66\x3D\x22\x2E\x2F\x63\x67\x69\x2D\x62\x69\x6E\x2F\x69\x6E\x64\x65\x78\x2E\x70\x6C\x22\x3E\x52\x65\x67\x69\x73\x74\x65\x72\x20\x68\x65\x72\x65\x3C\x2F\x61\x3E\x3C\x2F\x62\x3E\x3C\x2F\x70\x3E","\x62\x75\x74\x74\x6F\x6E","\x50\x6C\x61\x79\x20\x47\x61\x6D\x65","\x63\x72\x65\x61\x74\x65\x54\x65\x78\x74\x4E\x6F\x64\x65","\x64\x69\x73\x70\x6C\x61\x79","\x6E\x6F\x6E\x65","\x73\x65\x74\x42\x6F\x61\x72\x64\x53\x74\x61\x74\x65","\x77\x68\x69\x63\x68","\x6B\x65\x79\x43\x6F\x64\x65","\x73\x62\x54\x72\x79\x41\x67\x61\x69\x6E","\x73\x6E\x61\x6B\x65\x2D\x74\x72\x79\x2D\x61\x67\x61\x69\x6E\x2D\x64\x69\x61\x6C\x6F\x67","\x3C\x62\x3E\x53\x75\x62\x6D\x69\x74\x20\x73\x63\x6F\x72\x65\x3C\x2F\x62\x3E\x3C\x62\x72\x3E\x59\x6F\x75\x72\x20\x6C\x6F\x67\x69\x6E\x3A","\x69\x6E\x70\x75\x74","\x70\x6C\x61\x79\x65\x72\x6E\x61\x6D\x65","\x53\x75\x62\x6D\x69\x74","\x72\x65\x73\x65\x74\x42\x6F\x61\x72\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x70\x6C\x61\x79\x65\x72\x4E\x61\x6D\x65\x3D","\x76\x61\x6C\x75\x65","\x26\x70\x6C\x61\x79\x65\x72\x53\x63\x6F\x72\x65\x3D","\x26\x68\x61\x73\x68\x3D","\x70\x63\x38\x58\x57\x32\x78\x55\x4A\x63\x57\x4D\x46\x56\x47\x6B\x5A\x35\x50\x4C","\x50\x4F\x53\x54","\x2F\x63\x67\x69\x2D\x62\x69\x6E\x2F\x73\x61\x76\x65\x2E\x70\x6C","\x6F\x70\x65\x6E","\x43\x6F\x6E\x74\x65\x6E\x74\x2D\x54\x79\x70\x65","\x61\x70\x70\x6C\x69\x63\x61\x74\x69\x6F\x6E\x2F\x78\x2D\x77\x77\x77\x2D\x66\x6F\x72\x6D\x2D\x75\x72\x6C\x65\x6E\x63\x6F\x64\x65\x64","\x73\x65\x74\x52\x65\x71\x75\x65\x73\x74\x48\x65\x61\x64\x65\x72","\x73\x65\x6E\x64","\x72\x65\x73\x70\x6F\x6E\x73\x65\x54\x65\x78\x74","\x62\x6C\x6F\x63\x6B","\x6B\x65\x79\x64\x6F\x77\x6E","\x73\x65\x74\x75\x70\x50\x6C\x61\x79\x69\x6E\x67\x46\x69\x65\x6C\x64","\x67\x65\x74\x42\x6F\x61\x72\x64\x53\x74\x61\x74\x65","\x67\x65\x74\x50\x6C\x61\x79\x69\x6E\x67\x46\x69\x65\x6C\x64\x45\x6C\x65\x6D\x65\x6E\x74","\x73\x65\x74\x42\x6F\x61\x72\x64\x43\x6F\x6E\x74\x61\x69\x6E\x65\x72","\x73\x74\x72\x69\x6E\x67","\x62\x61\x63\x6B\x67\x72\x6F\x75\x6E\x64\x43\x6F\x6C\x6F\x72","\x23\x46\x43\x35\x34\x35\x34","\x6D\x69\x6E","\x72\x6F\x75\x6E\x64","\x34\x35\x30\x70\x78","\x4C\x65\x6E\x67\x74\x68\x3A\x20","\x6D\x61\x78","\x72\x65\x6D\x6F\x76\x65\x43\x68\x69\x6C\x64","\x75\x6E\x64\x65\x66\x69\x6E\x65\x64","\x72\x65\x73\x69\x7A\x65","\x62\x6F\x61\x72\x64\x43\x6F\x6E\x74\x61\x69\x6E\x65\x72"];var SNAKE=SNAKE||{};SNAKE[_0x515d[0]]=(function (){if(window[_0x515d[0]]){return function (_0xcef5x2,_0xcef5x3,_0xcef5x4,_0xcef5x5){_0xcef5x2[_0x515d[0]](_0xcef5x3,_0xcef5x4,_0xcef5x5);} ;} else {if(window[_0x515d[1]]){return function (_0xcef5x2,_0xcef5x3,_0xcef5x4){_0xcef5x2[_0x515d[1]](_0x515d[2]+_0xcef5x3,_0xcef5x4);} ;} ;} ;} )();SNAKE[_0x515d[3]]=(function (){if(window[_0x515d[3]]){return function (_0xcef5x2,_0xcef5x3,_0xcef5x4,_0xcef5x5){_0xcef5x2[_0x515d[3]](_0xcef5x3,_0xcef5x4,_0xcef5x5);} ;} else {if(window[_0x515d[4]]){return function (_0xcef5x2,_0xcef5x3,_0xcef5x4){_0xcef5x2[_0x515d[4]](_0x515d[2]+_0xcef5x3,_0xcef5x4);} ;} ;} ;} )();SNAKE[_0x515d[5]]=SNAKE[_0x515d[5]]||(function (){var _0xcef5x6=0;var _0xcef5x7=[];var _0xcef5x8=function (){this[_0x515d[6]]=null;this[_0x515d[7]]=null;this[_0x515d[8]]=-1;this[_0x515d[9]]=-1;this[_0x515d[10]]=-1000;this[_0x515d[11]]=-1000;this[_0x515d[12]]=null;this[_0x515d[13]]=null;} ;function _0xcef5x9(_0xcef5xa){var _0xcef5xb=0,_0xcef5xc=0,_0xcef5xd;for(_0xcef5xd in _0xcef5xa){if(_0xcef5xa[_0xcef5xd][_0x515d[6]][_0x515d[14]]){_0xcef5xc=parseFloat(_0xcef5xa[_0xcef5xd][_0x515d[6]][_0x515d[16]][_0x515d[15]],10);} else {if(window[_0x515d[17]]){_0xcef5xc=parseFloat(document[_0x515d[19]][_0x515d[17]](_0xcef5xa[_0xcef5xd][_0x515d[6]],null)[_0x515d[18]](_0x515d[15]),10);} ;} ;if(!isNaN(_0xcef5xc)&&_0xcef5xc>_0xcef5xb){_0xcef5xb=_0xcef5xc;} ;} ;return (_0xcef5xb+1);} ;return function (_0xcef5xe){if(!_0xcef5xe||!_0xcef5xe[_0x515d[20]]){return ;} ;var _0xcef5xf=this,_0xcef5x10=_0xcef5xe[_0x515d[20]],_0xcef5x11=_0xcef5x6++,_0xcef5x12=5,_0xcef5x13=[],_0xcef5x14=1,_0xcef5x15=[0,1,0,-1],_0xcef5x16=[-1,0,1,0],_0xcef5x17=[],_0xcef5x18=[],_0xcef5x19=75,_0xcef5x1a=false;_0xcef5xf[_0x515d[21]]={};_0xcef5xf[_0x515d[21]][_0x515d[22]]= new _0xcef5x8();_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[8]]=_0xcef5xe[_0x515d[23]]||1;_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[9]]=_0xcef5xe[_0x515d[24]]||1;_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[10]]=_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[8]]*_0xcef5x10[_0x515d[25]]();_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[11]]=_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[9]]*_0xcef5x10[_0x515d[26]]();_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[6]]=_0xcef5x1b();_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[7]]=_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[6]][_0x515d[16]];_0xcef5x10[_0x515d[28]]()[_0x515d[27]](_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[6]]);_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[6]][_0x515d[16]][_0x515d[29]]=_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[10]]+_0x515d[30];_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[6]][_0x515d[16]][_0x515d[31]]=_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[11]]+_0x515d[30];_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[12]]=_0xcef5xf[_0x515d[21]][_0x515d[22]];_0xcef5xf[_0x515d[21]][_0x515d[22]][_0x515d[13]]=_0xcef5xf[_0x515d[21]][_0x515d[22]];_0xcef5xf[_0x515d[32]]=1;_0xcef5xf[_0x515d[33]]=_0xcef5xf[_0x515d[21]][_0x515d[22]];_0xcef5xf[_0x515d[34]]=_0xcef5xf[_0x515d[21]][_0x515d[22]];_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]]=_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]][_0x515d[37]](/\bsnake-snakebody-dead\b/,_0x515d[36]);_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]]+=_0x515d[38];function _0xcef5x1b(){var _0xcef5x1c=document[_0x515d[40]](_0x515d[39]);_0xcef5x1c[_0x515d[35]]=_0x515d[41];_0xcef5x1c[_0x515d[16]][_0x515d[29]]=_0x515d[42];_0xcef5x1c[_0x515d[16]][_0x515d[31]]=_0x515d[42];_0xcef5x1c[_0x515d[16]][_0x515d[43]]=_0xcef5x10[_0x515d[25]]()+_0x515d[30];_0xcef5x1c[_0x515d[16]][_0x515d[44]]=_0xcef5x10[_0x515d[26]]()+_0x515d[30];return _0xcef5x1c;} ;function _0xcef5x1d(_0xcef5x1e){var _0xcef5x1f;var _0xcef5x1c=_0xcef5x1b();for(var _0xcef5xd=1;_0xcef5xd<_0xcef5x1e;_0xcef5xd++){_0xcef5x1f= new _0xcef5x8();_0xcef5x1f[_0x515d[6]]=_0xcef5x1c[_0x515d[45]](true);_0xcef5x1f[_0x515d[7]]=_0xcef5x1f[_0x515d[6]][_0x515d[16]];_0xcef5x10[_0x515d[28]]()[_0x515d[27]](_0xcef5x1f[_0x515d[6]]);_0xcef5x7[_0xcef5x7[_0x515d[46]]]=_0xcef5x1f;} ;_0xcef5x1f= new _0xcef5x8();_0xcef5x1f[_0x515d[6]]=_0xcef5x1c;_0xcef5x10[_0x515d[28]]()[_0x515d[27]](_0xcef5x1f[_0x515d[6]]);_0xcef5x7[_0xcef5x7[_0x515d[46]]]=_0xcef5x1f;} ;_0xcef5xf[_0x515d[47]]=function (_0xcef5x20){if(_0xcef5x1a){return ;} ;var _0xcef5x21=_0xcef5xf[_0x515d[32]];var _0xcef5x22=_0xcef5x13[0]||_0xcef5x14;switch(_0xcef5x20){case 37:if(_0xcef5x22!==1||_0xcef5x21===1){_0xcef5x13[_0x515d[48]](3);} ;break ;;case 38:if(_0xcef5x22!==2||_0xcef5x21===1){_0xcef5x13[_0x515d[48]](0);} ;break ;;case 39:if(_0xcef5x22!==3||_0xcef5x21===1){_0xcef5x13[_0x515d[48]](1);} ;break ;;case 40:if(_0xcef5x22!==0||_0xcef5x21===1){_0xcef5x13[_0x515d[48]](2);} ;break ;;} ;} ;_0xcef5xf[_0x515d[49]]=function (){var _0xcef5x23=_0xcef5xf[_0x515d[33]],_0xcef5x24=_0xcef5xf[_0x515d[34]],_0xcef5x25=_0xcef5x14,_0xcef5x26=_0xcef5x10[_0x515d[50]];_0xcef5xf[_0x515d[34]]=_0xcef5x24[_0x515d[13]];_0xcef5xf[_0x515d[33]]=_0xcef5x24;if(_0xcef5x26[_0xcef5x24[_0x515d[8]]]&&_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]){_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]=0;} ;if(_0xcef5x13[_0x515d[46]]){_0xcef5x25=_0xcef5x14=_0xcef5x13[_0x515d[51]]();} ;_0xcef5x24[_0x515d[9]]=_0xcef5x23[_0x515d[9]]+_0xcef5x15[_0xcef5x25];_0xcef5x24[_0x515d[8]]=_0xcef5x23[_0x515d[8]]+_0xcef5x16[_0xcef5x25];_0xcef5x24[_0x515d[10]]=_0xcef5x23[_0x515d[10]]+_0xcef5x17[_0xcef5x25];_0xcef5x24[_0x515d[11]]=_0xcef5x23[_0x515d[11]]+_0xcef5x18[_0xcef5x25];if(!_0xcef5x24[_0x515d[7]]){_0xcef5x24[_0x515d[7]]=_0xcef5x24[_0x515d[6]][_0x515d[16]];} ;_0xcef5x24[_0x515d[7]][_0x515d[29]]=_0xcef5x24[_0x515d[10]]+_0x515d[30];_0xcef5x24[_0x515d[7]][_0x515d[31]]=_0xcef5x24[_0x515d[11]]+_0x515d[30];if(_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]===0){_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]=1;setTimeout(function (){_0xcef5xf[_0x515d[49]]();} ,_0xcef5x19);} else {if(_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]>0){_0xcef5xf[_0x515d[52]]();} else {if(_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]===_0xcef5x10[_0x515d[53]]()){_0xcef5x26[_0xcef5x24[_0x515d[8]]][_0xcef5x24[_0x515d[9]]]=1;_0xcef5xf[_0x515d[54]]();setTimeout(function (){_0xcef5xf[_0x515d[49]]();} ,_0xcef5x19);} ;} ;} ;} ;_0xcef5xf[_0x515d[54]]=function (){if(_0xcef5x7[_0x515d[46]]<=_0xcef5x12){_0xcef5x1d(_0xcef5x12*2);} ;var _0xcef5x27=_0xcef5x7[_0x515d[55]](0,_0xcef5x12);var _0xcef5xd=_0xcef5x27[_0x515d[46]],_0xcef5x28,_0xcef5x29=_0xcef5xf[_0x515d[34]];while(_0xcef5xd--){_0xcef5x28=_0x515d[56]+_0xcef5xf[_0x515d[32]]++;_0xcef5xf[_0x515d[21]][_0xcef5x28]=_0xcef5x27[_0xcef5xd];_0xcef5xf[_0x515d[21]][_0xcef5x28][_0x515d[13]]=_0xcef5x29;_0xcef5xf[_0x515d[21]][_0xcef5x28][_0x515d[6]][_0x515d[35]]=_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]][_0x515d[37]](/\bsnake-snakebody-dead\b/,_0x515d[36]);_0xcef5xf[_0x515d[21]][_0xcef5x28][_0x515d[6]][_0x515d[35]]+=_0x515d[38];_0xcef5x29[_0x515d[12]]=_0xcef5xf[_0x515d[21]][_0xcef5x28];_0xcef5x29=_0xcef5xf[_0x515d[21]][_0xcef5x28];} ;_0xcef5xf[_0x515d[34]]=_0xcef5xf[_0x515d[21]][_0xcef5x28];_0xcef5xf[_0x515d[34]][_0x515d[12]]=_0xcef5xf[_0x515d[33]];_0xcef5xf[_0x515d[33]][_0x515d[13]]=_0xcef5xf[_0x515d[34]];_0xcef5x10[_0x515d[57]]();} ;_0xcef5xf[_0x515d[52]]=function (){_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[16]][_0x515d[58]]=_0xcef5x9(_0xcef5xf[_0x515d[21]]);_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]]=_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]][_0x515d[37]](/\bsnake-snakebody-alive\b/,_0x515d[36]);_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]]+=_0x515d[59];_0xcef5x1a=true;_0xcef5x10[_0x515d[52]]();_0xcef5x13[_0x515d[46]]=0;} ;_0xcef5xf[_0x515d[60]]=function (){_0xcef5x1a=false;} ;_0xcef5xf[_0x515d[61]]=function (){if(_0xcef5x1a===false){return ;} ;var _0xcef5x27=[],_0xcef5x2a=_0xcef5xf[_0x515d[33]][_0x515d[12]],_0xcef5x2b;while(_0xcef5x2a!==_0xcef5xf[_0x515d[33]]){_0xcef5x2b=_0xcef5x2a[_0x515d[12]];_0xcef5x2a[_0x515d[13]]=null;_0xcef5x2a[_0x515d[12]]=null;_0xcef5x27[_0x515d[62]](_0xcef5x2a);_0xcef5x2a=_0xcef5x2b;} ;_0xcef5xf[_0x515d[33]][_0x515d[12]]=_0xcef5xf[_0x515d[33]];_0xcef5xf[_0x515d[33]][_0x515d[13]]=_0xcef5xf[_0x515d[33]];_0xcef5xf[_0x515d[34]]=_0xcef5xf[_0x515d[33]];_0xcef5xf[_0x515d[32]]=1;for(var _0xcef5xd=0;_0xcef5xd<_0xcef5x27[_0x515d[46]];_0xcef5xd++){_0xcef5x27[_0xcef5xd][_0x515d[6]][_0x515d[16]][_0x515d[29]]=_0x515d[42];_0xcef5x27[_0xcef5xd][_0x515d[6]][_0x515d[16]][_0x515d[31]]=_0x515d[42];_0xcef5x27[_0xcef5xd][_0x515d[6]][_0x515d[35]]=_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]][_0x515d[37]](/\bsnake-snakebody-dead\b/,_0x515d[36]);_0xcef5x27[_0xcef5xd][_0x515d[6]][_0x515d[35]]+=_0x515d[38];} ;_0xcef5x7[_0x515d[63]](_0xcef5x27);_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]]=_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]][_0x515d[37]](/\bsnake-snakebody-dead\b/,_0x515d[36]);_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[35]]+=_0x515d[38];_0xcef5xf[_0x515d[33]][_0x515d[8]]=_0xcef5xe[_0x515d[23]]||1;_0xcef5xf[_0x515d[33]][_0x515d[9]]=_0xcef5xe[_0x515d[24]]||1;_0xcef5xf[_0x515d[33]][_0x515d[10]]=_0xcef5xf[_0x515d[33]][_0x515d[8]]*_0xcef5x10[_0x515d[25]]();_0xcef5xf[_0x515d[33]][_0x515d[11]]=_0xcef5xf[_0x515d[33]][_0x515d[9]]*_0xcef5x10[_0x515d[26]]();_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[16]][_0x515d[29]]=_0xcef5xf[_0x515d[33]][_0x515d[10]]+_0x515d[30];_0xcef5xf[_0x515d[33]][_0x515d[6]][_0x515d[16]][_0x515d[31]]=_0xcef5xf[_0x515d[33]][_0x515d[11]]+_0x515d[30];} ;_0xcef5x1d(_0xcef5x12*2);_0xcef5x17[0]=0;_0xcef5x17[1]=_0xcef5x10[_0x515d[25]]();_0xcef5x17[2]=0;_0xcef5x17[3]=-1*_0xcef5x10[_0x515d[25]]();_0xcef5x18[0]=-1*_0xcef5x10[_0x515d[26]]();_0xcef5x18[1]=0;_0xcef5x18[2]=_0xcef5x10[_0x515d[26]]();_0xcef5x18[3]=0;} ;} )();SNAKE[_0x515d[64]]=SNAKE[_0x515d[64]]||(function (){var _0xcef5x6=0;function _0xcef5x2c(_0xcef5x2d,_0xcef5x2e){return Math[_0x515d[66]](Math[_0x515d[65]]()*(_0xcef5x2e+1-_0xcef5x2d))+_0xcef5x2d;} ;return function (_0xcef5xe){if(!_0xcef5xe||!_0xcef5xe[_0x515d[20]]){return ;} ;var _0xcef5xf=this;var _0xcef5x10=_0xcef5xe[_0x515d[20]];var _0xcef5x2f,_0xcef5x30;var _0xcef5x11=_0xcef5x6++;var _0xcef5x31=document[_0x515d[40]](_0x515d[39]);_0xcef5x31[_0x515d[69]](_0x515d[67],_0x515d[68]+_0xcef5x11);_0xcef5x31[_0x515d[35]]=_0x515d[70];_0xcef5x31[_0x515d[16]][_0x515d[43]]=_0xcef5x10[_0x515d[25]]()+_0x515d[30];_0xcef5x31[_0x515d[16]][_0x515d[44]]=_0xcef5x10[_0x515d[26]]()+_0x515d[30];_0xcef5x31[_0x515d[16]][_0x515d[29]]=_0x515d[42];_0xcef5x31[_0x515d[16]][_0x515d[31]]=_0x515d[42];_0xcef5x10[_0x515d[28]]()[_0x515d[27]](_0xcef5x31);_0xcef5xf[_0x515d[71]]=function (){return _0xcef5x31;} ;_0xcef5xf[_0x515d[72]]=function (){if(_0xcef5x10[_0x515d[50]][_0xcef5x2f]&&_0xcef5x10[_0x515d[50]][_0xcef5x2f][_0xcef5x30]===_0xcef5x10[_0x515d[53]]()){_0xcef5x10[_0x515d[50]][_0xcef5x2f][_0xcef5x30]=0;} ;var _0xcef5x32=0,_0xcef5x33=0,_0xcef5x34=0;var _0xcef5x35=_0xcef5x10[_0x515d[50]][_0x515d[46]]-1;var _0xcef5x36=_0xcef5x10[_0x515d[50]][0][_0x515d[46]]-1;while(_0xcef5x10[_0x515d[50]][_0xcef5x32][_0xcef5x33]!==0){_0xcef5x32=_0xcef5x2c(1,_0xcef5x35);_0xcef5x33=_0xcef5x2c(1,_0xcef5x36);_0xcef5x34++;if(_0xcef5x34>20000){_0xcef5x32=-1;_0xcef5x33=-1;break ;} ;} ;_0xcef5x10[_0x515d[50]][_0xcef5x32][_0xcef5x33]=_0xcef5x10[_0x515d[53]]();_0xcef5x2f=_0xcef5x32;_0xcef5x30=_0xcef5x33;_0xcef5x31[_0x515d[16]][_0x515d[31]]=_0xcef5x32*_0xcef5x10[_0x515d[26]]()+_0x515d[30];_0xcef5x31[_0x515d[16]][_0x515d[29]]=_0xcef5x33*_0xcef5x10[_0x515d[25]]()+_0x515d[30];} ;} ;} )();SNAKE[_0x515d[73]]=SNAKE[_0x515d[73]]||(function (){var _0xcef5x6=0;function _0xcef5x9(_0xcef5xa){var _0xcef5xb=0,_0xcef5xc=0,_0xcef5xd;for(_0xcef5xd in _0xcef5xa){if(_0xcef5xa[_0xcef5xd][_0x515d[6]][_0x515d[14]]){_0xcef5xc=parseFloat(_0xcef5xa[_0xcef5xd][_0x515d[6]][_0x515d[16]][_0x515d[15]],10);} else {if(window[_0x515d[17]]){_0xcef5xc=parseFloat(document[_0x515d[19]][_0x515d[17]](_0xcef5xa[_0xcef5xd][_0x515d[6]],null)[_0x515d[18]](_0x515d[15]),10);} ;} ;if(!isNaN(_0xcef5xc)&&_0xcef5xc>_0xcef5xb){_0xcef5xb=_0xcef5xc;} ;} ;return (_0xcef5xb+1);} ;function _0xcef5x37(){var _0xcef5x38=0;if( typeof window[_0x515d[74]]===_0x515d[75]){_0xcef5x38=window[_0x515d[74]];} else {if(document[_0x515d[76]]&&(document[_0x515d[76]][_0x515d[77]]||document[_0x515d[76]][_0x515d[78]])){_0xcef5x38=document[_0x515d[76]][_0x515d[77]];} else {if(document[_0x515d[79]]&&(document[_0x515d[79]][_0x515d[77]]||document[_0x515d[79]][_0x515d[78]])){_0xcef5x38=document[_0x515d[79]][_0x515d[77]];} ;} ;} ;return _0xcef5x38;} ;function _0xcef5x39(){var _0xcef5x3a=0;if( typeof window[_0x515d[80]]===_0x515d[75]){_0xcef5x3a=window[_0x515d[80]];} else {if(document[_0x515d[76]]&&(document[_0x515d[76]][_0x515d[77]]||document[_0x515d[76]][_0x515d[78]])){_0xcef5x3a=document[_0x515d[76]][_0x515d[78]];} else {if(document[_0x515d[79]]&&(document[_0x515d[79]][_0x515d[77]]||document[_0x515d[79]][_0x515d[78]])){_0xcef5x3a=document[_0x515d[79]][_0x515d[78]];} ;} ;} ;return _0xcef5x3a;} ;return function (_0xcef5x3b){var _0xcef5xf=this,_0xcef5x11=_0xcef5x6++,_0xcef5xe=_0xcef5x3b||{},_0xcef5x3c=250,_0xcef5x3d=250,_0xcef5x3e=20,_0xcef5x3f=20,_0xcef5x40=-1,_0xcef5x41,_0xcef5x42,_0xcef5x43=1,_0xcef5x44,_0xcef5x45,_0xcef5x46,_0xcef5x47,_0xcef5x48,_0xcef5x49,_0xcef5x4a;_0xcef5xf[_0x515d[50]]=[];function _0xcef5x4b(){_0xcef5x46=document[_0x515d[40]](_0x515d[39]);_0xcef5x46[_0x515d[69]](_0x515d[67],_0x515d[81]);_0xcef5x46[_0x515d[35]]=_0x515d[82];SNAKE[_0x515d[0]](_0xcef5x46,_0x515d[83],function (){_0xcef5x45[_0x515d[84]]();} ,false);_0xcef5x47=document[_0x515d[40]](_0x515d[39]);_0xcef5x47[_0x515d[35]]=_0x515d[85];_0xcef5x47[_0x515d[86]]=_0x515d[36];_0xcef5x48=document[_0x515d[40]](_0x515d[39]);_0xcef5x48[_0x515d[35]]=_0x515d[85];_0xcef5x48[_0x515d[86]]=_0x515d[87];_0xcef5x49=_0xcef5x4f();_0xcef5x4a=_0xcef5x56();SNAKE[_0x515d[0]](_0xcef5x45,_0x515d[88],function (_0xcef5x4c){if(!_0xcef5x4c){var _0xcef5x4c=window[_0x515d[89]];} ;_0xcef5x4c[_0x515d[90]]=true;if(_0xcef5x4c[_0x515d[91]]){_0xcef5x4c[_0x515d[91]]();} ;if(_0xcef5x4c[_0x515d[92]]){_0xcef5x4c[_0x515d[92]]();} ;return false;} ,false);_0xcef5x45[_0x515d[35]]=_0x515d[93];_0xcef5x45[_0x515d[27]](_0xcef5x46);_0xcef5x45[_0x515d[27]](_0xcef5x47);_0xcef5x45[_0x515d[27]](_0xcef5x48);_0xcef5x45[_0x515d[27]](_0xcef5x49);_0xcef5x45[_0x515d[27]](_0xcef5x4a);_0xcef5x42= new SNAKE.Snake({playingBoard:_0xcef5xf,startRow:2,startCol:2});_0xcef5x41= new SNAKE.Food({playingBoard:_0xcef5xf});_0xcef5x49[_0x515d[16]][_0x515d[58]]=1000;} ;function _0xcef5x4d(){return _0xcef5x3c*_0xcef5xf[_0x515d[25]]();} ;function _0xcef5x4e(){return _0xcef5x3d*_0xcef5xf[_0x515d[26]]();} ;function _0xcef5x4f(){var _0xcef5x50=document[_0x515d[40]](_0x515d[39]);_0xcef5x50[_0x515d[67]]=_0x515d[94]+_0xcef5x11;_0xcef5x50[_0x515d[35]]=_0x515d[95];var _0xcef5x51=document[_0x515d[40]](_0x515d[39]);var _0xcef5x52=_0x515d[36];if(_0xcef5xe[_0x515d[96]]){_0xcef5x52=_0x515d[97];} ;_0xcef5x51[_0x515d[86]]=_0x515d[98];var _0xcef5x53=document[_0x515d[40]](_0x515d[99]);_0xcef5x53[_0x515d[27]](document[_0x515d[101]](_0x515d[100]));var _0xcef5x54=function (){SNAKE[_0x515d[3]](window,_0x515d[88],_0xcef5x55,false);_0xcef5x50[_0x515d[16]][_0x515d[102]]=_0x515d[103];_0xcef5xf[_0x515d[104]](1);_0xcef5xf[_0x515d[28]]()[_0x515d[84]]();} ;var _0xcef5x55=function (_0xcef5x4c){if(!_0xcef5x4c){var _0xcef5x4c=window[_0x515d[89]];} ;var _0xcef5x20=(_0xcef5x4c[_0x515d[105]])?_0xcef5x4c[_0x515d[105]]:_0xcef5x4c[_0x515d[106]];if(_0xcef5x20===32||_0xcef5x20===13){_0xcef5x54();} ;} ;SNAKE[_0x515d[0]](window,_0x515d[88],_0xcef5x55,false);SNAKE[_0x515d[0]](_0xcef5x53,_0x515d[83],_0xcef5x54,false);_0xcef5x50[_0x515d[27]](_0xcef5x51);_0xcef5x50[_0x515d[27]](_0xcef5x53);return _0xcef5x50;} ;function _0xcef5x56(){var _0xcef5x50=document[_0x515d[40]](_0x515d[39]);_0xcef5x50[_0x515d[67]]=_0x515d[107]+_0xcef5x11;_0xcef5x50[_0x515d[35]]=_0x515d[108];var _0xcef5x57=document[_0x515d[40]](_0x515d[39]);_0xcef5x57[_0x515d[86]]=_0x515d[109];var _0xcef5x58=document[_0x515d[40]](_0x515d[110]);_0xcef5x58[_0x515d[69]](_0x515d[67],_0x515d[111]);var _0xcef5x59=document[_0x515d[40]](_0x515d[99]);_0xcef5x59[_0x515d[27]](document[_0x515d[101]](_0x515d[112]));var _0xcef5x5a=function (){_0xcef5x50[_0x515d[16]][_0x515d[102]]=_0x515d[103];_0xcef5xf[_0x515d[113]]();_0xcef5xf[_0x515d[104]](1);_0xcef5xf[_0x515d[28]]()[_0x515d[84]]();} ;var _0xcef5x5b=function (){var _0xcef5x5c= new XMLHttpRequest();var _0xcef5x5d=document[_0x515d[114]](_0x515d[111]);var _0xcef5x5e=_0xcef5x42[_0x515d[32]];var _0xcef5x5f=_0x515d[115]+encodeURIComponent(_0xcef5x5d[_0x515d[116]])+_0x515d[117]+encodeURIComponent(_0xcef5x5e)+_0x515d[118]+hex_md5(_0xcef5x5e+_0xcef5x5d[_0x515d[116]]+_0x515d[119]);_0xcef5x5c[_0x515d[122]](_0x515d[120],_0x515d[121],false);_0xcef5x5c[_0x515d[125]](_0x515d[123],_0x515d[124]);_0xcef5x5c[_0x515d[126]](_0xcef5x5f);var _0xcef5x60=_0xcef5x5c[_0x515d[127]];_0xcef5x5d[_0x515d[116]]=_0x515d[36];_0xcef5x5a();} ;var _0xcef5x61=function (_0xcef5x4c){if(_0xcef5x43!==0||_0xcef5x50[_0x515d[16]][_0x515d[102]]!==_0x515d[128]){return ;} ;if(!_0xcef5x4c){var _0xcef5x4c=window[_0x515d[89]];} ;var _0xcef5x20=(_0xcef5x4c[_0x515d[105]])?_0xcef5x4c[_0x515d[105]]:_0xcef5x4c[_0x515d[106]];if(_0xcef5x20===32||_0xcef5x20===13){_0xcef5x5a();} ;} ;SNAKE[_0x515d[0]](window,_0x515d[88],_0xcef5x61,true);SNAKE[_0x515d[0]](_0xcef5x59,_0x515d[83],_0xcef5x5b,false);_0xcef5x50[_0x515d[27]](_0xcef5x57);_0xcef5x50[_0x515d[27]](_0xcef5x58);_0xcef5x50[_0x515d[27]](_0xcef5x59);return _0xcef5x50;} ;_0xcef5xf[_0x515d[113]]=function (){SNAKE[_0x515d[3]](_0xcef5x45,_0x515d[129],_0xcef5x44,false);_0xcef5x42[_0x515d[61]]();_0xcef5x48[_0x515d[86]]=_0x515d[87];_0xcef5xf[_0x515d[130]]();} ;_0xcef5xf[_0x515d[131]]=function (){return _0xcef5x43;} ;_0xcef5xf[_0x515d[104]]=function (_0xcef5x62){_0xcef5x43=_0xcef5x62;} ;_0xcef5xf[_0x515d[53]]=function (){return _0xcef5x40;} ;_0xcef5xf[_0x515d[132]]=function (){return _0xcef5x46;} ;_0xcef5xf[_0x515d[133]]=function (_0xcef5x63){if( typeof _0xcef5x63===_0x515d[134]){_0xcef5x63=document[_0x515d[114]](_0xcef5x63);} ;if(_0xcef5x63===_0xcef5x45){return ;} ;_0xcef5x45=_0xcef5x63;_0xcef5x46=null;_0xcef5xf[_0x515d[130]]();} ;_0xcef5xf[_0x515d[28]]=function (){return _0xcef5x45;} ;_0xcef5xf[_0x515d[25]]=function (){return _0xcef5x3e;} ;_0xcef5xf[_0x515d[26]]=function (){return _0xcef5x3f;} ;_0xcef5xf[_0x515d[130]]=function (){if(!_0xcef5x46){_0xcef5x4b();} ;var _0xcef5x64,_0xcef5x65;if(_0xcef5xe[_0x515d[96]]===true){cTop=0;cLeft=0;_0xcef5x64=_0xcef5x37()-5;_0xcef5x65=_0xcef5x39()-5;document[_0x515d[79]][_0x515d[16]][_0x515d[135]]=_0x515d[136];} else {cTop=_0xcef5xe[_0x515d[31]];cLeft=_0xcef5xe[_0x515d[29]];_0xcef5x64=_0xcef5xe[_0x515d[43]];_0xcef5x65=_0xcef5xe[_0x515d[44]];} ;var _0xcef5x66=_0xcef5xf[_0x515d[25]]()*2+(_0xcef5x64%_0xcef5xf[_0x515d[25]]());var _0xcef5x67=Math[_0x515d[137]](_0xcef5x4d()-_0xcef5x66,_0xcef5x64-_0xcef5x66);var _0xcef5x68=_0xcef5xf[_0x515d[26]]()*3+(_0xcef5x65%_0xcef5xf[_0x515d[26]]());var _0xcef5x69=Math[_0x515d[137]](_0xcef5x4e()-_0xcef5x68,_0xcef5x65-_0xcef5x68);_0xcef5x45[_0x515d[16]][_0x515d[29]]=cLeft+_0x515d[30];_0xcef5x45[_0x515d[16]][_0x515d[31]]=cTop+_0x515d[30];_0xcef5x45[_0x515d[16]][_0x515d[43]]=_0xcef5x64+_0x515d[30];_0xcef5x45[_0x515d[16]][_0x515d[44]]=_0xcef5x65+_0x515d[30];_0xcef5x46[_0x515d[16]][_0x515d[29]]=_0xcef5xf[_0x515d[25]]()+_0x515d[30];_0xcef5x46[_0x515d[16]][_0x515d[31]]=_0xcef5xf[_0x515d[26]]()+_0x515d[30];_0xcef5x46[_0x515d[16]][_0x515d[43]]=_0xcef5x67+_0x515d[30];_0xcef5x46[_0x515d[16]][_0x515d[44]]=_0xcef5x69+_0x515d[30];var _0xcef5x6a=_0xcef5x68-_0xcef5xf[_0x515d[26]]();var _0xcef5x6b=_0xcef5xf[_0x515d[26]]()+_0xcef5x69+Math[_0x515d[138]]((_0xcef5x6a-30)/2)+_0x515d[30];_0xcef5x47[_0x515d[16]][_0x515d[31]]=_0xcef5x6b;_0xcef5x47[_0x515d[16]][_0x515d[43]]=_0x515d[139];_0xcef5x47[_0x515d[16]][_0x515d[29]]=Math[_0x515d[138]](_0xcef5x64/2)-Math[_0x515d[138]](450/2)+_0x515d[30];_0xcef5x48[_0x515d[16]][_0x515d[31]]=_0xcef5x6b;_0xcef5x48[_0x515d[16]][_0x515d[29]]=_0xcef5x64-120+_0x515d[30];if(_0xcef5x64<700){_0xcef5x47[_0x515d[16]][_0x515d[102]]=_0x515d[103];} else {_0xcef5x47[_0x515d[16]][_0x515d[102]]=_0x515d[128];} ;_0xcef5xf[_0x515d[50]]=[];var _0xcef5x6c=_0xcef5x67/_0xcef5xf[_0x515d[25]]()+2;var _0xcef5x6d=_0xcef5x69/_0xcef5xf[_0x515d[26]]()+2;for(var _0xcef5x32=0;_0xcef5x32<_0xcef5x6d;_0xcef5x32++){_0xcef5xf[_0x515d[50]][_0xcef5x32]=[];for(var _0xcef5x33=0;_0xcef5x33<_0xcef5x6c;_0xcef5x33++){if(_0xcef5x33===0||_0xcef5x32===0||_0xcef5x33===(_0xcef5x6c-1)||_0xcef5x32===(_0xcef5x6d-1)){_0xcef5xf[_0x515d[50]][_0xcef5x32][_0xcef5x33]=1;} else {_0xcef5xf[_0x515d[50]][_0xcef5x32][_0xcef5x33]=0;} ;} ;} ;_0xcef5x41[_0x515d[72]]();_0xcef5x44=function (_0xcef5x4c){if(!_0xcef5x4c){var _0xcef5x4c=window[_0x515d[89]];} ;var _0xcef5x20=(_0xcef5x4c[_0x515d[105]])?_0xcef5x4c[_0x515d[105]]:_0xcef5x4c[_0x515d[106]];if(_0xcef5xf[_0x515d[131]]()===1){if(!(_0xcef5x20>=37&&_0xcef5x20<=40)){return ;} ;SNAKE[_0x515d[3]](_0xcef5x45,_0x515d[129],_0xcef5x44,false);_0xcef5x44=function (_0xcef5x4c){if(!_0xcef5x4c){var _0xcef5x4c=window[_0x515d[89]];} ;var _0xcef5x20=(_0xcef5x4c[_0x515d[105]])?_0xcef5x4c[_0x515d[105]]:_0xcef5x4c[_0x515d[106]];_0xcef5x42[_0x515d[47]](_0xcef5x20);_0xcef5x4c[_0x515d[90]]=true;if(_0xcef5x4c[_0x515d[91]]){_0xcef5x4c[_0x515d[91]]();} ;if(_0xcef5x4c[_0x515d[92]]){_0xcef5x4c[_0x515d[92]]();} ;return false;} ;SNAKE[_0x515d[0]](_0xcef5x45,_0x515d[129],_0xcef5x44,false);_0xcef5x42[_0x515d[60]]();_0xcef5x42[_0x515d[47]](_0xcef5x20);_0xcef5xf[_0x515d[104]](2);_0xcef5x42[_0x515d[49]]();} ;_0xcef5x4c[_0x515d[90]]=true;if(_0xcef5x4c[_0x515d[91]]){_0xcef5x4c[_0x515d[91]]();} ;if(_0xcef5x4c[_0x515d[92]]){_0xcef5x4c[_0x515d[92]]();} ;return false;} ;SNAKE[_0x515d[0]](_0xcef5x45,_0x515d[129],_0xcef5x44,false);} ;_0xcef5xf[_0x515d[57]]=function (){_0xcef5x48[_0x515d[86]]=_0x515d[140]+_0xcef5x42[_0x515d[32]];_0xcef5x41[_0x515d[72]]();} ;_0xcef5xf[_0x515d[52]]=function (){var _0xcef5x28=Math[_0x515d[141]](_0xcef5x9(_0xcef5x42[_0x515d[21]]),_0xcef5x9({tmp:{elm:_0xcef5x41[_0x515d[71]]()}}));_0xcef5x45[_0x515d[142]](_0xcef5x4a);_0xcef5x45[_0x515d[27]](_0xcef5x4a);SNAKE[_0x515d[3]](_0xcef5x45,_0x515d[129],_0xcef5x44,false);_0xcef5x4a[_0x515d[16]][_0x515d[58]]=_0xcef5x28;_0xcef5x4a[_0x515d[16]][_0x515d[102]]=_0x515d[128];_0xcef5xf[_0x515d[104]](0);} ;_0xcef5xe[_0x515d[96]]=( typeof _0xcef5xe[_0x515d[96]]===_0x515d[143])?false:_0xcef5xe[_0x515d[96]];_0xcef5xe[_0x515d[31]]=( typeof _0xcef5xe[_0x515d[31]]===_0x515d[143])?0:_0xcef5xe[_0x515d[31]];_0xcef5xe[_0x515d[29]]=( typeof _0xcef5xe[_0x515d[29]]===_0x515d[143])?0:_0xcef5xe[_0x515d[29]];_0xcef5xe[_0x515d[43]]=( typeof _0xcef5xe[_0x515d[43]]===_0x515d[143])?400:_0xcef5xe[_0x515d[43]];_0xcef5xe[_0x515d[44]]=( typeof _0xcef5xe[_0x515d[44]]===_0x515d[143])?400:_0xcef5xe[_0x515d[44]];if(_0xcef5xe[_0x515d[96]]){SNAKE[_0x515d[0]](window,_0x515d[144],function (){_0xcef5xf[_0x515d[130]]();} ,false);} ;_0xcef5xf[_0x515d[104]](0);if(_0xcef5xe[_0x515d[145]]){_0xcef5xf[_0x515d[133]](_0xcef5xe[_0x515d[145]]);} ;} ;} )(); ./www/js/snake_.js0000755000175000017500000011152712216072131013704 0ustar ubuntuubuntu/* JavaScript Snake By Patrick Gillespie http://patorjk.com/games/snake */ /** * @module Snake * @class SNAKE */ var SNAKE = SNAKE || {}; /** * @method addEventListener * @param {Object} obj The object to add an event listener to. * @param {String} event The event to listen for. * @param {Function} funct The function to execute when the event is triggered. * @param {Boolean} evtCapturing True to do event capturing, false to do event bubbling. */ SNAKE.addEventListener = (function() { if (window.addEventListener) { return function(obj, event, funct, evtCapturing) { obj.addEventListener(event, funct, evtCapturing); }; } else if (window.attachEvent) { return function(obj, event, funct) { obj.attachEvent("on" + event, funct); }; } })(); /** * @method removeEventListener * @param {Object} obj The object to remove an event listener from. * @param {String} event The event that was listened for. * @param {Function} funct The function that was executed when the event is triggered. * @param {Boolean} evtCapturing True if event capturing was done, false otherwise. */ SNAKE.removeEventListener = (function() { if (window.removeEventListener) { return function(obj, event, funct, evtCapturing) { obj.removeEventListener(event, funct, evtCapturing); }; } else if (window.detachEvent) { return function(obj, event, funct) { obj.detachEvent("on" + event, funct); }; } })(); /** * This class manages the snake which will reside inside of a SNAKE.Board object. * @class Snake * @constructor * @namespace SNAKE * @param {Object} config The configuration object for the class. Contains playingBoard (the SNAKE.Board that this snake resides in), startRow and startCol. */ SNAKE.Snake = SNAKE.Snake || (function() { // ------------------------------------------------------------------------- // Private static variables and methods // ------------------------------------------------------------------------- var instanceNumber = 0; var blockPool = []; var SnakeBlock = function() { this.elm = null; this.elmStyle = null; this.row = -1; this.col = -1; this.xPos = -1000; this.yPos = -1000; this.next = null; this.prev = null; }; // this function is adapted from the example at http://greengeckodesign.com/blog/2007/07/get-highest-z-index-in-javascript.html function getNextHighestZIndex(myObj) { var highestIndex = 0, currentIndex = 0, ii; for (ii in myObj) { if (myObj[ii].elm.currentStyle){ currentIndex = parseFloat(myObj[ii].elm.style["z-index"],10); }else if(window.getComputedStyle) { currentIndex = parseFloat(document.defaultView.getComputedStyle(myObj[ii].elm,null).getPropertyValue("z-index"),10); } if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; } } return(highestIndex+1); } // ------------------------------------------------------------------------- // Contructor + public and private definitions // ------------------------------------------------------------------------- /* config options: playingBoard - the SnakeBoard that this snake belongs too. startRow - The row the snake should start on. startCol - The column the snake should start on. */ return function(config) { if (!config||!config.playingBoard) {return;} // ----- private variables ----- var me = this, playingBoard = config.playingBoard, myId = instanceNumber++, growthIncr = 5, moveQueue = [], // a queue that holds the next moves of the snake currentDirection = 1, // 0: up, 1: left, 2: down, 3: right columnShift = [0, 1, 0, -1], rowShift = [-1, 0, 1, 0], xPosShift = [], yPosShift = [], snakeSpeed = 75, isDead = false; // ----- public variables ----- me.snakeBody = {}; me.snakeBody["b0"] = new SnakeBlock(); // create snake head me.snakeBody["b0"].row = config.startRow || 1; me.snakeBody["b0"].col = config.startCol || 1; me.snakeBody["b0"].xPos = me.snakeBody["b0"].row * playingBoard.getBlockWidth(); me.snakeBody["b0"].yPos = me.snakeBody["b0"].col * playingBoard.getBlockHeight(); me.snakeBody["b0"].elm = createSnakeElement(); me.snakeBody["b0"].elmStyle = me.snakeBody["b0"].elm.style; playingBoard.getBoardContainer().appendChild( me.snakeBody["b0"].elm ); me.snakeBody["b0"].elm.style.left = me.snakeBody["b0"].xPos + "px"; me.snakeBody["b0"].elm.style.top = me.snakeBody["b0"].yPos + "px"; me.snakeBody["b0"].next = me.snakeBody["b0"]; me.snakeBody["b0"].prev = me.snakeBody["b0"]; me.snakeLength = 1; me.snakeHead = me.snakeBody["b0"]; me.snakeTail = me.snakeBody["b0"]; me.snakeHead.elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-dead\b/,''); me.snakeHead.elm.className += " snake-snakebody-alive"; // ----- private methods ----- function createSnakeElement() { var tempNode = document.createElement("div"); tempNode.className = "snake-snakebody-block"; tempNode.style.left = "-1000px"; tempNode.style.top = "-1000px"; tempNode.style.width = playingBoard.getBlockWidth() + "px"; tempNode.style.height = playingBoard.getBlockHeight() + "px"; return tempNode; } function createBlocks(num) { var tempBlock; var tempNode = createSnakeElement(); for (var ii = 1; ii < num; ii++){ tempBlock = new SnakeBlock(); tempBlock.elm = tempNode.cloneNode(true); tempBlock.elmStyle = tempBlock.elm.style; playingBoard.getBoardContainer().appendChild( tempBlock.elm ); blockPool[blockPool.length] = tempBlock; } tempBlock = new SnakeBlock(); tempBlock.elm = tempNode; playingBoard.getBoardContainer().appendChild( tempBlock.elm ); blockPool[blockPool.length] = tempBlock; } // ----- public methods ----- /** * This method is called when a user presses a key. It logs arrow key presses in "moveQueue", which is used when the snake needs to make its next move. * @method handleArrowKeys * @param {Number} keyNum A number representing the key that was pressed. */ /* Handles what happens when an arrow key is pressed. Direction explained (0 = up, etc etc) 0 3 1 2 */ me.handleArrowKeys = function(keyNum) { if (isDead) {return;} var snakeLength = me.snakeLength; var lastMove = moveQueue[0] || currentDirection; switch (keyNum) { case 37: if ( lastMove !== 1 || snakeLength === 1 ) { moveQueue.unshift(3); //SnakeDirection = 3; } break; case 38: if ( lastMove !== 2 || snakeLength === 1 ) { moveQueue.unshift(0);//SnakeDirection = 0; } break; case 39: if ( lastMove !== 3 || snakeLength === 1 ) { moveQueue.unshift(1); //SnakeDirection = 1; } break; case 40: if ( lastMove !== 0 || snakeLength === 1 ) { moveQueue.unshift(2);//SnakeDirection = 2; } break; } }; /** * This method is executed for each move of the snake. It determines where the snake will go and what will happen to it. This method needs to run quickly. * @method go */ me.go = function() { var oldHead = me.snakeHead, newHead = me.snakeTail, myDirection = currentDirection, grid = playingBoard.grid; // cache grid for quicker lookup me.snakeTail = newHead.prev; me.snakeHead = newHead; // clear the old board position if ( grid[newHead.row] && grid[newHead.row][newHead.col] ) { grid[newHead.row][newHead.col] = 0; } if (moveQueue.length){ myDirection = currentDirection = moveQueue.pop(); } newHead.col = oldHead.col + columnShift[myDirection]; newHead.row = oldHead.row + rowShift[myDirection]; newHead.xPos = oldHead.xPos + xPosShift[myDirection]; newHead.yPos = oldHead.yPos + yPosShift[myDirection]; if ( !newHead.elmStyle ) { newHead.elmStyle = newHead.elm.style; } newHead.elmStyle.left = newHead.xPos + "px"; newHead.elmStyle.top = newHead.yPos + "px"; // check the new spot the snake moved into if (grid[newHead.row][newHead.col] === 0) { grid[newHead.row][newHead.col] = 1; setTimeout(function(){me.go();}, snakeSpeed); } else if (grid[newHead.row][newHead.col] > 0) { me.handleDeath(); } else if (grid[newHead.row][newHead.col] === playingBoard.getGridFoodValue()) { grid[newHead.row][newHead.col] = 1; me.eatFood(); setTimeout(function(){me.go();}, snakeSpeed); } }; /** * This method is called when it is determined that the snake has eaten some food. * @method eatFood */ me.eatFood = function() { if (blockPool.length <= growthIncr) { createBlocks(growthIncr*2); } var blocks = blockPool.splice(0, growthIncr); var ii = blocks.length, index, prevNode = me.snakeTail; while (ii--) { index = "b" + me.snakeLength++; me.snakeBody[index] = blocks[ii]; me.snakeBody[index].prev = prevNode; me.snakeBody[index].elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-dead\b/,'') me.snakeBody[index].elm.className += " snake-snakebody-alive"; prevNode.next = me.snakeBody[index]; prevNode = me.snakeBody[index]; } me.snakeTail = me.snakeBody[index]; me.snakeTail.next = me.snakeHead; me.snakeHead.prev = me.snakeTail; playingBoard.foodEaten(); }; /** * This method handles what happens when the snake dies. * @method handleDeath */ me.handleDeath = function() { me.snakeHead.elm.style.zIndex = getNextHighestZIndex(me.snakeBody); me.snakeHead.elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-alive\b/,'') me.snakeHead.elm.className += " snake-snakebody-dead"; isDead = true; playingBoard.handleDeath(); moveQueue.length = 0; }; /** * This method sets a flag that lets the snake be alive again. * @method rebirth */ me.rebirth = function() { isDead = false; }; /** * This method reset the snake so it is ready for a new game. * @method reset */ me.reset = function() { if (isDead === false) {return;} var blocks = [], curNode = me.snakeHead.next, nextNode; while (curNode !== me.snakeHead) { nextNode = curNode.next; curNode.prev = null; curNode.next = null; blocks.push(curNode); curNode = nextNode; } me.snakeHead.next = me.snakeHead; me.snakeHead.prev = me.snakeHead; me.snakeTail = me.snakeHead; me.snakeLength = 1; for (var ii = 0; ii < blocks.length; ii++) { blocks[ii].elm.style.left = "-1000px"; blocks[ii].elm.style.top = "-1000px"; blocks[ii].elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-dead\b/,'') blocks[ii].elm.className += " snake-snakebody-alive"; } blockPool.concat(blocks); me.snakeHead.elm.className = me.snakeHead.elm.className.replace(/\bsnake-snakebody-dead\b/,'') me.snakeHead.elm.className += " snake-snakebody-alive"; me.snakeHead.row = config.startRow || 1; me.snakeHead.col = config.startCol || 1; me.snakeHead.xPos = me.snakeHead.row * playingBoard.getBlockWidth(); me.snakeHead.yPos = me.snakeHead.col * playingBoard.getBlockHeight(); me.snakeHead.elm.style.left = me.snakeHead.xPos + "px"; me.snakeHead.elm.style.top = me.snakeHead.yPos + "px"; }; // --------------------------------------------------------------------- // Initialize // --------------------------------------------------------------------- createBlocks(growthIncr*2); xPosShift[0] = 0; xPosShift[1] = playingBoard.getBlockWidth(); xPosShift[2] = 0; xPosShift[3] = -1 * playingBoard.getBlockWidth(); yPosShift[0] = -1 * playingBoard.getBlockHeight(); yPosShift[1] = 0; yPosShift[2] = playingBoard.getBlockHeight(); yPosShift[3] = 0; }; })(); /** * This class manages the food which the snake will eat. * @class Food * @constructor * @namespace SNAKE * @param {Object} config The configuration object for the class. Contains playingBoard (the SNAKE.Board that this food resides in). */ SNAKE.Food = SNAKE.Food || (function() { // ------------------------------------------------------------------------- // Private static variables and methods // ------------------------------------------------------------------------- var instanceNumber = 0; function getRandomPosition(x, y){ return Math.floor(Math.random()*(y+1-x)) + x; } // ------------------------------------------------------------------------- // Contructor + public and private definitions // ------------------------------------------------------------------------- /* config options: playingBoard - the SnakeBoard that this object belongs too. */ return function(config) { if (!config||!config.playingBoard) {return;} // ----- private variables ----- var me = this; var playingBoard = config.playingBoard; var fRow, fColumn; var myId = instanceNumber++; var elmFood = document.createElement("div"); elmFood.setAttribute("id", "snake-food-"+myId); elmFood.className = "snake-food-block"; elmFood.style.width = playingBoard.getBlockWidth() + "px"; elmFood.style.height = playingBoard.getBlockHeight() + "px"; elmFood.style.left = "-1000px"; elmFood.style.top = "-1000px"; playingBoard.getBoardContainer().appendChild(elmFood); // ----- public methods ----- /** * @method getFoodElement * @return {DOM Element} The div the represents the food. */ me.getFoodElement = function() { return elmFood; }; /** * Randomly places the food onto an available location on the playing board. * @method randomlyPlaceFood */ me.randomlyPlaceFood = function() { // if there exist some food, clear its presence from the board if (playingBoard.grid[fRow] && playingBoard.grid[fRow][fColumn] === playingBoard.getGridFoodValue()){ playingBoard.grid[fRow][fColumn] = 0; } var row = 0, col = 0, numTries = 0; var maxRows = playingBoard.grid.length-1; var maxCols = playingBoard.grid[0].length-1; while (playingBoard.grid[row][col] !== 0){ row = getRandomPosition(1, maxRows); col = getRandomPosition(1, maxCols); // in some cases there may not be any room to put food anywhere // instead of freezing, exit out numTries++; if (numTries > 20000){ row = -1; col = -1; break; } } playingBoard.grid[row][col] = playingBoard.getGridFoodValue(); fRow = row; fColumn = col; elmFood.style.top = row * playingBoard.getBlockHeight() + "px"; elmFood.style.left = col * playingBoard.getBlockWidth() + "px"; }; }; })(); /** * This class manages playing board for the game. * @class Board * @constructor * @namespace SNAKE * @param {Object} config The configuration object for the class. Set fullScreen equal to true if you want the game to take up the full screen, otherwise, set the top, left, width and height parameters. */ SNAKE.Board = SNAKE.Board || (function() { // ------------------------------------------------------------------------- // Private static variables and methods // ------------------------------------------------------------------------- var instanceNumber = 0; // this function is adapted from the example at http://greengeckodesign.com/blog/2007/07/get-highest-z-index-in-javascript.html function getNextHighestZIndex(myObj) { var highestIndex = 0, currentIndex = 0, ii; for (ii in myObj) { if (myObj[ii].elm.currentStyle){ currentIndex = parseFloat(myObj[ii].elm.style["z-index"],10); }else if(window.getComputedStyle) { currentIndex = parseFloat(document.defaultView.getComputedStyle(myObj[ii].elm,null).getPropertyValue("z-index"),10); } if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; } } return(highestIndex+1); } /* This function returns the width of the available screen real estate that we have */ function getClientWidth(){ var myWidth = 0; if( typeof window.innerWidth === "number" ) { myWidth = window.innerWidth;//Non-IE } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { myWidth = document.documentElement.clientWidth;//IE 6+ in 'standards compliant mode' } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { myWidth = document.body.clientWidth;//IE 4 compatible } return myWidth; } /* This function returns the height of the available screen real estate that we have */ function getClientHeight(){ var myHeight = 0; if( typeof window.innerHeight === "number" ) { myHeight = window.innerHeight;//Non-IE } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { myHeight = document.documentElement.clientHeight;//IE 6+ in 'standards compliant mode' } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { myHeight = document.body.clientHeight;//IE 4 compatible } return myHeight; } // ------------------------------------------------------------------------- // Contructor + public and private definitions // ------------------------------------------------------------------------- return function(inputConfig) { // --- private variables --- var me = this, myId = instanceNumber++, config = inputConfig || {}, MAX_BOARD_COLS = 250, MAX_BOARD_ROWS = 250, blockWidth = 20, blockHeight = 20, GRID_FOOD_VALUE = -1, // the value of a spot on the board that represents snake food, MUST BE NEGATIVE myFood, mySnake, boardState = 1, // 0: in active; 1: awaiting game start; 2: playing game myKeyListener, // Board components elmContainer, elmPlayingField, elmAboutPanel, elmLengthPanel, elmWelcome, elmTryAgain; // --- public variables --- me.grid = []; // --------------------------------------------------------------------- // private functions // --------------------------------------------------------------------- function createBoardElements() { elmPlayingField = document.createElement("div"); elmPlayingField.setAttribute("id", "playingField"); elmPlayingField.className = "snake-playing-field"; SNAKE.addEventListener(elmPlayingField, "click", function() { elmContainer.focus(); }, false); elmAboutPanel = document.createElement("div"); elmAboutPanel.className = "snake-panel-component"; elmAboutPanel.innerHTML = ''; elmLengthPanel = document.createElement("div"); elmLengthPanel.className = "snake-panel-component"; elmLengthPanel.innerHTML = "Length: 1"; elmWelcome = createWelcomeElement(); elmTryAgain = createTryAgainElement(); SNAKE.addEventListener( elmContainer, "keyup", function(evt) { if (!evt) var evt = window.event; evt.cancelBubble = true; if (evt.stopPropagation) {evt.stopPropagation();} if (evt.preventDefault) {evt.preventDefault();} return false; }, false); elmContainer.className = "snake-game-container"; elmContainer.appendChild(elmPlayingField); elmContainer.appendChild(elmAboutPanel); elmContainer.appendChild(elmLengthPanel); elmContainer.appendChild(elmWelcome); elmContainer.appendChild(elmTryAgain); mySnake = new SNAKE.Snake({playingBoard:me,startRow:2,startCol:2}); myFood = new SNAKE.Food({playingBoard: me}); elmWelcome.style.zIndex = 1000; } function maxBoardWidth() { return MAX_BOARD_COLS * me.getBlockWidth(); } function maxBoardHeight() { return MAX_BOARD_ROWS * me.getBlockHeight(); } function createWelcomeElement() { var tmpElm = document.createElement("div"); tmpElm.id = "sbWelcome" + myId; tmpElm.className = "snake-welcome-dialog"; var welcomeTxt = document.createElement("div"); var fullScreenText = ""; if (config.fullScreen) { fullScreenText = "On Windows, press F11 to play in Full Screen mode."; } welcomeTxt.innerHTML = 'Welcome!

You need to be registered user to be able to save game results and manage personal statistics. Register here

'; var welcomeStart = document.createElement("button"); welcomeStart.appendChild( document.createTextNode("Play Game")); var loadGame = function() { SNAKE.removeEventListener(window, "keyup", kbShortcut, false); tmpElm.style.display = "none"; me.setBoardState(1); me.getBoardContainer().focus(); }; var kbShortcut = function(evt) { if (!evt) var evt = window.event; var keyNum = (evt.which) ? evt.which : evt.keyCode; if (keyNum === 32 || keyNum === 13) { loadGame(); } }; SNAKE.addEventListener(window, "keyup", kbShortcut, false); SNAKE.addEventListener(welcomeStart, "click", loadGame, false); tmpElm.appendChild(welcomeTxt); tmpElm.appendChild(welcomeStart); return tmpElm; } function createTryAgainElement() { var tmpElm = document.createElement("div"); tmpElm.id = "sbTryAgain" + myId; tmpElm.className = "snake-try-again-dialog"; var tryAgainTxt = document.createElement("div"); tryAgainTxt.innerHTML = "Submit score
Your login:"; var loginField= document.createElement("input"); loginField.setAttribute("id","playername"); var sendScoreBtn = document.createElement("button"); sendScoreBtn.appendChild(document.createTextNode("Submit")); var reloadGame = function() { tmpElm.style.display = "none"; me.resetBoard(); me.setBoardState(1); me.getBoardContainer().focus(); }; var SendScore = function() { var req = new XMLHttpRequest(); var login = document.getElementById("playername"); var score = mySnake.snakeLength; var params = 'playerName='+encodeURIComponent(login.value)+'&playerScore='+encodeURIComponent(score)+'&hash='+hex_md5(score+login.value+'pc8XW2xUJcWMFVGkZ5PL'); req.open('POST', '/cgi-bin/save.pl', false); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') req.send(params); var resp_text = req.responseText; login.value = ""; reloadGame(); } var kbTryAgainShortcut = function(evt) { if (boardState !== 0 || tmpElm.style.display !== "block") {return;} if (!evt) var evt = window.event; var keyNum = (evt.which) ? evt.which : evt.keyCode; if (keyNum === 32 || keyNum === 13) { reloadGame(); } }; SNAKE.addEventListener(window, "keyup", kbTryAgainShortcut, true); SNAKE.addEventListener(sendScoreBtn, "click", SendScore, false); tmpElm.appendChild(tryAgainTxt); tmpElm.appendChild(loginField); tmpElm.appendChild(sendScoreBtn); return tmpElm; } // --------------------------------------------------------------------- // public functions // --------------------------------------------------------------------- /** * Resets the playing board for a new game. * @method resetBoard */ me.resetBoard = function() { SNAKE.removeEventListener(elmContainer, "keydown", myKeyListener, false); mySnake.reset(); elmLengthPanel.innerHTML = "Length: 1"; me.setupPlayingField(); }; /** * Gets the current state of the playing board. There are 3 states: 0 - Welcome or Try Again dialog is present. 1 - User has pressed "Start Game" on the Welcome or Try Again dialog but has not pressed an arrow key to move the snake. 2 - The game is in progress and the snake is moving. * @method getBoardState * @return {Number} The state of the board. */ me.getBoardState = function() { return boardState; }; /** * Sets the current state of the playing board. There are 3 states: 0 - Welcome or Try Again dialog is present. 1 - User has pressed "Start Game" on the Welcome or Try Again dialog but has not pressed an arrow key to move the snake. 2 - The game is in progress and the snake is moving. * @method setBoardState * @param {Number} state The state of the board. */ me.setBoardState = function(state) { boardState = state; }; /** * @method getGridFoodValue * @return {Number} A number that represents food on a number representation of the playing board. */ me.getGridFoodValue = function() { return GRID_FOOD_VALUE; }; /** * @method getPlayingFieldElement * @return {DOM Element} The div representing the playing field (this is where the snake can move). */ me.getPlayingFieldElement = function() { return elmPlayingField; }; /** * @method setBoardContainer * @param {DOM Element or String} myContainer Sets the container element for the game. */ me.setBoardContainer = function(myContainer) { if (typeof myContainer === "string") { myContainer = document.getElementById(myContainer); } if (myContainer === elmContainer) {return;} elmContainer = myContainer; elmPlayingField = null; me.setupPlayingField(); }; /** * @method getBoardContainer * @return {DOM Element} */ me.getBoardContainer = function() { return elmContainer; }; /** * @method getBlockWidth * @return {Number} */ me.getBlockWidth = function() { return blockWidth; }; /** * @method getBlockHeight * @return {Number} */ me.getBlockHeight = function() { return blockHeight; }; /** * Sets up the playing field. * @method setupPlayingField */ me.setupPlayingField = function () { if (!elmPlayingField) {createBoardElements();} // create playing field // calculate width of our game container var cWidth, cHeight; if (config.fullScreen === true) { cTop = 0; cLeft = 0; cWidth = getClientWidth()-5; cHeight = getClientHeight()-5; document.body.style.backgroundColor = "#FC5454"; } else { cTop = config.top; cLeft = config.left; cWidth = config.width; cHeight = config.height; } // define the dimensions of the board and playing field var wEdgeSpace = me.getBlockWidth()*2 + (cWidth % me.getBlockWidth()); var fWidth = Math.min(maxBoardWidth()-wEdgeSpace,cWidth-wEdgeSpace); var hEdgeSpace = me.getBlockHeight()*3 + (cHeight % me.getBlockHeight()); var fHeight = Math.min(maxBoardHeight()-hEdgeSpace,cHeight-hEdgeSpace); elmContainer.style.left = cLeft + "px"; elmContainer.style.top = cTop + "px"; elmContainer.style.width = cWidth + "px"; elmContainer.style.height = cHeight + "px"; elmPlayingField.style.left = me.getBlockWidth() + "px"; elmPlayingField.style.top = me.getBlockHeight() + "px"; elmPlayingField.style.width = fWidth + "px"; elmPlayingField.style.height = fHeight + "px"; // the math for this will need to change depending on font size, padding, etc // assuming height of 14 (font size) + 8 (padding) var bottomPanelHeight = hEdgeSpace - me.getBlockHeight(); var pLabelTop = me.getBlockHeight() + fHeight + Math.round((bottomPanelHeight - 30)/2) + "px"; elmAboutPanel.style.top = pLabelTop; elmAboutPanel.style.width = "450px"; elmAboutPanel.style.left = Math.round(cWidth/2) - Math.round(450/2) + "px"; elmLengthPanel.style.top = pLabelTop; elmLengthPanel.style.left = cWidth - 120 + "px"; // if width is too narrow, hide the about panel if (cWidth < 700) { elmAboutPanel.style.display = "none"; } else { elmAboutPanel.style.display = "block"; } me.grid = []; var numBoardCols = fWidth / me.getBlockWidth() + 2; var numBoardRows = fHeight / me.getBlockHeight() + 2; for (var row = 0; row < numBoardRows; row++) { me.grid[row] = []; for (var col = 0; col < numBoardCols; col++) { if (col === 0 || row === 0 || col === (numBoardCols-1) || row === (numBoardRows-1)) { me.grid[row][col] = 1; // an edge } else { me.grid[row][col] = 0; // empty space } } } myFood.randomlyPlaceFood(); // setup event listeners myKeyListener = function(evt) { if (!evt) var evt = window.event; var keyNum = (evt.which) ? evt.which : evt.keyCode; if (me.getBoardState() === 1) { if ( !(keyNum >= 37 && keyNum <= 40) ) {return;} // if not an arrow key, leave // This removes the listener added at the #listenerX line SNAKE.removeEventListener(elmContainer, "keydown", myKeyListener, false); myKeyListener = function(evt) { if (!evt) var evt = window.event; var keyNum = (evt.which) ? evt.which : evt.keyCode; mySnake.handleArrowKeys(keyNum); evt.cancelBubble = true; if (evt.stopPropagation) {evt.stopPropagation();} if (evt.preventDefault) {evt.preventDefault();} return false; }; SNAKE.addEventListener( elmContainer, "keydown", myKeyListener, false); mySnake.rebirth(); mySnake.handleArrowKeys(keyNum); me.setBoardState(2); // start the game! mySnake.go(); } evt.cancelBubble = true; if (evt.stopPropagation) {evt.stopPropagation();} if (evt.preventDefault) {evt.preventDefault();} return false; }; // Search for #listenerX to see where this is removed SNAKE.addEventListener( elmContainer, "keydown", myKeyListener, false); }; /** * This method is called when the snake has eaten some food. * @method foodEaten */ me.foodEaten = function() { elmLengthPanel.innerHTML = "Length: " + mySnake.snakeLength; myFood.randomlyPlaceFood(); }; /** * This method is called when the snake dies. * @method handleDeath */ me.handleDeath = function() { var index = Math.max(getNextHighestZIndex( mySnake.snakeBody), getNextHighestZIndex( {tmp:{elm:myFood.getFoodElement()}} )); elmContainer.removeChild(elmTryAgain); elmContainer.appendChild(elmTryAgain); SNAKE.removeEventListener(elmContainer, "keydown", myKeyListener, false); elmTryAgain.style.zIndex = index; elmTryAgain.style.display = "block"; me.setBoardState(0); }; // --------------------------------------------------------------------- // Initialize // --------------------------------------------------------------------- config.fullScreen = (typeof config.fullScreen === "undefined") ? false : config.fullScreen; config.top = (typeof config.top === "undefined") ? 0 : config.top; config.left = (typeof config.left === "undefined") ? 0 : config.left; config.width = (typeof config.width === "undefined") ? 400 : config.width; config.height = (typeof config.height === "undefined") ? 400 : config.height; if (config.fullScreen) { SNAKE.addEventListener(window,"resize", function() { me.setupPlayingField(); }, false); } me.setBoardState(0); if (config.boardContainer) { me.setBoardContainer(config.boardContainer); } }; // end return function })();