From 20e9f67d00ad5082432d0535495f71af215590fd Mon Sep 17 00:00:00 2001 From: farteryhr Date: Fri, 17 Jul 2015 16:50:18 +0800 Subject: [PATCH] dig race added, a broken replay added. ready for adding settings into replay. --- compress.js | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 9 ++- preview.js | 3 +- ranking.js | 6 +- stack.js | 8 ++- tetris.js | 133 ++++++++++++++++++++++++++++---------- 6 files changed, 302 insertions(+), 40 deletions(-) create mode 100644 compress.js diff --git a/compress.js b/compress.js new file mode 100644 index 0000000..70ac6f1 --- /dev/null +++ b/compress.js @@ -0,0 +1,183 @@ +function Compress(strNormalString) +{ + var strCompressedString = ""; + var strBase52 = ""; + + var ht = new HashTable; + for(i = 0; i < 128; i++) { + var e = new HashTableElement; + e.key = i; + e.code = i; + ht.Insert(e); + } + + var used = 128; + var intLeftOver = 0; + var intOutputCode = 0; + var pcode = 0; + var ccode = 0; + var k = 0; + + for(var i=0; i= 16) { + strCompressedString += String.fromCharCode( intOutputCode >> ( intLeftOver - 16 ) ); + intOutputCode &= (Math.pow(2,(intLeftOver - 16)) - 1); + intLeftOver -= 16; + } + if(used < 4096) { + used ++; + var e = new HashTableElement; + e.key = k; + e.code = used - 1; + ht.Insert(e); + } + } + } + + if(pcode != 0) { + intLeftOver += 12; + intOutputCode <<= 12; + intOutputCode |= pcode; + } + + if(intLeftOver >= 16) { + strCompressedString += String.fromCharCode( intOutputCode >> ( intLeftOver - 16 ) ); + intOutputCode &= (Math.pow(2,(intLeftOver - 16)) - 1); + intLeftOver -= 16; + } + + if( intLeftOver > 0) { + intOutputCode <<= (16 - intLeftOver); + strCompressedString += String.fromCharCode( intOutputCode ); + } + + //return strCompressedString; + + for(var i=0;i=65&&num<65+26) num-=65; + else if(num>=97&&ch0<97+26) num-=(97-26); + else return null; + return num; + } + + if(strBase52.length % 3 != 0) + return null; + + for(var i=0;i= 12) { + ccode = intOutputCode >> (intLeftOver - 12); + if( typeof( key = ht[ccode] ) != "undefined" ) { + strNormalString += key; + if(used > 128) { + ht[ht.length] = ht[pcode] + key.substr(0, 1); + } + pcode = ccode; + } else { + key = ht[pcode] + ht[pcode].substr(0, 1); + strNormalString += key; + ht[ht.length] = ht[pcode] + key.substr(0, 1); + pcode = ht.length - 1; + }used ++; + intLeftOver -= 12; + intOutputCode &= (Math.pow(2,intLeftOver) - 1); + } else { + break; + } + } + } + return strNormalString; +} + +function HashTableElement() +{ + this.key = null; + this.code = null; +} + +function HashTable() +{ + this.ht = new Array(4099); + + this.Search = function(keyword) { + var arr = this.ht[keyword]; + if(typeof(arr) != "undefined") { + for(i = 0; i < arr.length; i ++) { + if(arr[i].key == keyword) return arr[i].code; + } + } + return null; + } + this.Insert = function(e) { + var arr = this.ht[e.key]; + if(typeof(arr) == "undefined") { + arr = new Array(); + arr[0] = e; + this.ht[e.key] = arr; + } else { + arr[arr.length] = e; + } + } +} diff --git a/index.html b/index.html index 4e2931f..6324f0a 100755 --- a/index.html +++ b/index.html @@ -62,12 +62,15 @@

Tetr.js - Dig v0.31

  • Marathon 马拉松
  • Dig! 挖掘机
  • +
  • Dig Race 挖掘练习
  • Controls 调整按键
  • Settings 调整设定
  • Dig - 500+
  • Dig - 1000+
  • Dig - 1500+
  • -
  • *MONSTER*
  • +
  • *DANGER*
  • +
  • Replay(α) 回放(测试)
  • + @@ -100,7 +103,7 @@

    Controls 调整按键