From f936253e58d3f1e56c745b0391dd8607f79e1fb8 Mon Sep 17 00:00:00 2001 From: Noah Moroze Date: Sat, 17 May 2014 12:16:56 -0400 Subject: [PATCH 1/2] yes --- index.html | 2 ++ input.js | 2 ++ keypress.min.js | 25 +++++++++++++++++++++++++ main.js | 2 ++ 4 files changed, 31 insertions(+) create mode 100644 input.js create mode 100644 keypress.min.js diff --git a/index.html b/index.html index 9a3a56b..c0b01d6 100644 --- a/index.html +++ b/index.html @@ -17,5 +17,7 @@ + + \ No newline at end of file diff --git a/input.js b/input.js new file mode 100644 index 0000000..fc1a54c --- /dev/null +++ b/input.js @@ -0,0 +1,2 @@ +keypress.simple_combo("left", clock.rotate(-1)); +keypress.simple_combo("right", clock.rotate(1)); \ No newline at end of file diff --git a/keypress.min.js b/keypress.min.js new file mode 100644 index 0000000..e004f6a --- /dev/null +++ b/keypress.min.js @@ -0,0 +1,25 @@ +/* + Keypress version 1.0.8 (c) 2013 David Mauro. + Licensed under the Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 +*/ +(function(){var w,x,j,R,S,T,U,y,z,A,V,H,I,B,m,W,X,Y,Z,J,$,aa,ba,ca,da,K,ea,r,s,g,L,t,fa,M,u,N,C,v,O,D,h,P,E,p,F,Q,G,ga,i=[].indexOf||function(a){for(var c=0,b=this.length;ce;b=0<=e?++d:--d)if(a[b]!==c[b])return!1;return!0};ba=function(a,c){var b,d,e;d=0;for(e=a.length;di.call(c,b))return!1;return!0};ca=function(a,c){var b,d,e,f;e=d=0;for(f=a.length;e=d)d=b;else return!1;return!0};v=function(a, +c){if((c||keypress.suppress_event_defaults)&&!keypress.force_event_defaults)if(a.preventDefault?a.preventDefault():a.returnValue=!1,a.stopPropagation)return a.stopPropagation()};T=function(a){if(a.prevent_repeat)return!1;if("function"===typeof a.on_keydown)return!0};L=function(a){var c,b,d,e;e=a.keys;b=0;for(d=e.length;bi.call(a,"cmd")?!1:!0};X=function(a){var c,b;c=[];b=B(g,function(b){return b!==a});b.push(a);fa(b,function(a){if(y(a.keys))return c.push(a)});W(b,function(a){if(!(0<=i.call(c,a))&&!a.is_solitary&& +y(a.keys))return c.push(a)});return c};Z=function(a){var c,b,d,e;b=[];d=0;for(e=h.length;dk;e=0<=k?++g:--g)if((c=j[e])&&c.is_exclusive&&a.is_exclusive){c=c.keys;if(!q){h=0;for(l=c.length;hi.call(a.keys,b)){q=!1;break}}if(f&&!q){o=a.keys;h=0;for(l=o.length;hi.call(c,b)){f=!0;break}}q&&(d?E(j.splice(e,1)):(E(j.splice(e,1,a)),d=!0),f=!1)}}f&&j.unshift(a);return q||f};P=function(a){var c,b,d,e;b=d=0;for(e=j.length;0<=e?de;b=0<=e?++d:--d)if(c=j[b],c===a){E(j.splice(b,1));break}};E=function(a){if(a)return a.count=null,a.keyup_fired=null};R=function(a,c){var b,d,e,f;p.push(a);d=Y();if(d.length){e=0;for(f=d.length;e=l;c=1<=l?++g:--g)if(e=p.slice(-c),a.is_sequence){if(0>i.call(a.keys,"shift")&&(e=B(e,function(a){return"shift"!==a}),!e.length))continue;c=n=0;for(k=e.length;0<=k?nk;c=0<=k?++n:--n)if(a.keys[c]===e[c])b=!0;else{b=!1;break}b&&d.push(a)}}return d};J=function(a){var c,b,d,e,f,g,j,m,l,k,o;g=0;for(l=h.length;g=k;b=1<= +k?++j:--j)if(f=B(p,function(a){return 0<=i.call(c.keys,"shift")?!0:"shift"!==a}).slice(-b),c.keys.length===f.length){b=m=0;for(o=f.length;0<=o?mo;b=0<=o?++m:--m)if(e=f[b],!(0>i.call(c.keys,"shift")&&"shift"===e)&&!("shift"===a&&0>i.call(c.keys,"shift")))if(c.keys[b]===e)d=!0;else{d=!1;break}}if(d)return c}return!1};I=function(a,c){var b;if(!c.shiftKey)return!1;b=s[a];return null!=b?b:!1};$=function(a,c,b){if(0>i.call(a.keys,c))return!1;v(b,a&&a.prevent_default);if(0<=i.call(g,c)&&!T(a))return!1; +c=S(a,c);a.keyup_fired=!1;a.is_counting&&"function"===typeof a.on_keydown&&(a.count+=1);if(c)return m("keydown",a,b)};da=function(a,c){var b,d,e,f;(d=I(a,c))&&(a=d);R(a,c);(d=J(a))&&m("keydown",d,c);for(b in u)d=u[b],c[d]&&(b===a||0<=i.call(g,b)||g.push(b));for(b in u)if(d=u[b],b!==a&&0<=i.call(g,b)&&!c[d]){d=e=0;for(f=g.length;0<=f?ef;d=0<=f?++e:--e)g[d]===b&&g.splice(d,1)}d=X(a);e=0;for(f=d.length;e +i.call(g,a)&&g.push(a)};aa=function(a,c,b){var d,e;e=L(a);if(!a.keyup_fired&&(d=g.slice(),d.push(b),!a.is_solitary||A(d,a.keys)))m("keyup",a,c),a.is_counting&&("function"===typeof a.on_keyup&&"function"!==typeof a.on_keydown)&&(a.count+=1);e||(m("release",a,c),P(a))};K=function(a,c){var b,d,e,f,h,n;d=a;(e=I(a,c))&&(a=e);e=s[d];c.shiftKey?e&&0<=i.call(g,e)||(a=d):d&&0<=i.call(g,d)||(a=e);(f=J(a))&&m("keyup",f,c);if(0>i.call(g,a))return!1;f=h=0;for(n=g.length;0<=n?hn;f=0<=n?++h:--h)if((b=g[f])=== +a||b===e||b===d){g.splice(f,1);break}d=j.length;e=[];f=0;for(h=j.length;fd;c=0<=d?++b:--b)if(a===h[c]){h.splice(c,1);break}else e.push(void 0);return e};ga=function(a){var c, +b,d,e,f;a.keys.length||t("You're trying to bind a combo with no keys.");b=e=0;for(f=a.keys.length;0<=f?ef;b=0<=f?++e:--e)d=a.keys[b],(c=ea[d])&&(d=a.keys[b]=c),"meta"===d&&a.keys.splice(b,1,M),"cmd"===d&&t('Warning: use the "meta" key rather than "cmd" for Windows compatibility');f=a.keys;c=0;for(e=f.length;ci.call(G,d))return t('Do not recognize the key "'+d+'"'),!1;if(0<=i.call(a.keys,"meta")||0<=i.call(a.keys,"cmd")){c=a.keys.slice();e=0;for(f=N.length;e",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&", +8:"*",9:"(","0":")"};r={"0":"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"escape",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x", +89:"y",90:"z",91:"cmd",92:"cmd",93:"cmd",96:"num_0",97:"num_1",98:"num_2",99:"num_3",100:"num_4",101:"num_5",102:"num_6",103:"num_7",104:"num_8",105:"num_9",106:"num_multiply",107:"num_add",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",124:"print",144:"num",145:"scroll",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",57392:"ctrl",63289:"num"};for(x in r)w=r[x],G.push(w);for(x in s)w=s[x],G.push(w);-1!==navigator.userAgent.indexOf("Mac OS X")&& +(M="cmd");-1!==navigator.userAgent.indexOf("Opera")&&(r["17"]="cmd");O=function(a){return(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?a():setTimeout(function(){return O(a)},9)};O(function(){var a;a=function(a,b,d){if(a.addEventListener)return a.addEventListener(b,d);if(a.attachEvent)return a.attachEvent("on"+b,d)};a(document.body,"keydown",function(a){a=a||window.event;D(a,!0);return U(a)});a(document.body,"keyup",function(a){a=a||window.event;return D(a, +!1)});return a(window,"blur",function(){var a,b,d;b=0;for(d=g.length;b Date: Sat, 17 May 2014 12:39:49 -0400 Subject: [PATCH 2/2] vertical checking working --- checking.js | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 checking.js diff --git a/checking.js b/checking.js new file mode 100644 index 0000000..9832bf1 --- /dev/null +++ b/checking.js @@ -0,0 +1,88 @@ +function getIndex(list,index) +{ + if(index>-1) + return index%list.length; + else + return list.length+index; +} +function scoreCheckHorizontal(clock,side,index) { + clockSides = clock.blocks; + clockSides[0]; + if(clockSides[getIndex(clockSides,side)][index] && clockSides[getIndex(clockSides,side-1)][index] && clockSides[getIndex(clockSides,side-2)][index]) { + if(clockSides[getIndex(clockSides,side)][index].color == clockSides[getIndex(clockSides,side-1)][index].color&& clockSides[getIndex(clockSides,side-1)][index].color === clockSides[getIndex(clockSides,side-2)][index].color) { + return -2; + } + } + + if(clockSides[getIndex(clockSides,side)][index] && clockSides[getIndex(clockSides,side+1)][index] && clockSides[getIndex(clockSides,side-1)][index]) { + if(clockSides[getIndex(clockSides,side)][index].color == clockSides[getIndex(clockSides,side+1)][index].color&& clockSides[getIndex(clockSides,side+1)][index].color === clockSides[getIndex(clockSides,side-1)][index].color) { + return -1; + } + } + if(clockSides[getIndex(clockSides,side)][index] && clockSides[getIndex(clockSides,side+1)][index] && clockSides[getIndex(clockSides,side+2)][index]) { + if(clockSides[getIndex(clockSides,side)][index].color == clockSides[getIndex(clockSides,side+1)][index].color&& clockSides[getIndex(clockSides,side+1)][index].color === clockSides[getIndex(clockSides,side+2)][index].color) { + return 0; + } + } + return "false"; +} + +function scoreCheckVertical(clock,side,index) { + curSide = clock.blocks[side]; + if(curSide[index] && curSide[index-2] && curSide[index-1]) { + if(curSide[index].color == curSide[index-2].color && curSide[index-2].color ==curSide[index-1].color) { + return -2; + } + } + + if(curSide[index] && curSide[index+1] && curSide[index-1]) { + if(curSide[index].color == curSide[index+1].color && curSide[index+1].color == curSide[index-1].color) { + return -1; + } + } + + if(curSide[index] && curSide[index+2] && curSide[index+1]) { + if(curSide[index].color == curSide[index+2].color&& curSide[index+2].color ==curSide[index+1].color) { + return 0; + } + } + return "false"; +} +function consolidateBlocks(clock,side,index) { + horizontal = scoreCheckHorizontal(clock,side,index); + vertical = scoreCheckVertical(clock,side,index); + deleted = []; + if(horizontal != "false") { + deleted.push([side,index,horizontal]); + } + else { + deleted.push([]); + } + if(vertical != "false") { + deleted.push([side,index,vertical]); + } + else { + deleted.push([]); + } + eraseBlocks(clock,deleted); +} +function eraseBlocks(clock,deleted) { + if(deleted[0].length>0){ + side = deleted[0][0]; + index = deleted[0][1]; + horizontal = deleted[0][2]; + for(var i=0;i<3;i++) { + clock.blocks[getIndex(clock.sides,side+horizontal+i)].splice(index,1); + } + for(var i=0;i<3;i++) { + consolidateBlocks(clock,side+horizontal+i,index); + } + } + if(deleted[1].length>0){ + side = deleted[1][0]; + index = deleted[1][1]; + vertical = deleted[1][2]; + clock.blocks[side].splice(index+vertical,3); + consolidateBlocks(clock,side,index+vertical); + } +}