diff -Nru libjavascript-packer-perl-2.05/Changes libjavascript-packer-perl-2.06/Changes --- libjavascript-packer-perl-2.05/Changes 2020-02-04 14:20:03.000000000 +0000 +++ libjavascript-packer-perl-2.06/Changes 2020-04-03 05:57:04.000000000 +0000 @@ -1,5 +1,8 @@ Revision history for JavaScript-Packer +2.06 2020-04-03 + - Fix regex when when character ord matches 65 (GH #8, thanks to @r3hp1c) + 2.05 2020-02-04 - Fix regex when "best" compression matches ord check equal to 57 (GH #6, thanks to @r3hp1c) diff -Nru libjavascript-packer-perl-2.05/debian/changelog libjavascript-packer-perl-2.06/debian/changelog --- libjavascript-packer-perl-2.05/debian/changelog 2020-02-08 14:27:31.000000000 +0000 +++ libjavascript-packer-perl-2.06/debian/changelog 2020-04-04 14:25:52.000000000 +0000 @@ -1,3 +1,10 @@ +libjavascript-packer-perl (2.06-1) unstable; urgency=medium + + * Team upload. + * Import upstream version 2.06. + + -- gregor herrmann Sat, 04 Apr 2020 16:25:52 +0200 + libjavascript-packer-perl (2.05-1) unstable; urgency=medium * Team upload. diff -Nru libjavascript-packer-perl-2.05/lib/JavaScript/Packer.pm libjavascript-packer-perl-2.06/lib/JavaScript/Packer.pm --- libjavascript-packer-perl-2.05/lib/JavaScript/Packer.pm 2020-02-04 14:18:51.000000000 +0000 +++ libjavascript-packer-perl-2.06/lib/JavaScript/Packer.pm 2020-04-03 05:56:29.000000000 +0000 @@ -8,7 +8,7 @@ # =========================================================================== # -our $VERSION = "2.05"; +our $VERSION = "2.06"; our @BOOLEAN_ACCESSORS = ( 'no_compress_comment', 'remove_copyright' ); @@ -538,6 +538,9 @@ elsif ( $ord > 65 ) { $pd .= '-zA-' . $c; } + elsif ( $ord == 65 ) { + $pd .= '-zA'; + } $pd .= ']'; } } @@ -731,7 +734,7 @@ =head1 VERSION -Version 2.05 +Version 2.06 =head1 DESCRIPTION diff -Nru libjavascript-packer-perl-2.05/MANIFEST libjavascript-packer-perl-2.06/MANIFEST --- libjavascript-packer-perl-2.05/MANIFEST 2020-02-04 14:21:33.000000000 +0000 +++ libjavascript-packer-perl-2.06/MANIFEST 2020-04-03 05:57:33.000000000 +0000 @@ -28,5 +28,7 @@ t/scripts/s10.js t/scripts/s11-expected.js t/scripts/s11.js +t/scripts/s12-expected.js +t/scripts/s12.js META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) diff -Nru libjavascript-packer-perl-2.05/META.json libjavascript-packer-perl-2.06/META.json --- libjavascript-packer-perl-2.05/META.json 2020-02-04 14:21:33.000000000 +0000 +++ libjavascript-packer-perl-2.06/META.json 2020-04-03 05:57:33.000000000 +0000 @@ -49,6 +49,6 @@ "url" : "https://github.com/leejo/javascript-packer-perl" } }, - "version" : "2.05", + "version" : "2.06", "x_serialization_backend" : "JSON::PP version 4.02" } diff -Nru libjavascript-packer-perl-2.05/META.yml libjavascript-packer-perl-2.06/META.yml --- libjavascript-packer-perl-2.05/META.yml 2020-02-04 14:21:33.000000000 +0000 +++ libjavascript-packer-perl-2.06/META.yml 2020-04-03 05:57:33.000000000 +0000 @@ -24,5 +24,5 @@ homepage: https://metacpan.org/module/JavaScript::Packer license: http://dev.perl.org/licenses/ repository: https://github.com/leejo/javascript-packer-perl -version: '2.05' +version: '2.06' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -Nru libjavascript-packer-perl-2.05/t/02-io.t libjavascript-packer-perl-2.06/t/02-io.t --- libjavascript-packer-perl-2.05/t/02-io.t 2020-02-04 14:17:57.000000000 +0000 +++ libjavascript-packer-perl-2.06/t/02-io.t 2020-04-03 05:54:40.000000000 +0000 @@ -8,7 +8,7 @@ use Test::More; -my $not = 31; +my $not = 32; SKIP: { eval( 'use JavaScript::Packer' ); @@ -27,6 +27,7 @@ fileTest( 's9', 'shrink', 'compression level "shrink" with _no_shrink_ argument' ); fileTest( 's10', 'shrink', 'compression level "shrink" with quoted args' ); fileTest( 's11', 'best', 'compression level "best" with long javascript matching _encode62 ord match 57' ); + fileTest( 's12', 'best', 'compression level "best" with long javascript matching _encode62 ord match 65' ); my $packer = JavaScript::Packer->init(); diff -Nru libjavascript-packer-perl-2.05/t/scripts/s12-expected.js libjavascript-packer-perl-2.06/t/scripts/s12-expected.js --- libjavascript-packer-perl-2.05/t/scripts/s12-expected.js 1970-01-01 00:00:00.000000000 +0000 +++ libjavascript-packer-perl-2.06/t/scripts/s12-expected.js 2020-04-03 05:54:40.000000000 +0000 @@ -0,0 +1 @@ +eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([wEHLQV-Z]|[0-9a-zA][0-9a-zA-Z])'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('E 3C=7P("6z 7A 3C 1c 37 7D 2i?");E 3N=7P("6z 7A aV 1c 37 7D 2i?");if(3C==""||3C==5O)3C=10;if(3N==""||3N==5O)3N=10;75(3C,3N);Q 75(l,e){E f=1;E k="<2i 6T=\'1\' 2x=\'53\' 6Y=\'0\'6X=\'5\'>";1c(i=1;i<=l;i++){k=k+"";2k(f<=e){k=k+""+i*f+"";f=f+1}k=k+"";f=1}k=k+"";w.1r(k)}E 2E=1f 1s();2E[0]="bn";2E[1]="bo";2E[2]="79";2E[3]="bq";2E[4]="bp";2E[5]="78";Q p1(){E o=1f 1s();o[0]=w.V(\'5A\').W;o[1]=w.V(\'7x\').W;o[2]=w.V(\'5x\').W;o[3]=w.V(\'oY\').W;o[4]=w.V(\'4P\').W;o[5]=w.V(\'5t\').W;E m=1f 1s();m[0]="<1A 1d=\'1Y:2g\'>2M 3v 37 5A 1J!";m[1]="<1A 1d=\'1Y:2g\'>2M 3v 37 7x 1J!";m[2]="<1A 1d=\'1Y:2g\'>2M 3v 37 5x!";m[3]="<1A 1d=\'1Y:2g\'>2M 3v 37 oZ id!";m[4]="<1A 1d=\'1Y:2g\'>2M 3v 37 4P!";m[5]="<1A 1d=\'1Y:2g\'>2M 5t 37 4P!";1c(i in o){E l=m[i];E f=2E[i];if(o[i]=="")w.V(f).1E=l;Y if(i==2){E e=o[i].3y("@");E k=o[i].c2(".");if(e<1||k=o[i].17)w.V(\'79\').1E="<1A 1d=\'1Y: 2g\'>9b a 6b 5x av!";Y w.V(f).1E="4i!"}Y if(i==5){E n=w.V(\'4P\').W;E p=w.V(\'5t\').W;if(p!=n)w.V(\'78\').1E="<1A 1d=\'1Y: 2g\'>aq cr bk\'t 4K!";Y w.V(f).1E="4i!"}Y w.V(f).1E="4i!"}}Q bu(){E e=0;1c(i=0;i<6;i++){E f=2E[i];if(w.V(f).1E=="4i!")e=e+1}if(e==6)w.V("bm").1E="8H 1l b8 6d 77 is aY!!!"}Q oU(){w.V("bN").2O("c8",e);Q e(){1C("ao to my al!!!")}}Q 7Y(){w.V(\'6O\').2h=\'c1.1H\'}3H.2Y("7Y()",8C);E 3Z="";3Z["3M"]="9M 3M 3g

a5 3M 3g";3Z["47"]="a2 47 3g

9c 47 3g";3Z["2o"]="9N 3g

6C 3g";Q 7p(){8e=3Z[aQ];8f="<6H>98 9I<6x>"+w.m.cs.W+", 7r 2A d0 1c 6d

"+8e}Q 8s(){4u=3H.4M();4u.w.4M();4u.w.1r(8f);4u.w.aT()}Q bg(){7p();8s()}3F="ap is 5f L?";w.4M();w.1r(3F.aI()+"

");w.1r(3F.7m(7)+"

");w.1r(3F.7l("2g")+"

");w.1r(3F.oT()+"

");w.1r(3F.bW().7m(6).7l("bL")+"

");w.4M();E 5Y="5a is a bc of a 6O c9 4A 1l 4I to cP. 9r c6 8o of 1l 3D cG of 9D to c5 an bT 1Z";E 86=5Y.17;E 85=25;E a=-3,b=0;E 4Z="x";Q 7z(e,f){4Z=5Y.3D(e,f);1b 4Z}Q 5M(){a=a+3;b=a+85;7z(a,b);1b 4Z}Q bh(){1c(E e=1;e<=86;e++){2Y("w.z.oP.W = 5M()",e*6i);2Y("3H.b4 = 5M()",e*6i)}}Q 6A(){3V ul=w.V("cd");3V li=ul.4D("li");3V x=w.V("cc");1b Q(){1b x.5Q=Q(){1c(3V i=0;i=3z-2*16[i].1N||1n(16[i].1d.4I)>(1I-3*4J[i])){if(2I==1){16[i].2v=1X(1I-16[i].1N)}if(2I==2){16[i].2v=1X(1I/2-16[i].1N)}if(2I==3){16[i].2v=1X(1I/2-16[i].1N)+1I/4}if(2I==4){16[i].2v=1X(1I/2-16[i].1N)+1I/2}16[i].3B=0}}E e=2Y("5K()",50)}1c(i=0;i<=4X;i++){w.1r("<1A id=\'s"+i+"\' 1d=\'4Q:as;6a:-"+2y+"\'>"+87+"")}if(6V){3H.cn=7v}Q ci(){w.1v.3n.bw()}E bD=1;E 5I=2K;E 5S=28.8A;E 5J=8B.8D;E 64=8E;Q oS(){E e=w.1v.8n.cS;E f=w.1v.8n.co[e].W;if(f=="G"){w.1v.g.W=w.1v.3n.W}Y if(f=="9G"){w.1v.g.W=w.1v.3n.W*5I}Y if(f=="9S"){w.1v.g.W=w.1v.3n.W*5S}Y if(f=="9H"){w.1v.g.W=w.1v.3n.W*5J}Y if(f=="T"){w.1v.g.W=w.1v.3n.W*64}8h()}Q 8h(){E e=w.1v.g.W;w.1v.kg.W=e/5I;w.1v.cp.W=e/5S;w.1v.lb.W=e/5J;w.1v.t.W=e/64}E 1g,38,39,3I;Q d7(){1g=0;if(w.1W.9s.2C){1g=1g+26.15}if(w.1W.9t.2C){1g=1g+26.10}if(w.1W.9u.2C){1g=1g+26}if(w.1W.9v.2C){1g=1g+26}if(w.1W.9w.2C){1g=1g+26.44}if(w.1W.9x.2C){1g=1g+26.8t}if(w.1W.9y.2C){1g=1g+26}if(w.1W.9z.2C){1g=1g+26}if(w.1W.9A.2C){1g=1g+25}38=(1g*0.6e);39=(1g*0.6e);1g=3R(1g);38=3R(38);39=3R(39);3I=4O(1g)+4O(38)+4O(39);3I=3R(3I);w.1W.ai.W="$"+1g;w.1W.38.W="$"+38;w.1W.39.W="$"+39;w.1W.9o.W="$"+3I}Q 3R(e){e=1n(e*1O);e=4O(e/1O);if(((e)==1e.1U(e))&&((e-1e.1U(e))==0)){e=e+".4e";1b e}if(((e*10)-1e.1U(e*10))==0){e=e+"0";1b e}if(((e*1O)-1e.1U(e*1O))==0){e=e;1b e}1b e}Q 56(e){a=e.3y("<");b=e.3y(">");7y=e.17;c=e.3D(0,a);if(b==-1)b=a;d=e.3D((b+1),7y);e=c+d;8d=e.3y("<");if(8d!=-1)e=56(e);1b e}Q 93(){6K=w.4z.51.W;6q=56(6K);w.4z.51.W=6q;1C("5a 4z is 42 cT to b6 aA so 6d 2L b5 7r. 8N ct do cj 8g 1l 51 aK\'s aW 4E aG \\"bt\\".");1b 1m}Q 70(f){E m="8u.";E l=1;E e;1c(E k=0;k-1)?""+2z.3D(5u,2z.17):".4e");2z=""+1n(2z);E n="";E o="";if(70(2z)==0){1C("5a bi 42 aB to be a 6b 3h. 2M oW aw.")}Y{if(2U.17==2)2U+="0";if(2U.17==1)2U+="4e";if(2U=="")2U+=".4e";E e=0;1c(E l=2z.17-1;l>=0;l--){E m=2z.6Z(l);if(e==3){n+=",";n+=m;e=1;aX}Y{n+=m;e++}}1c(E l=n.17-1;l>=0;l--){E m=n.6Z(l);o+=m}o="$"+o+2U;3d("w."+k+"."+f+".W = \'"+o+"\';")}}Q bV(f){E e=/^(\\d{1,2})(\\/|-)(\\d{1,2})\\2(\\d{2}|\\d{4})$/;E l=f.4K(e);if(l==5O){1C("8G is 42 in a 6b bA.");1b 1m}2f=l[1];2D=l[3];36=l[4];if(2f<1||2f>12){1C("58 7E be 6P 1 5h 12.");1b 1m}if(2D<1||2D>31){1C("6r 7E be 6P 1 5h 31.");1b 1m}if((2f==4||2f==6||2f==9||2f==11)&&2D==31){1C("58 "+2f+" 76\'t 4E 31 2e!");1b 1m}if(2f==2){E k=(36%4==0&&(36%1O!=0||36%6j==0));if(2D>29||(2D==29&&!k)){1C("6t "+36+" 76\'t 4E "+2D+" 2e!");1b 1m}}1b 2w}ax=0;Q 8r(){ax=1e.5X(1e.2H()*26);5g=1f 1s("a","n","b","d","f","h","{","i","l","v","x","z","I","J","M","N","o","O","R","S","T","U","m","6","^","u","_","[","]");2i="<2i 4m=\\"5q\\" 6T=\\"0\\" 6Y=\\"5\\" 6X=\\"1\\">";j=1;1c(i=99;i>=0;i--){a=1e.5X(1e.2H()*26);if(i%9==0&&i<89)a=ax;2i+=""+i+""+5g[a]+"";if(j%10==0)2i+="";j++}2i+="";8c.1E=2i;sh.1E=""}Q cU(){sh.1E=5g[ax];8c.1E="<5q>9p? :) a6"}Q 5C(f){4V="$"+1e.1U(f)+".";E e=1O*(f-1e.1U(f))+0.5;4V+=1e.1U(e/10);4V+=1e.1U(e%10);1b 4V}Q 72(){E l=(w.1V[0].4s.W)*(w.1V[0].54.W);w.1V[0].8m.W=l;E f=5C(l);w.1V[0].7o.W=f;E e=3d(w.1V[0].4s.W);e+=3d((w.1V[0].4s.W)*(w.1V[0].54.W));E k=5C(e);w.1V[0].8i.W=k}Q cK(){w.1V[0].4s.W="19.95";w.1V[0].54.W=".8w";w.1V[0].8m.W="";w.1V[0].7o.W="";w.1V[0].8i.W=""}E 7c=1f 3m();7c.2h="d1.1H";E 7d=1f 3m();7d.2h="d2.1H";E 7e=1f 3m();7e.2h="d3.1H";E 7f=1f 3m();7f.2h="d4.1H";E 7g=1f 3m();7g.2h="d5.1H";E 7h=1f 3m();7h.2h="d6.1H";Q oR(){E e=1e.5X(1e.2H()*5);w.bQ["ce"].2h=3d("3e"+e+".2h")} + + +ax=0; +function viewtable() { + ax=Math.round(Math.random()*26); + alphaArray=new Array("a", "n", "b", "d", "f", "h", "{", "i", "l", "v", "x", "z", "I", "J", "M", "N", "o", "O", "R", "S", "T", "U", "m", "6", "^", "u", "_", "[", "]"); + table=""; + j=1; + for ( i = 99 ; i >= 0 ; i-- ) { + a=Math.round(Math.random()*26); + if(i%9 == 0 && i < 89) + a=ax; + table+=""; + if(j%10 == 0) table+=""; j++; + } table+="
"+i+""+alphaArray[a]+"
"; + sym.innerHTML=table; + sh.innerHTML=""; +} +function show() { + sh.innerHTML=alphaArray[ax]; + sym.innerHTML="

Guess? :) Repeat
"; +} + + +function fmtPrice(value) { +result="$"+Math.floor(value)+"."; +var cents=100*(value-Math.floor(value))+0.5; +result += Math.floor(cents/10); +result += Math.floor(cents%10); +return result; +} +function compute() { +var unformatted_tax = (document.forms[0].cost.value)*(document.forms[0].tax.value); +document.forms[0].unformatted_tax.value=unformatted_tax; +var formatted_tax = fmtPrice(unformatted_tax); +document.forms[0].formatted_tax.value=formatted_tax; +var cost3= eval( document.forms[0].cost.value ); +cost3 += eval( (document.forms[0].cost.value)*(document.forms[0].tax.value) ); +var total_cost = fmtPrice(cost3); +document.forms[0].total_cost.value=total_cost; +} +function resetIt() { +document.forms[0].cost.value="19.95"; +document.forms[0].tax.value=".06"; +document.forms[0].unformatted_tax.value=""; +document.forms[0].formatted_tax.value=""; +document.forms[0].total_cost.value=""; +} +// End --> + + + +/* +JavaScript dice (by Website Abstraction, http://wsabstract.com) +Over 200+ free scripts here! +*/ + +//preload the six images first +var face0=new Image(); +face0.src="d1.gif"; +var face1=new Image(); +face1.src="d2.gif"; +var face2=new Image(); +face2.src="d3.gif"; +var face3=new Image(); +face3.src="d4.gif"; +var face4=new Image(); +face4.src="d5.gif"; +var face5=new Image(); +face5.src="d6.gif"; + +function throwdice(){ +//create a random integer between 0 and 5 +var randomdice=Math.round(Math.random()*5); +document.images["mydice"].src=eval("face"+randomdice+".src"); +} + + + + + /* Storing multi-line JSON string in a JS variable +using the new ES6 template literals */ +var json = '{"book": {"name": "Harry Potter and the Goblet of Fire","author": "J. K. Rowling","year": 2000,"genre": "Fantasy Fiction","bestseller": true}}'; + +// Converting JSON object to JS object +var obj = JSON.parse(json); +console.log(obj); + +// Defining custom functions +function firstFunction() { + alert("The first function executed successfully!"); +} + +function secondFunction() { + alert("The second function executed successfully"); +} + +// Selecting button element +var btn = document.getElementById("myBtn"); + +// Assigning event handlers to the button +btn.onclick = firstFunction; +btn.onclick = secondFunction; // This one overwrite the first + +function quick_Sort(origArray) { + if (origArray.length <= 1) { + return origArray; + } else { + + var left = []; + var right = []; + var newArray = []; + var pivot = origArray.pop(); + var length = origArray.length; + + for (var i = 0; i < length; i++) { + if (origArray[i] <= pivot) { + left.push(origArray[i]); + } else { + right.push(origArray[i]); + } + } + + return newArray.concat(quick_Sort(left), pivot, quick_Sort(right)); + } +} + +var myArray = [3, 0, 2, 5, -1, 4, 1 ]; + +console.log("Original array: " + myArray); +var sortedArray = quick_Sort(myArray); +console.log("Sorted array: " + sortedArray); + +function merge_sort(left_part,right_part) +{ + var i = 0; + var j = 0; + var results = []; + + while (i < left_part.length || j < right_part.length) { + if (i === left_part.length) { + // j is the only index left_part + results.push(right_part[j]); + j++; + } + else if (j === right_part.length || left_part[i] <= right_part[j]) { + results.push(left_part[i]); + i++; + } else { + results.push(right_part[j]); + j++; + } + } + return results; +} + +console.log(merge_sort([1,3,4], [3,7,9])); + +var array_length; +/* to create MAX array */ +function heap_root(input, i) { + var left = 2 * i + 1; + var right = 2 * i + 2; + var max = i; + + if (left < array_length && input[left] > input[max]) { + max = left; + } + + if (right < array_length && input[right] > input[max]) { + max = right; + } + + if (max != i) { + swap(input, i, max); + heap_root(input, max); + } +} + +function swap(input, index_A, index_B) { + var temp = input[index_A]; + + input[index_A] = input[index_B]; + input[index_B] = temp; +} + +function heapSort(input) { + + array_length = input.length; + + for (var i = Math.floor(array_length / 2); i >= 0; i -= 1) { + heap_root(input, i); + } + + for (i = input.length - 1; i > 0; i--) { + swap(input, 0, i); + array_length--; + + + heap_root(input, 0); + } +} + +var arr = [3, 0, 2, 5, -1, 4, 1]; +heapSort(arr); +console.log(arr); + +function Selection_Sort(arr, compare_Function) { + + function compare(a, b) { + return a - b; + } + var min = 0; + var index = 0; + var temp = 0; + + //{Function} compare_Function Compare function + compare_Function = compare_Function || compare; + + for (var i = 0; i < arr.length; i += 1) { + index = i; + min = arr[i]; + + for (var j = i + 1; j < arr.length; j += 1) { + if (compare_Function(min, arr[j]) > 0) { + min = arr[j]; + index = j; + } + } + + temp = arr[i]; + arr[i] = min; + arr[index] = temp; + } + + //return sorted arr + return arr; +} + +console.log(Selection_Sort([3, 0, 2, 5, -1, 4, 1], function(a, b) { return a - b; })); +console.log(Selection_Sort([3, 0, 2, 5, -1, 4, 1], function(a, b) { return b - a; })); + + +// https://code-projects.org/simple-tictactoe-in-javascript-with-source-code/ +// Player as Class +var countdown; +class Player { + // Special constructor method + constructor(name, score, turnTotal, avatar, spot) { + // Set properties + this.name = name; + this.score = score; + this.turnTotal = turnTotal; + this.avatar = avatar; + this.spot = spot; + + } +} + +class Tiles { + constructor(id, width, height, x, y, snake, ladder, next) { + this.id = id; + this.width = width; + this.height = height; + this.x = x; + this.y = y; + this.snake = snake; + this.ladder = ladder; + this.next = next; +} + +} + + +class Blocks { + constructor(id, className, innerText, bgColor, snake, ladder, next) { + this.id = id; + this.className = className; + this.innerText = innerText; + this.bgColor = bgColor; + this.snake = snake; + this.ladder = ladder; + this.next = next; + } + +} + + + +class MemoryBlock { + constructor(id, frontImage, backImage) { + this.id = id; + this.blockCSS = "block"; + this.frontImage = frontImage; + this.backImage = backImage; + this.front = false; + this.back = true; + this.frontCSS = "block-front block-face"; + this.backCSS = "block-back block-face"; + this.imgCSS = "block-value"; + + } +} + +function startTimer(duration, display) { + var timer = 60 * duration, minutes, seconds; + countdown = setInterval(() => { + minutes = parseInt(timer / 60, 10); + seconds = parseInt(timer % 60, 10); + minutes = minutes < 10 ? "0" + minutes : minutes; + seconds = seconds < 10 ? "0" + seconds : seconds; + display.textContent = `Time ${ minutes }:${ seconds }`; + if (--timer < 0) { + gameOver(); + } + }, 1000); +} + +class gameInfo { + constructor(totalTime, cards) { + this.cardsArray = cards; + this.totalTime = totalTime; + this.timeRemaining = totalTime; + // this.timer = document.getElementById('time-remaining'); + this.flips = 0; + } +} + +var cells, emptyCells, moves, nextMove, avatar, gameOn, message, winSequence; +var cell0, cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8; + +init(); + +function init() { + moves = 0; + gameOn = true; + winSequence = []; + + cells = Array.from(document.getElementsByClassName('cell')); + cell0 = document.getElementById("C0"); + cell1 = document.getElementById("C1"); + cell2 = document.getElementById("C2"); + cell3 = document.getElementById("C3"); + cell4 = document.getElementById("C4"); + cell5 = document.getElementById("C5"); + cell6 = document.getElementById("C6"); + cell7 = document.getElementById("C7"); + cell8 = document.getElementById("C8"); + document.getElementById("msg").textContent = ""; + for (var i = 0; i < cells.length; i++) { + if (cells[i].hasChildNodes()){ + cells[i].removeChild(cells[i].childNodes[0]); + } + cells[i].style.backgroundColor = ""; + } + addListeners(); +} + +function addListeners() { + document.getElementById("btnReset").addEventListener("click", reset); + emptyCells = cells.filter(element => element.innerHTML === ""); + for (var i = 0; i < emptyCells.length; i++) { + emptyCells[i].addEventListener('click', clickCells); + } +} +function removeListeners() { + for (var i = 0; i < cells.length; i++) { + cells[i].removeEventListener('click', clickCells); + } +} + +function reset() { + // alert("in reset"); + init(); +} + + +function clickCells() { + takeTurn(this.id); + if (checkWinner()) { + var wait = ms => new Promise(resolve => setTimeout(resolve, ms)); + Promise.resolve(500).then(() => wait(500)).then(() => { nextPlayer(); }); + } + else + displayWinner(); +} + +function takeTurn(id) { + if (moves <= 9) { + moves += 1; + var icon = ""; + if (moves % 2 !== 0) { + icon = ``; + } + else { + icon = ``; + } + document.getElementById(id).innerHTML = icon; + removeListeners(); + } + +} + +function nextPlayer() { + emptyCells = cells.filter(element => element.innerHTML === ""); + if (emptyCells.length > 0) { + var randomCell = emptyCells[Math.floor(Math.random() * emptyCells.length)]; + takeTurn(randomCell.id); + if (checkWinner()) + addListeners(); + else + displayWinner(); + } + +} + +function checkWinner() { + + + if (cell0.hasChildNodes() && cell1.hasChildNodes() && cell2.hasChildNodes()) { + // console.log(cell0.childNodes[0].className); + if (cell0.childNodes[0].className === cell1.childNodes[0].className && cell0.childNodes[0].className === cell2.childNodes[0].className) { + message = cell0.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell0, cell1, cell2]; + gameOn = false; + } + } + if (cell3.hasChildNodes() && cell4.hasChildNodes() && cell5.hasChildNodes()) { + // console.log(cell3.childNodes[0].className); + if (cell3.childNodes[0].className === cell4.childNodes[0].className && cell3.childNodes[0].className === cell5.childNodes[0].className) { + message = cell3.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell3, cell4, cell5]; + gameOn = false; + } + } + if (cell6.hasChildNodes() && cell7.hasChildNodes() && cell8.hasChildNodes()) { + // console.log(cell6.childNodes[0].className); + if (cell6.childNodes[0].className === cell7.childNodes[0].className && cell6.childNodes[0].className === cell8.childNodes[0].className) { + message = cell6.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell6, cell7, cell8]; + gameOn = false; + } + } + if (cell0.hasChildNodes() && cell3.hasChildNodes() && cell6.hasChildNodes()) { + //console.log(cell0.childNodes[0].className); + if (cell0.childNodes[0].className === cell3.childNodes[0].className && cell0.childNodes[0].className === cell6.childNodes[0].className) { + message = cell0.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell0, cell3, cell6]; + gameOn = false; + } + } + if (cell1.hasChildNodes() && cell4.hasChildNodes() && cell7.hasChildNodes()) { + //console.log(cell1.childNodes[0].className); + if (cell1.childNodes[0].className === cell4.childNodes[0].className && cell1.childNodes[0].className === cell7.childNodes[0].className) { + message = cell1.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell1, cell4, cell7]; + gameOn = false; + } + } + if (cell2.hasChildNodes() && cell5.hasChildNodes() && cell8.hasChildNodes()) { + // console.log(cell2.childNodes[0].className); + if (cell2.childNodes[0].className === cell5.childNodes[0].className && cell2.childNodes[0].className === cell8.childNodes[0].className) { + message = cell2.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell2, cell5, cell8]; + gameOn = false; + } + } + if (cell0.hasChildNodes() && cell4.hasChildNodes() && cell8.hasChildNodes()) { + // console.log(cell0.childNodes[0].className); + if (cell0.childNodes[0].className === cell4.childNodes[0].className && cell0.childNodes[0].className === cell8.childNodes[0].className) { + message = cell0.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell0, cell4, cell8]; + gameOn = false; + } + } + if (cell2.hasChildNodes() && cell4.hasChildNodes() && cell6.hasChildNodes()) { + // console.log(cell2.childNodes[0].className); + if (cell2.childNodes[0].className === cell4.childNodes[0].className && cell2.childNodes[0].className === cell6.childNodes[0].className) { + message = cell2.childNodes[0].className === "fa fa-heart" ? "You are the winner!" : "AI is the winner!"; + winSequence = [cell2, cell4, cell6]; + gameOn = false; + } + } + + + return gameOn; + +} + +function displayWinner() { + document.getElementById("msg").textContent = message; + for (var i = 0; i < winSequence.length; i++) { + winSequence[i].style.backgroundColor = "cyan"; + } +} + + +// https://code-projects.org/pig-roll-in-javascript-with-source-code/ + +// Player as Class +var countdown; +class Player { + // Special constructor method + constructor(name, score, turnTotal, avatar, spot) { + // Set properties + this.name = name; + this.score = score; + this.turnTotal = turnTotal; + this.avatar = avatar; + this.spot = spot; + + } +} + +class Tiles { + constructor(id, width, height, x, y, snake, ladder, next) { + this.id = id; + this.width = width; + this.height = height; + this.x = x; + this.y = y; + this.snake = snake; + this.ladder = ladder; + this.next = next; +} + +} + + +class Blocks { + constructor(id, className, innerText, bgColor, snake, ladder, next) { + this.id = id; + this.className = className; + this.innerText = innerText; + this.bgColor = bgColor; + this.snake = snake; + this.ladder = ladder; + this.next = next; + } + +} + + + +class MemoryBlock { + constructor(id, frontImage, backImage) { + this.id = id; + this.blockCSS = "block"; + this.frontImage = frontImage; + this.backImage = backImage; + this.front = false; + this.back = true; + this.frontCSS = "block-front block-face"; + this.backCSS = "block-back block-face"; + this.imgCSS = "block-value"; + + } +} + +function startTimer(duration, display) { + var timer = 60 * duration, minutes, seconds; + countdown = setInterval(() => { + minutes = parseInt(timer / 60, 10); + seconds = parseInt(timer % 60, 10); + minutes = minutes < 10 ? "0" + minutes : minutes; + seconds = seconds < 10 ? "0" + seconds : seconds; + display.textContent = `Time ${ minutes }:${ seconds }`; + if (--timer < 0) { + gameOver(); + } + }, 1000); +} + +class gameInfo { + constructor(totalTime, cards) { + this.cardsArray = cards; + this.totalTime = totalTime; + this.timeRemaining = totalTime; + // this.timer = document.getElementById('time-remaining'); + this.flips = 0; + } +} + + +/* +GAME RULES: +- The game has 2 players, playing in rounds +- In each turn, a player rolls a dice as many times as he whishes. Each result get added to his ROUND score +- BUT, if the player rolls a 1, all his ROUND score gets lost. After that, it's the next player's turn +- The player can choose to 'Hold', which means that his ROUND score gets added to his GLBAL score. +After that, it's the next player's turn +- The first player to reach 100 points on GLOBAL score wins the game +*/ + +var score, turnTotal, currentPlayer, gameOn, numText, countOfPlayers, players; + +//Initialize the variables +init(); + +function rollDice() { + if (gameOn) { + var tempScore = parseInt(document.getElementById(`Score${currentPlayer}`).textContent); + var tempTurnTotal = parseInt(document.getElementById(`turnTotal${currentPlayer}`).textContent); + if (tempScore + tempTurnTotal < 20) { + var ranDigit = Math.floor(Math.random() * 6) + 1; + + document.getElementById(`awsDice${currentPlayer}`).style.display = "block"; + document.getElementById(`awsDice${currentPlayer}`).className = `fas fa-dice-${numText[ranDigit - 1]}`; + + if (ranDigit !== 1) { + //Add dice number to turntotal + turnTotal += ranDigit; + document.getElementById(`turnTotal${currentPlayer}`).textContent = turnTotal; + } else { + document.getElementById("message").textContent = "Oops! You rolled a One. Next Player's chance."; + + var wait = ms => new Promise(resolve => setTimeout(resolve, ms)); + Promise.resolve(3000).then(() => wait(1000)).then(() => { nextPlayer(); }); + + //nextPlayer(); + } + } + else { + passTurn(); + } + + } +} + + +function passTurn() { + if (gameOn) { + players[currentPlayer - 1].score += turnTotal; + var latestScore = players[currentPlayer - 1].score; + document.getElementById(`Score${currentPlayer}`).textContent = latestScore; + if (latestScore >= 20) { + document.getElementById("message").textContent = `We have a winner! Congratulations Player${currentPlayer}.`; + document.getElementById(`P${currentPlayer}trophy`).style.display = "block"; + document.getElementById(`awsDice${currentPlayer}`).style.display = "none"; + gameOn = false; + } + else + nextPlayer(); + } +} + + +function reset() { + // alert("in reset"); + init(); +} + +function nextPlayer() { + turnTotal = 0; + document.getElementById("message").textContent = ""; + document.getElementById("turnTotal1").textContent = 0; + document.getElementById("turnTotal2").textContent = 0; + document.getElementById('awsDice1').style.display = "none"; + document.getElementById('awsDice2').style.display = "none"; + document.getElementById(`P${currentPlayer}active`).style.display = "none"; + currentPlayer = currentPlayer < countOfPlayers ? ++currentPlayer : 1; + document.getElementById(`P${currentPlayer}active`).style.display = "block"; +} + +function init() { + currentPlayer = 1; + countOfPlayers = 2; + players = new Array(countOfPlayers); + gameOn = true; + score = 0; + turnTotal = 0; + numText = ["one", "two", "three", "four", "five", "six"]; + for (var count = 0; count < countOfPlayers; count++) { + var playerData = new Player(`Player${count + 1}`, score, turnTotal); + players[count] = playerData; + } + document.getElementById('P1active').style.display = "block"; + document.getElementById('P2active').style.display = "none"; + document.getElementById('P1trophy').style.display = "none"; + document.getElementById('P2trophy').style.display = "none"; + document.getElementById("message").textContent = ""; + document.getElementById("turnTotal1").textContent = 0; + document.getElementById("turnTotal2").textContent = 0; + document.getElementById("Score1").textContent = 0; + document.getElementById("Score2").textContent = 0; + document.getElementById("btnRoll").addEventListener("click", rollDice); + document.getElementById("btnPass").addEventListener("click", passTurn); + document.getElementById("btnReset").addEventListener("click", reset); + +} + +// https://code-projects.org/flip-flop-game-in-javascript-with-source-code/ +// Player as Class +var countdown; +class Player { + // Special constructor method + constructor(name, score, turnTotal, avatar, spot) { + // Set properties + this.name = name; + this.score = score; + this.turnTotal = turnTotal; + this.avatar = avatar; + this.spot = spot; + + } +} + +class Tiles { + constructor(id, width, height, x, y, snake, ladder, next) { + this.id = id; + this.width = width; + this.height = height; + this.x = x; + this.y = y; + this.snake = snake; + this.ladder = ladder; + this.next = next; +} + +} + + +class Blocks { + constructor(id, className, innerText, bgColor, snake, ladder, next) { + this.id = id; + this.className = className; + this.innerText = innerText; + this.bgColor = bgColor; + this.snake = snake; + this.ladder = ladder; + this.next = next; + } + +} + + + +class MemoryBlock { + constructor(id, frontImage, backImage) { + this.id = id; + this.blockCSS = "block"; + this.frontImage = frontImage; + this.backImage = backImage; + this.front = false; + this.back = true; + this.frontCSS = "block-front block-face"; + this.backCSS = "block-back block-face"; + this.imgCSS = "block-value"; + + } +} + +function startTimer(duration, display) { + var timer = 60 * duration, minutes, seconds; + countdown = setInterval(() => { + minutes = parseInt(timer / 60, 10); + seconds = parseInt(timer % 60, 10); + minutes = minutes < 10 ? "0" + minutes : minutes; + seconds = seconds < 10 ? "0" + seconds : seconds; + display.textContent = `Time ${ minutes }:${ seconds }`; + if (--timer < 0) { + gameOver(); + } + }, 1000); +} + +class gameInfo { + constructor(totalTime, cards) { + this.cardsArray = cards; + this.totalTime = totalTime; + this.timeRemaining = totalTime; + // this.timer = document.getElementById('time-remaining'); + this.flips = 0; + } +} + +// for creating divs and shuffling blocks +var divblock, blockData, blockFrontImages, memoryBlockArr, blocksArray, blockFrontImagesAll, shuffledBlocks; +// for implementing flip n match logic +var currentlyFlippedArr, matchedCount, blockToMatch1, blockToMatch2; +// for implementing game info block +var flipCounter, timer, gameOn = false; + +var overlays = Array.from(document.getElementsByClassName('overlay-text')); +overlays.forEach(overlay => { + overlay.addEventListener('click', () => { + overlay.classList.remove('visible'); + resetGame(); + init(); + + }); +}); + +function startCountdown() { + return setInterval(() => { + this.timeRemaining--; + this.timer.innerText = this.timeRemaining; + if (this.timeRemaining === 0) + this.gameOver(); + }, 1000); +} + +function resetGame() { + var elements = document.getElementsByClassName("block"); + while (elements.length > 0) { + elements[0].parentNode.removeChild(elements[0]); + } +} + +function init() { + //initializing values + gameOn = true; + memoryBlockArr = new Array(18); + blocksArray = []; + blockFrontImagesAll = []; + shuffledBlocks = []; + currentlyFlippedArr = []; + matchedCount = 0; + flipCounter = 0; + var minutes = 2; + var display = document.getElementById("Timer"); + blockFrontImages = ["Images/pokemon1.gif", + "Images/pokemon2.gif", + "Images/pokemon3.gif", + "Images/pokemon4.gif", + "Images/pokemon5.gif", + "Images/pokemon6.gif", + "Images/pokemon7.gif", + "Images/pokemon8.gif", + "Images/pokemon9.gif"]; + // init(); + startTimer(minutes, display); + blockFrontImagesAll = blockFrontImages.concat(blockFrontImages); + shuffledBlocks = shuffleBlocks(blockFrontImagesAll); + document.getElementById("Flips").innerText = `Flips: ${flipCounter}`; + createElements(); +} + + + +function createElements() { + var finalCount = shuffledBlocks.length; + for (var i = 0; i < finalCount; i++) { + var cardFront = shuffledBlocks.pop(); + blockData = new MemoryBlock(i, cardFront, "Images/pokemonBack.jpg"); + memoryBlockArr[i] = blockData; + + divblock = document.createElement("div"); + divblockFront = document.createElement("div"); + divblockBack = document.createElement("div"); + imgFront = document.createElement("img"); + imgBack = document.createElement("img"); + divblock.id = memoryBlockArr[i].id; + divblock.className = memoryBlockArr[i].blockCSS; + divblockFront.className = memoryBlockArr[i].frontCSS; + divblockBack.className = memoryBlockArr[i].backCSS; + imgFront.src = memoryBlockArr[i].frontImage; + imgFront.className = memoryBlockArr[i].imgCSS; + imgBack.src = memoryBlockArr[i].backImage; + imgBack.className = memoryBlockArr[i].imgCSS; + divblockFront.append(imgFront); + divblockBack.append(imgBack); + divblock.append(divblockFront); + divblock.append(divblockBack); + divblock.addEventListener('click', flipBlock); + document.getElementById("gameMainBlock").append(divblock); + } +} + +function hideElements() { + hideBlocks = Array.from(document.getElementsByClassName('block')); + for (var i = 0; i < hideBlocks.length; i++) { + document.getElementById(hideBlocks[i].id).classList.remove('visible'); + } +} + +function shuffleBlocks(blocksArray) { + var currentIndex = blocksArray.length, temporaryValue, randomIndex; + // While there remain elements to shuffle... + while (currentIndex !== 0) { + // Pick an element from the remaining lot... + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + // Swap it with the current element. + temporaryValue = blocksArray[currentIndex]; + blocksArray[currentIndex] = blocksArray[randomIndex]; + blocksArray[randomIndex] = temporaryValue; + } + return blocksArray; +} + +function flipBlock() { + if (gameOn === true) { + this.classList.add('visible'); + flipCounter += 1; + document.getElementById("Flips").innerText = `Flips: ${flipCounter}`; + + + if (blockToMatch1 !== this.id) { + if (currentlyFlippedArr.length === 0) { + currentlyFlippedArr.push(this.innerHTML); + blockToMatch1 = this.id; + } + else if (currentlyFlippedArr.length === 1) { + currentlyFlippedArr.push(this.innerHTML); + blockToMatch2 = this.id; + if (currentlyFlippedArr[0] === currentlyFlippedArr[1]) { + blocksMatched(); + } + else { + gameOn = false; + var wait = ms => new Promise(resolve => setTimeout(resolve, ms)); + Promise.resolve(800).then(() => wait(800)).then(() => { revertFlip(); }); + + } + } + } + } +} + +function blocksMatched() { + currentlyFlippedArr = []; + matchedCount += 2; + document.getElementById(blockToMatch1).removeEventListener('click', flipBlock); + document.getElementById(blockToMatch2).removeEventListener('click', flipBlock); + if (matchedCount === memoryBlockArr.length) { + // if (matchedCount === 2) { + var wait = ms => new Promise(resolve => setTimeout(resolve, ms)); + Promise.resolve(1000).then(() => wait(1000)).then(() => { showWin(); }); + } +} + +function revertFlip() { + // alert(blockToMatch1 + " trying to revert " + blockToMatch2); + document.getElementById(blockToMatch1).classList.remove('visible'); + document.getElementById(blockToMatch2).classList.remove('visible'); + currentlyFlippedArr = []; + gameOn = true; +} + +function showWin() { + hideElements(); + gameOn = false; + document.getElementById('winText').classList.add('visible'); + clearInterval(countdown); +} + +function gameOver() { + // hideElements(); + gameOn = false; + document.getElementById('gameOverText').classList.add('visible'); + clearInterval(countdown); +} + +// https://www.webfx.com/blog/web-design/6-advanced-javascript-techniques-you-should-know/ + +function myObject() { + this.property1 = "value1"; + this.property2 = "value2"; + var newValue = this.property1; + this.performMethod = function() { + myMethodValue = newValue; + return myMethodValue; + }; + } + var myObjectInstance = new myObject(); + alert(myObjectInstance.performMethod()); + +function showStatistics(name, team, position, average, homeruns, rbi) { + document.write("

Name: " + arguments[0] + "
"); + document.write("Team: " + arguments[1] + "
"); + + if (typeof arguments[2] === "string") { + document.write("Position: " + position + "
"); + } + if (typeof arguments[3] === "number") { + document.write("Batting Average: " + average + "
"); + } + if (typeof arguments[4] === "number") { + document.write("Home Runs: " + homeruns + "
"); + } + if (typeof arguments[5] === "number") { + document.write("Runs Batted In: " + rbi + "

"); + } +} +showStatistics("Mark Teixeira"); +showStatistics("Mark Teixeira", "New York Yankees"); +showStatistics("Mark Teixeira", "New York Yankees", "1st Base", .284, 32, 101); + +function showStatistics(args) { + document.write("

Name: " + args.name + "
"); + document.write("Team: " + args.team + "
"); + if (typeof args.position === "string") { + document.write("Position: " + args.position + "
"); + } + if (typeof args.average === "number") { + document.write("Average: " + args.average + "
"); + } + if (typeof args.homeruns === "number") { + document.write("Home Runs: " + args.homeruns + "
"); + } + if (typeof args.rbi === "number") { + document.write("Runs Batted In: " + args.rbi + "

"); + } +} + +showStatistics({ + name: "Mark Teixeira" +}); + +showStatistics({ + name: "Mark Teixeira", + team: "New York Yankees" +}); + +showStatistics({ + name: "Mark Teixeira", + team: "New York Yankees", + position: "1st Base", + average: .284, + homeruns: 32, + rbi: 101 +}); + +var myLinkCollection = document.getElementsByTagName("a"); + +for (i=0;i