<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs 
 title="Tetriculis - a Game Like Tetris!"
 directory_title="Tetriculis - a Game Like Tetris!"
 title_url="http://www.airspace-v.com/ggadgets/index.php4"
 description="Tetriculis - a Game like Tetris! Tetrablocks are falling from the sky and ask you to pack them to piles. They will vanish and give you points as reward!"
 author="Thomas Bremer"
 author_email="gadgets@airspace-v.com"
 author_location="Schwelm, Germany"
 author_affiliation="Druckerei Robert Beste GmbH"
 author_aboutme="Software engineer. Background compiler construction - widely applicable. Think about former jobs of Eric Schmidt..."
 author-quote="Quote? Sorry, I'm too creative for that!"
 height="420"
 screenshot="http://img.airspace-v.com/tetriculis.png"
 thumbnail="http://img.airspace-v.com/tetriculisThumb.png"
>
<Require feature="setprefs"/>
<Locale messages="datetime_content/en_ALL.xml" />
</ModulePrefs>
<UserPref name="HighScores" datatype="hidden" />
<UserPref name="l" display_name="Left" default_value="66" datatype="enum">
<EnumValue value="32" display_value="&lt;SPC&gt;" />
<EnumValue value="48" display_value="0" />
<EnumValue value="49" display_value="1" />
<EnumValue value="50" display_value="2" />
<EnumValue value="51" display_value="3" />
<EnumValue value="52" display_value="4" />
<EnumValue value="53" display_value="5" />
<EnumValue value="54" display_value="6" />
<EnumValue value="55" display_value="7" />
<EnumValue value="56" display_value="8" />
<EnumValue value="57" display_value="9" />
<EnumValue value="64" display_value="@" />
<EnumValue value="65" display_value="A" />
<EnumValue value="66" display_value="B" />
<EnumValue value="67" display_value="C" />
<EnumValue value="68" display_value="D" />
<EnumValue value="69" display_value="E" />
<EnumValue value="70" display_value="F" />
<EnumValue value="71" display_value="G" />
<EnumValue value="72" display_value="H" />
<EnumValue value="73" display_value="I" />
<EnumValue value="74" display_value="J" />
<EnumValue value="75" display_value="K" />
<EnumValue value="76" display_value="L" />
<EnumValue value="77" display_value="M" />
<EnumValue value="78" display_value="N" />
<EnumValue value="79" display_value="O" />
<EnumValue value="80" display_value="P" />
<EnumValue value="81" display_value="Q" />
<EnumValue value="82" display_value="R" />
<EnumValue value="83" display_value="S" />
<EnumValue value="84" display_value="T" />
<EnumValue value="85" display_value="U" />
<EnumValue value="86" display_value="V" />
<EnumValue value="87" display_value="W" />
<EnumValue value="88" display_value="X" />
<EnumValue value="89" display_value="Y" />
<EnumValue value="90" display_value="Z" />
</UserPref>

<UserPref name="r" display_name="Right" default_value="77" datatype="enum">
<EnumValue value="32" display_value="&lt;SPC&gt;" />
<EnumValue value="48" display_value="0" />
<EnumValue value="49" display_value="1" />
<EnumValue value="50" display_value="2" />
<EnumValue value="51" display_value="3" />
<EnumValue value="52" display_value="4" />
<EnumValue value="53" display_value="5" />
<EnumValue value="54" display_value="6" />
<EnumValue value="55" display_value="7" />
<EnumValue value="56" display_value="8" />
<EnumValue value="57" display_value="9" />
<EnumValue value="64" display_value="@" />
<EnumValue value="65" display_value="A" />
<EnumValue value="66" display_value="B" />
<EnumValue value="67" display_value="C" />
<EnumValue value="68" display_value="D" />
<EnumValue value="69" display_value="E" />
<EnumValue value="70" display_value="F" />
<EnumValue value="71" display_value="G" />
<EnumValue value="72" display_value="H" />
<EnumValue value="73" display_value="I" />
<EnumValue value="74" display_value="J" />
<EnumValue value="75" display_value="K" />
<EnumValue value="76" display_value="L" />
<EnumValue value="77" display_value="M" />
<EnumValue value="78" display_value="N" />
<EnumValue value="79" display_value="O" />
<EnumValue value="80" display_value="P" />
<EnumValue value="81" display_value="Q" />
<EnumValue value="82" display_value="R" />
<EnumValue value="83" display_value="S" />
<EnumValue value="84" display_value="T" />
<EnumValue value="85" display_value="U" />
<EnumValue value="86" display_value="V" />
<EnumValue value="87" display_value="W" />
<EnumValue value="88" display_value="X" />
<EnumValue value="89" display_value="Y" />
<EnumValue value="90" display_value="Z" />
</UserPref>

<UserPref name="o" display_name="Rotate" default_value="72" datatype="enum">
<EnumValue value="32" display_value="&lt;SPC&gt;" />
<EnumValue value="48" display_value="0" />
<EnumValue value="49" display_value="1" />
<EnumValue value="50" display_value="2" />
<EnumValue value="51" display_value="3" />
<EnumValue value="52" display_value="4" />
<EnumValue value="53" display_value="5" />
<EnumValue value="54" display_value="6" />
<EnumValue value="55" display_value="7" />
<EnumValue value="56" display_value="8" />
<EnumValue value="57" display_value="9" />
<EnumValue value="64" display_value="@" />
<EnumValue value="65" display_value="A" />
<EnumValue value="66" display_value="B" />
<EnumValue value="67" display_value="C" />
<EnumValue value="68" display_value="D" />
<EnumValue value="69" display_value="E" />
<EnumValue value="70" display_value="F" />
<EnumValue value="71" display_value="G" />
<EnumValue value="72" display_value="H" />
<EnumValue value="73" display_value="I" />
<EnumValue value="74" display_value="J" />
<EnumValue value="75" display_value="K" />
<EnumValue value="76" display_value="L" />
<EnumValue value="77" display_value="M" />
<EnumValue value="78" display_value="N" />
<EnumValue value="79" display_value="O" />
<EnumValue value="80" display_value="P" />
<EnumValue value="81" display_value="Q" />
<EnumValue value="82" display_value="R" />
<EnumValue value="83" display_value="S" />
<EnumValue value="84" display_value="T" />
<EnumValue value="85" display_value="U" />
<EnumValue value="86" display_value="V" />
<EnumValue value="87" display_value="W" />
<EnumValue value="88" display_value="X" />
<EnumValue value="89" display_value="Y" />
<EnumValue value="90" display_value="Z" />
</UserPref>

<UserPref name="d" display_name="Drop" default_value="78" datatype="enum">
<EnumValue value="32" display_value="&lt;SPC&gt;" />
<EnumValue value="48" display_value="0" />
<EnumValue value="49" display_value="1" />
<EnumValue value="50" display_value="2" />
<EnumValue value="51" display_value="3" />
<EnumValue value="52" display_value="4" />
<EnumValue value="53" display_value="5" />
<EnumValue value="54" display_value="6" />
<EnumValue value="55" display_value="7" />
<EnumValue value="56" display_value="8" />
<EnumValue value="57" display_value="9" />
<EnumValue value="64" display_value="@" />
<EnumValue value="65" display_value="A" />
<EnumValue value="66" display_value="B" />
<EnumValue value="67" display_value="C" />
<EnumValue value="68" display_value="D" />
<EnumValue value="69" display_value="E" />
<EnumValue value="70" display_value="F" />
<EnumValue value="71" display_value="G" />
<EnumValue value="72" display_value="H" />
<EnumValue value="73" display_value="I" />
<EnumValue value="74" display_value="J" />
<EnumValue value="75" display_value="K" />
<EnumValue value="76" display_value="L" />
<EnumValue value="77" display_value="M" />
<EnumValue value="78" display_value="N" />
<EnumValue value="79" display_value="O" />
<EnumValue value="80" display_value="P" />
<EnumValue value="81" display_value="Q" />
<EnumValue value="82" display_value="R" />
<EnumValue value="83" display_value="S" />
<EnumValue value="84" display_value="T" />
<EnumValue value="85" display_value="U" />
<EnumValue value="86" display_value="V" />
<EnumValue value="87" display_value="W" />
<EnumValue value="88" display_value="X" />
<EnumValue value="89" display_value="Y" />
<EnumValue value="90" display_value="Z" />
</UserPref>
<Content type="html"><![CDATA[

<style>
body{width:100%;height:100%;font-size:9px;}
input{font-size:9px;width:4em;text-align:right;}
.s{text-align:center;}
.o{font-size:48pt;font-weight:bold;text-align:center;color:#ff0000;position:absolute;top:240px;left:24px;}
.f{position:absolute;top:140px;left:4px;width:64px;text-align:right;}
.sc{width:160px;height:352px;position:absolute;top:64px;left:80px;}
.nx{width:64px;height:64px;position:absolute;top:64px;left:4px;}
.hs{position:absolute;top:69px;left:64px;font-size:18px;color:#0000ff;background-color:#ffffff;border:2px solid #0000ff;}
.th{text-align:right;}
.th{font-weight:bold;text-align:right;}
</style>
<script language="JavaScript">
var up='http://www.airspace-v.com/ggadgets/';
var starting=false;
var cntColumns=10;
var cntRows=22;
var BD=new Array("0000011001100000","0000222200000000","0000333030000000","0000044400040000","0000550005500000","0000006606600000","0000070077700000");
function _gel(i){return document.getElementById(i);}
function ce(t){return document.createElement(t);}
function ac(p,c){p.appendChild(c);}
Array.prototype.forEach=function(other,pt,func){
 for(var y=0;y<this.length&&y+pt.y<other.length;y++)
  for(var x=0;x<this[y].length && x+pt.x<other[y].length;x++){
   var r=func(this[y][x],{x:pt.x+x,y:pt.y+y});if(r)return r;
  }
}
Array.prototype.init=function(r,c,func){
 if(this.length>r)this.splice(r,this.length);
 for(var y=0;y<r;y++){this[y]=new Array(c);for(var x=0;x<c;x++)if(func)func(this,{x:x,y:y});else this[y][x]=0;}
 return this;
}
function Block(r,c,init){r=r||4;c=c||4;this.m=new Array(r);this.m.init(r||4,c||4,init);};
Block.prototype={
 init:function(str){this.m.init(4,4,function(a,p){a[p.y][p.x]=parseInt(str.charAt(p.y*4+p.x))});},
 rotate:function(){var n=this.m;this.m=[[n[3][0],n[2][0],n[1][0],n[0][0]],[n[3][1],n[2][1],n[1][1],n[0][1]],[n[3][2],n[2][2],n[1][2],n[0][2]],[n[3][3],n[2][3],n[1][3],n[0][3]]];return this;},
 move:function(arr,pt){this.m.forEach(arr.m,pt,function(v,p){if(arr.m[p.y][p.x]==0)arr.m[p.y][p.x]=v;});},
 draw:function(tbl,off,func){this.m.forEach(tbl.m,off,function(v,p){var clr=func?func(v):v;if(null!=clr)tbl.m[p.y][p.x].src=up+clr+'.gif';});},
 clone:function(){var blk=new Block();this.move(blk,{x:0,y:0});return blk;}
};
var tI=null;var tD=500;var SB;
var NE=new Block();var CE=new Block();var LE=new Block();
var CP={x:3,y:0};var LP={x:0,y:0};
var to=0;var score=0;
var NT=null;var ST=null;
var p;var kl;var kr;var ko;var kd;
var hs=[];
var hsn;
var o;

////////////////////////////////////////////////////////////////////////
var hs = [];
var name = '';
var i2a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
var a2i = [];
for (c = 0; c <= 9;c++) a2i['0'.charCodeAt(0) + c] = c;
for (c = 0; c <= 26;c++) {a2i['A'.charCodeAt(0) + c] = c + 10; a2i['a'.charCodeAt(0) + c] = c + 36;}
a2i['.'.charCodeAt(0)] = 62;
a2i['-'.charCodeAt(0)] = 63;

function HS(pn,ps){this.n=pn;this.s=ps;}
function getHighScores(){
  var str = p.getString("HighScores");
  var j = 0;
  while (j < str.length) {
    var s = 0;
    var t;
    for (var i = 0; i < 4; i++) s += a2i[str.charCodeAt(j + i)] << (3 * i);
    var n = str.substr(j + i + 1, t = a2i[str.charCodeAt(j + i)]);
    hs.push(new HS(n, s));
    j += 5 + t;
  }
}
function putHighScores(){
  var str = '';
  for (var i = 0; i < hs.length; i++) {
    var s = hs[i].s;
    for (var j = 0; j < 4; j++) {
      str += i2a.charAt(s & 0x3f);
      s = Math.floor(s / 64);
    }
    str += i2a.charAt(hs[i].n.length & 0x3f);
    str += hs[i].n.substring(0, 32);
  }
  p.set('HighScores', str);
}
function insertHighScore(n, s) {
  n = n.substring(0,31);
  s = parseInt(s);
  if (isNaN(s)) return;
  for (var i = 0; i < hs.length && i < 10; i++)if (s - hs[i].s > 0) break;
  if (i < 10) hs.splice(i, 0, new HS(n, s));
  if (hs.length > 10) hs.pop();
  putHighScores();
  showHighScores();
}
function showHighScores() {
  while (hsn.childNodes.length > 1) hsn.removeChild(hsn.childNodes[1]);
  var r = ce('tr');
  var h = ce('th');
  ac(h,document.createTextNode(''));
  var d = ce('td');
  ac(d,document.createTextNode(''));
  ac(r,h);
  ac(r,d);
  for (var i = 0; i < hs.length; i++) {
    var l = r.cloneNode(true);
    l.firstChild.firstChild.data = hs[i].n;
    l.childNodes[1].firstChild.data = hs[i].s;
    ac(hsn,l);
  }
  hsn.style.display = '';
}

function addEntry() {
  if (score <= 0) return false;
  if (hs.length) if (score < hs[0].s) return;
  var n = window.prompt('Name for Top Ten Entry:', name);
  if (!n) return false;
  if (!n.length) return false;
  insertHighScore(n, score);
  return false;
}
////////////////////////////////////////////////////////////////////////
function GT(){starting=false;clearTimeout(tI);if(DC())tI=setTimeout("GT()",tD)}
function Start(){
 starting=true;
 var x,y;
 kl=p.getString('l');
 kr=p.getString('r');
 ko=p.getString('o');
 kd=p.getString('d');
 o.style.display='none';
 hsn.style.display='none';
 NT=new Block(4,4,function(a,p){a[p.y][p.x]=_gel("nxt"+p.y+"_"+p.x);});
 ST=new Block(cntRows,cntColumns,function(a,p){a[p.y][p.x]=_gel("scr"+p.y+"_"+p.x);});
 SB=new Block(cntRows,cntColumns);
 SB.draw(ST,{x:0,y:0});
 _gel('line').value=to=0
 _gel('pts').value =score=0
 next();
 LP=CP={x:3,y:0};
 LE=CE=NE;
 screen();
 next();
 _gel('line').focus();
 tI=setTimeout("GT()",1000)
}
function next(){
 var i=Math.floor(Math.random() * BD.length);
 NE=new Block();
 NE.init(BD[i]);
 for(var j=Math.floor(Math.random()*4);j > 0;j--)NE.rotate();
 NE.draw(NT,{x:0,y:0});
}
function screen(){
 LE.draw(ST,LP,function(clr){return clr==0?null:0;});
 CE.draw(ST,CP,function(clr){return clr==0?null:clr;});
 LP={x:CP.x,y:CP.y};
 LE=CE;
}
function HC(blk,pos){
 for(var y=0;y<blk.m.length;y++){
  for(var x=0;x<blk.m[y].length;x++){
   if(blk.m[y][x]==0)continue;
   var x2=pos.x + x;
   var y2=pos.y + y;
   if(y2<0||y2>=SB.m.length||x2<0||x2>=SB.m[y2].length||SB.m[y2][x2]!=0)return true;
  }
 }
 CP=pos;
 CE=blk;
 screen();
 return false;
}
function DC(){
 if(!HC(CE,{ x:CP.x,y:CP.y + 1 }))return true;
 CE.move(SB,CP);
 for(i=cntRows-1;i >=0;i--){
  for(j=0;j<cntColumns;j++)if(SB.m[i][j]<=0)break;
  if(j==cntColumns)SB.m.splice(i,1);
 }
 var remLines=cntRows-SB.m.length;
 if(remLines>0)score+=Math.pow(5,remLines);
 to+=remLines;
 _gel('line').value=to
 _gel('pts').value =score
 while(SB.m.length<cntRows)SB.m.unshift([0,0,0,0,0,0,0,0,0,0]);
 var level=Math.min(to/10,6);
 tD=500*Math.exp(-level/8);
 SB.draw(ST,{x:0,y:0});
 LP=CP={x:3,y:0};
 CE=NE;
 screen()
 next();
 if(!HC(CE,CP))return true;
 o.style.display='';
  addEntry();
 hsn.style.display='';
 return false;
}
function kD(DnEvents){
 if (starting) return false;
 if(NT==null)return;
 var k=(document.all)?window.event.keyCode:DnEvents.which;
 if(k==kl)HC(CE,{x:CP.x-1,y:CP.y});
 else if(k==kr)HC(CE,{x:CP.x+1,y:CP.y});
 else if(k==ko)HC(CE.clone().rotate(),CP);
 else if(k==kd)DC();
}
function dT(p,r,c){
 var s=_gel(p);
 var m=document.createElement('img');
 m.style.position='absolute';
 m.style.width='16px';
 m.style.height='16px';
 m.src=up+'0.gif';
 for(var i=0;i<r;i++){
  for(var j=0;j<c;j++){
   var n=m.cloneNode(true);n.style.top=i*16+'px';n.style.left=j*16+'px';n.id=p+i+'_'+j;ac(s,n);
  }
 }
}
window.onload=function(){
 p=new _IG_Prefs();
 var s=[];
 for (var i=0;i<8;i++){s.push(ce('img'));s[s.length-1].src=up+i+'.gif';}
 hsn=_gel('hs');o=_gel('o');dT("nxt",4,4);dT("scr",cntRows,cntColumns);_gel('start').onclick=Start;document.onkeydown=kD;
 getHighScores();
 showHighScores();
};
</script>
</head><body bgcolor="white" text="#000000" vlink="#ff0000">
<script type="text/javascript"><!--
google_ad_client = "pub-6820084268487574";
google_alternate_ad_url = "http://www.airspace-v.com/ggadgets/jawbreaker-ad-234x60.htm";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text_image";
//2007-10-03: ggadget-tetriculis
google_ad_channel = "0992646883";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "3165CE";
google_color_text = "000000";
google_color_url = "3165CE";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<div id=nxt class=nx></div>
<div id=scr class=sc></div>
<div class=f><form name='frm'>
  Lines:<br /><input id=line readonly><br />
  Score:<br /><input id=pts readonly><br />
  <input id=start class=s type=button value="Start">
</form></div>
<table class=hs><tbody id=hs><tr><th colspan=2><u>Your Top Ten</u></td></th></tbody></table>
<div id=o class="o">Game<br />Over!</div>
]]></Content></Module>
