Best JavaScript code snippet using root
adventure.js
Source:adventure.js
...352 document.getElementById("lose").style.display = "block";353 startLocation1 = originalLocation1;354 startLocation2 = originalLocation2;355 startLocation3 = originalLocation3;356 clearTimeout(currentProjectile3);357 clearTimeout(currentProjectile2);358 clearTimeout(currentProjectile1);359 clearTimeout(currentAnimation1);360 clearTimeout(currentAnimation2);361 clearTimeout(currentAnimation3);362 clearTimeout(currentAnimation4);363 clearTimeout(currentAnimation5);364 clearTimeout(currentAnimation6);365 clearTimeout(currentAnimation7);366 clearTimeout(currentAnimation8);367 clearTimeout(currentAnimation9);368 clearTimeout(currentAnimation10);369 clearTimeout(currentAnimation11);370 clearTimeout(currentAnimation12);371 clearTimeout(currentAnimation13);372 clearTimeout(currentAnimation14);373 clearTimeout(currentAnimation15);374 clearTimeout(currentAnimation16);375 canMove = false;376 return;377 } else if (nextClass.includes("enemy")){378 if(!newClass.includes("armor")){379 document.getElementById("lose").style.display = "block";380 startLocation1 = originalLocation1;381 startLocation2 = originalLocation2;382 startLocation3 = originalLocation3;383 clearTimeout(currentProjectile3);384 clearTimeout(currentProjectile2);385 clearTimeout(currentProjectile1);386 clearTimeout(currentAnimation1);387 clearTimeout(currentAnimation2);388 clearTimeout(currentAnimation3);389 clearTimeout(currentAnimation4);390 clearTimeout(currentAnimation5);391 clearTimeout(currentAnimation6);392 clearTimeout(currentAnimation7);393 clearTimeout(currentAnimation8);394 clearTimeout(currentAnimation9);395 clearTimeout(currentAnimation10);396 clearTimeout(currentAnimation11);397 clearTimeout(currentAnimation12);398 clearTimeout(currentAnimation13);399 clearTimeout(currentAnimation14);400 clearTimeout(currentAnimation15);401 clearTimeout(currentAnimation16);402 canMove = false;403 return;404 }405 }406 407 // if it is an orb408 if(nextClass.includes("orb")){409 document.getElementById("lose").style.display = "block";410 startLocation1 = originalLocation1;411 startLocation2 = originalLocation2;412 startLocation3 = originalLocation3;413 clearTimeout(currentProjectile3);414 clearTimeout(currentProjectile2);415 clearTimeout(currentProjectile1);416 clearTimeout(currentAnimation1);417 clearTimeout(currentAnimation2);418 clearTimeout(currentAnimation3);419 clearTimeout(currentAnimation4);420 clearTimeout(currentAnimation5);421 clearTimeout(currentAnimation6);422 clearTimeout(currentAnimation7);423 clearTimeout(currentAnimation8);424 clearTimeout(currentAnimation9);425 clearTimeout(currentAnimation10);426 clearTimeout(currentAnimation11);427 clearTimeout(currentAnimation12);428 clearTimeout(currentAnimation13);429 clearTimeout(currentAnimation14);430 clearTimeout(currentAnimation15);431 clearTimeout(currentAnimation16);432 canMove = false;433 return;434 }435 436 if(nextClass.includes("druid")){437 if(!newClass.includes("armor")){438 document.getElementById("lose").style.display = "block";439 startLocation1 = originalLocation1;440 startLocation2 = originalLocation2;441 startLocation3 = originalLocation3;442 clearTimeout(currentProjectile3);443 clearTimeout(currentProjectile2);444 clearTimeout(currentProjectile1);445 clearTimeout(currentAnimation1);446 clearTimeout(currentAnimation2);447 clearTimeout(currentAnimation3);448 clearTimeout(currentAnimation4);449 clearTimeout(currentAnimation5);450 clearTimeout(currentAnimation6);451 clearTimeout(currentAnimation7);452 clearTimeout(currentAnimation8);453 clearTimeout(currentAnimation9);454 clearTimeout(currentAnimation10);455 clearTimeout(currentAnimation11);456 clearTimeout(currentAnimation12);457 clearTimeout(currentAnimation13);458 clearTimeout(currentAnimation14);459 clearTimeout(currentAnimation15);460 clearTimeout(currentAnimation16);461 canMove = false;462 return;463 } 464 }465 466 //move up a level if needed467 levelUp(nextClass);468 469} //tryToMove470471// move up a level472function levelUp(nextClass) {473 if (nextClass == "flag" && riderOn && currentLevel < totalLevels) {474 document.getElementById("levelup").style.display = "block";475 clearTimeout(currentAnimation);476 setTimeout (function() {477 document.getElementById("levelup").style.display = "none";478 currentLevel++; //add an if statement if there are no more levels dont increment479 loadLevel(); 480 481 }, 1000);482 483 } else if(nextClass == "flag" && riderOn && currentLevel >= totalLevels){484 document.getElementById("end").style.display = "block";485 clearTimeout(currentAnimation);486 } // else if487 488} //levelUp489490491// load current levels 0 - maxlevel492function loadLevel(){493 let levelMap = levels[currentLevel];494 let animateBoxes1 = [];495 let animateBoxes2 = [];496 let animateBoxes3 = [];497 let animateBoxes4 = [];498 let animateBoxes5 = [];499 let animateBoxes6 = [];500 let animateBoxes7 = [];501 let animateBoxes8 = [];502 let animateBoxes9 = [];503 let animateBoxes10 = [];504 let animateBoxes11= [];505 let animateBoxes12 = [];506 let animateBoxes13 = [];507 let animateBoxes14 = [];508 let animateBoxes15 = [];509 let animateBoxes16 = [];510 let animate1Index = 0;511 let animate2Index = 0;512 let animate3Index = 0;513 let animate4Index = 0;514 let animate5Index = 0;515 let animate6Index = 0;516 let animate5Direction = "left";517 let animate6Direction = "down";518 let projectile1 = 0;519 let projectile2 = 0;520 let projectile3 = 0;521 riderOn = false;522 armorOn = false;523 canMove = true;524 document.getElementById("lose").style.display = "none";525 526 // load board527 for(var i = 0; i < gridBoxes.length; i++){528 gridBoxes[i].className = levelMap[i];529 if(levelMap[i].includes("char")) currentLocationOfHorse = i;530 if(levelMap[i].includes("proj1")){531 projectile1 = i;532 }533 if(levelMap[i].includes("proj2")){534 projectile2 = i;535 }536 if(levelMap[i].includes("proj3")){537 projectile3 = i;538 }539 if(currentLevel == 0){540 if(levelMap[i].includes("start animate1")){ 541 enemyStart1 = i - 1;542 currentLocationOfEnemy1 = enemyStart1;543 }// if544 if(levelMap[i].includes("start animate2")){ 545 enemyStart2 = i - 1;546 currentLocationOfEnemy2 = enemyStart2;547 }// if548 if(levelMap[i].includes("start animate3")){ 549 enemyStart3 = i - 1;550 currentLocationOfEnemy3 = enemyStart3;551 }// if552 if(levelMap[i].includes("start animate4")){ 553 enemyStart4 = i - 1;554 currentLocationOfEnemy4 = enemyStart4;555 }// if556 if(levelMap[i].includes("start animate5")){ 557 enemyStart5 = i + 6;558 currentLocationOfEnemy5 = enemyStart5;559 } 560 } else if (currentLevel == 1){561 562 if(levelMap[i].includes("start animate6")){ 563 enemyStart6 = i;564 currentLocationOfEnemy6 = enemyStart6;565 }566 if(levelMap[i].includes("start animate7")){ 567 enemyStart7 = i ;568 currentLocationOfEnemy7 = enemyStart7;569 }570 if(levelMap[i].includes("start animate8")){ 571 enemyStart8 = i ;572 currentLocationOfEnemy8 = enemyStart8;573 }574 if(levelMap[i].includes("start animate9")){ 575 enemyStart9 = i + 4;576 currentLocationOfEnemy9 = enemyStart9;577 }578 if(levelMap[i].includes("start animate10")){ 579 enemyStart10 = i + 6;580 currentLocationOfEnemy10 = enemyStart10;581 }582 } else if(currentLevel == 2){583 584 if(levelMap[i].includes("start animate11")){ 585 enemyStart11 = i - 1;586 currentLocationOfEnemy11 = enemyStart11;587 }588 if(levelMap[i].includes("start animate12")){ 589 enemyStart12 = i - 1;590 currentLocationOfEnemy12 = enemyStart12;591 }592 if(levelMap[i].includes("start animate13")){ 593 enemyStart13 = i - 1;594 currentLocationOfEnemy13 = enemyStart13;595 }596 if(levelMap[i].includes("start animate14")){ 597 enemyStart14 = i - 1;598 currentLocationOfEnemy14 = enemyStart14;599 }600 if(levelMap[i].includes("start animate15")){ 601 enemyStart15 = i - 1;602 currentLocationOfEnemy15 = enemyStart15;603 }604 if(levelMap[i].includes("start animate16")){ 605 enemyStart16 = i - 1;606 currentLocationOfEnemy16 = enemyStart16;607 }// if608 }609610 } // for611 612 animateBoxes1 = document.querySelectorAll(".animate1");613 animateBoxes2 = document.querySelectorAll(".animate2");614 animateBoxes3 = document.querySelectorAll(".animate3");615 animateBoxes4 = document.querySelectorAll(".animate4");616 animateBoxes5 = document.querySelectorAll(".animate5");617 animateBoxes6 = document.querySelectorAll(".animate6");618 animateBoxes7 = document.querySelectorAll(".animate7");619 animateBoxes8 = document.querySelectorAll(".animate8");620 animateBoxes9 = document.querySelectorAll(".animate9");621 animateBoxes10 = document.querySelectorAll(".animate10");622 animateBoxes11 = document.querySelectorAll(".animate11");623 animateBoxes12 = document.querySelectorAll(".animate12");624 animateBoxes13 = document.querySelectorAll(".animate13");625 animateBoxes14 = document.querySelectorAll(".animate14");626 animateBoxes15 = document.querySelectorAll(".animate15");627 animateBoxes16 = document.querySelectorAll(".animate16");628 629 if(currentLevel == 0){630631 animateEnemy1(animateBoxes1, 0, "right");632 animateEnemy2(animateBoxes2, 0, "right");633 animateEnemy3(animateBoxes3, 0, "right");634 animateEnemy4(animateBoxes4, 0, "right");635 animateEnemy5(animateBoxes5, 5, animate5Direction);636 } else if (currentLevel == 1) {637 638 animateEnemy6(animateBoxes6, 0, "right"); 639 animateEnemy7(animateBoxes7, 0, "right"); 640 animateEnemy8(animateBoxes8, 0, "right"); 641 animateEnemy9(animateBoxes9,4, "right"); 642 animateEnemy10(animateBoxes10, 7, "left"); 643 } else if (currentLevel == 2){644 animateEnemy11(animateBoxes11, 0, "right"); 645 animateEnemy12(animateBoxes12, 0, "right"); 646 animateEnemy13(animateBoxes13, 0, "right"); 647 animateEnemy14(animateBoxes14, 0, "right"); 648 animateEnemy15(animateBoxes15, 0, "right"); 649 animateEnemy16(animateBoxes16, 0, "right"); 650 }651 652 if(currentLevel == 2){653 animateProjectile1(projectile1);654 animateProjectile2(projectile2);655 animateProjectile3(projectile3);656 }657 658} //loadLevel659660//animate projectiles661function animateProjectile1(startLocation){662 if(stage1 == 0){663 startLocation1 = startLocation;664 startLocation = startLocation1;665 gridBoxes[startLocation].classList.add("orb");666 originalLocation1 = startLocation;667 }668 if(stage1 == 1){669 gridBoxes[startLocation].classList.remove("orb");670 startLocation -= widthOfBoard;671 gridBoxes[startLocation].classList.add("orb");672 }673 if(stage1 == 2){674 gridBoxes[startLocation].classList.remove("orb");675 startLocation -= widthOfBoard;676 gridBoxes[startLocation].classList.add("orb");677 }678 if(stage1 == 3){679 gridBoxes[startLocation].classList.remove("orb");680 startLocation -= widthOfBoard;681 gridBoxes[startLocation].classList.add("orb");682 }683 if(stage1 == 4){684 gridBoxes[startLocation].classList.remove("orb");685 startLocation = originalLocation1;686 startLocation += 10;687 stage1 = 0;688 }689 690 if(currentLocationOfHorse == startLocation){691 document.getElementById("lose").style.display = "block";692 startLocation1 = originalLocation1;693 startLocation2 = originalLocation2;694 startLocation3 = originalLocation3;695 clearTimeout(currentProjectile3);696 clearTimeout(currentProjectile2);697 clearTimeout(currentProjectile1);698 clearTimeout(currentAnimation1);699 clearTimeout(currentAnimation2);700 clearTimeout(currentAnimation3);701 clearTimeout(currentAnimation4);702 clearTimeout(currentAnimation5);703 clearTimeout(currentAnimation6);704 clearTimeout(currentAnimation7);705 clearTimeout(currentAnimation8);706 clearTimeout(currentAnimation9);707 clearTimeout(currentAnimation10);708 clearTimeout(currentAnimation11);709 clearTimeout(currentAnimation12);710 clearTimeout(currentAnimation13);711 clearTimeout(currentAnimation14);712 clearTimeout(currentAnimation15);713 clearTimeout(currentAnimation16);714 canMove = false;715 716 return; 717 }718 currentProjectile1 = setTimeout(function(){719 animateProjectile1(startLocation);720 721 }, 1000);722 723 stage1++;724}725726function animateProjectile2(startLocation){727 if(stage2 == 0){728 startLocation2 = startLocation;729 startLocation = startLocation2;730 gridBoxes[startLocation].classList.add("orb");731 originalLocation2 = startLocation;732 }733 if(stage2 == 1){734 gridBoxes[startLocation].classList.remove("orb");735 startLocation -= widthOfBoard;736 gridBoxes[startLocation].classList.add("orb");737 }738 if(stage2 == 2){739 gridBoxes[startLocation].classList.remove("orb");740 startLocation -= widthOfBoard;741 gridBoxes[startLocation].classList.add("orb");742 }743 if(stage2 == 3){744 gridBoxes[startLocation].classList.remove("orb");745 startLocation -= widthOfBoard;746 gridBoxes[startLocation].classList.add("orb");747 }748 if(stage2 == 4){749 gridBoxes[startLocation].classList.remove("orb");750 startLocation = originalLocation2;751 startLocation += 10;752 stage2 = 0;753 }754 755 if(currentLocationOfHorse == startLocation){756 document.getElementById("lose").style.display = "block";757 startLocation1 = originalLocation1;758 startLocation2 = originalLocation2;759 startLocation3 = originalLocation3;760 clearTimeout(currentProjectile3);761 clearTimeout(currentProjectile2);762 clearTimeout(currentProjectile1);763 clearTimeout(currentAnimation1);764 clearTimeout(currentAnimation2);765 clearTimeout(currentAnimation3);766 clearTimeout(currentAnimation4);767 clearTimeout(currentAnimation5);768 clearTimeout(currentAnimation6);769 clearTimeout(currentAnimation7);770 clearTimeout(currentAnimation8);771 clearTimeout(currentAnimation9);772 clearTimeout(currentAnimation10);773 clearTimeout(currentAnimation11);774 clearTimeout(currentAnimation12);775 clearTimeout(currentAnimation13);776 clearTimeout(currentAnimation14);777 clearTimeout(currentAnimation15);778 clearTimeout(currentAnimation16);779 canMove = false;780 781 return; 782 }783 currentProjectile2 = setTimeout(function(){784 animateProjectile2(startLocation);785 786 }, 1000);787 788 stage2++;789}790791function animateProjectile3(startLocation){792 if(stage3 == 0){793 startLocation3 = startLocation;794 startLocation = startLocation3;795 originalLocation3 = startLocation;796 gridBoxes[startLocation].classList.add("orb");797 798 }799 if(stage3 == 1){800 gridBoxes[startLocation].classList.remove("orb");801 startLocation -= widthOfBoard;802 gridBoxes[startLocation].classList.add("orb");803 }804 if(stage3 == 2){805 gridBoxes[startLocation].classList.remove("orb");806 startLocation -= widthOfBoard;807 gridBoxes[startLocation].classList.add("orb");808 }809 if(stage3 == 3){810 gridBoxes[startLocation].classList.remove("orb");811 startLocation -= widthOfBoard;812 gridBoxes[startLocation].classList.add("orb");813 }814 if(stage3 == 4){815 gridBoxes[startLocation].classList.remove("orb");816 startLocation = originalLocation3;817 startLocation += 10;818 stage3 = 0;819 }820 821 if(currentLocationOfHorse == startLocation){822 document.getElementById("lose").style.display = "block";823 startLocation1 = originalLocation1;824 startLocation2 = originalLocation2;825 startLocation3 = originalLocation3;826 clearTimeout(currentProjectile3);827 clearTimeout(currentProjectile2);828 clearTimeout(currentProjectile1);829 clearTimeout(currentAnimation1);830 clearTimeout(currentAnimation2);831 clearTimeout(currentAnimation3);832 clearTimeout(currentAnimation4);833 clearTimeout(currentAnimation5);834 clearTimeout(currentAnimation6);835 clearTimeout(currentAnimation7);836 clearTimeout(currentAnimation8);837 clearTimeout(currentAnimation9);838 clearTimeout(currentAnimation10);839 clearTimeout(currentAnimation11);840 clearTimeout(currentAnimation12);841 clearTimeout(currentAnimation13);842 clearTimeout(currentAnimation14);843 clearTimeout(currentAnimation15);844 clearTimeout(currentAnimation16);845 canMove = false;846 847 return; 848 }849 currentProjectile3 = setTimeout(function(){850 animateProjectile3(startLocation);851 852 }, 1000);853 854 stage3++;855 856 857}858// animate enemy left to right859// boxes - array of grid boxes that include animation860// index - current location of animation861// direction - current direction of animation862function animateEnemy1(boxes, index, direction){///////////////////863 864 if(counter == 0){865 currentLocationOfEnemy1 = enemyStart1;866 } // if867 868 // exits function if no animation869 if(boxes.length <= 0){ return;}870 if(currentLevel == 1){ return;}871 if(currentLevel == 2){ return;}872 // update the images873 if(direction == "right"){874 boxes[index].classList.add("enemy2right");875 } else{876 boxes[index].classList.add("enemy2left");877 } //else878 879 // remove images from other boxes880 for(i = 0; i < boxes.length; i++){881 if(i != index){882 boxes[i].classList.remove("enemy2left");883 boxes[i].classList.remove("enemy2right");884 } //if885 } //for886887 // moving right888 if(direction == "right"){889 if(counter >= 1){890891 currentLocationOfEnemy1++;892 } // if893 894 // turn around if hit right side of animation895 if(index == boxes.length - 1){896 //currentLocationOfEnemy = currentLocationOfEnemy + 1;897 index--;898 direction = "left";899 } else{900 index++;901 } //else902 903 // moving left904 } else{905 if(counter >= 1){906907 currentLocationOfEnemy1--;908 } //if 909 910 // turn around if hit left side of animation911 if(index == 0){912 // currentLocationOfEnemy = currentLocationOfEnemy - 1;913 index++;914 direction = "right";915 } else{916 index--;917 } //else918 919 }// else920 921 // if enemy runs into player, end the game922923 if(currentLocationOfHorse == currentLocationOfEnemy1){924 document.getElementById("lose").style.display = "block";925 startLocation1 = originalLocation1;926 startLocation2 = originalLocation2;927 startLocation3 = originalLocation3;928 clearTimeout(currentProjectile3);929 clearTimeout(currentProjectile2);930 clearTimeout(currentProjectile1);931 clearTimeout(currentAnimation1);932 clearTimeout(currentAnimation2);933 clearTimeout(currentAnimation3);934 clearTimeout(currentAnimation4);935 clearTimeout(currentAnimation5);936 clearTimeout(currentAnimation6);937 clearTimeout(currentAnimation7);938 clearTimeout(currentAnimation8);939 clearTimeout(currentAnimation9);940 clearTimeout(currentAnimation10);941 clearTimeout(currentAnimation11);942 clearTimeout(currentAnimation12);943 clearTimeout(currentAnimation13);944 clearTimeout(currentAnimation14);945 clearTimeout(currentAnimation15);946 clearTimeout(currentAnimation16);947 canMove = false;948 return; 949 } //if950 951counter++;952 953 currentAnimation1 = setTimeout(function(){954 animateEnemy1(boxes, index, direction);955 }, 750);956 957 //counter++;958959 960}// animateEnemy1961962// animate enemy left to right963// boxes - array of grid boxes that include animation964// index - current location of animation965// direction - current direction of animation966// enemy - type of enemy displayed967function animateEnemy2(boxes, index, direction){///////////////////968 969 if(counter == 0){970 currentLocationOfEnemy2 = enemyStart2;971 } // if972 973 // exits function if no animation974 if(boxes.length <= 0){ return;}975 if(currentLevel == 1){ return;}976 if(currentLevel == 2){ return;}977 978 // update the images979 if(direction == "right"){980 boxes[index].classList.add("enemy2right");981 } else{982 boxes[index].classList.add("enemy2left");983 } //else984 985 // remove images from other boxes986 for(i = 0; i < boxes.length; i++){987 if(i != index){988 boxes[i].classList.remove("enemy2left");989 boxes[i].classList.remove("enemy2right");990 } //if991 } //for992 993 // moving right994 if(direction == "right"){995 if(counter >= 1){996997 currentLocationOfEnemy2++;998 } // if999 1000 // turn around if hit right side of animation1001 if(index == boxes.length - 1){1002 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1003 index--;1004 direction = "left";1005 } else{1006 index++;1007 } //else1008 1009 // moving left1010 } else{1011 if(counter >= 1){10121013 currentLocationOfEnemy2--;1014 } //if 1015 1016 // turn around if hit left side of animation1017 if(index == 0){1018 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1019 index++;1020 direction = "right";1021 } else{1022 index--;1023 } //else1024 1025 }// else1026 10271028 currentAnimation2 = setTimeout(function(){1029 animateEnemy2(boxes, index, direction);1030 }, 750);1031 1032 //counter++;10331034 // if enemy runs into player, end the game1035 if(currentLocationOfHorse == currentLocationOfEnemy2){1036 document.getElementById("lose").style.display = "block";1037 startLocation1 = originalLocation1;1038 startLocation2 = originalLocation2;1039 startLocation3 = originalLocation3;1040 clearTimeout(currentProjectile3);1041 clearTimeout(currentProjectile2);1042 clearTimeout(currentProjectile1);1043 clearTimeout(currentAnimation1);1044 clearTimeout(currentAnimation2);1045 clearTimeout(currentAnimation3);1046 clearTimeout(currentAnimation4);1047 clearTimeout(currentAnimation5);1048 clearTimeout(currentAnimation6);1049 clearTimeout(currentAnimation7);1050 clearTimeout(currentAnimation8);1051 clearTimeout(currentAnimation9);1052 clearTimeout(currentAnimation10);1053 clearTimeout(currentAnimation11);1054 clearTimeout(currentAnimation12);1055 clearTimeout(currentAnimation13);1056 clearTimeout(currentAnimation14);1057 clearTimeout(currentAnimation15);1058 clearTimeout(currentAnimation16);1059 canMove = false;1060 return; 1061 } //if1062}// animateEnemy210631064// animate enemy left to right1065// boxes - array of grid boxes that include animation1066// index - current location of animation1067// direction - current direction of animation1068// enemy - type of enemy displayed1069function animateEnemy3(boxes, index, direction){///////////////////1070 1071 if(counter == 0){1072 currentLocationOfEnemy3 = enemyStart3;1073 } // if1074 1075 // exits function if no animation1076 if(boxes.length <= 0){ return;}1077 if(currentLevel == 1){ return;}1078 if(currentLevel == 2){ return;}1079 1080 // update the images1081 if(direction == "right"){1082 boxes[index].classList.add("enemy2right");1083 } else{1084 boxes[index].classList.add("enemy2left");1085 } //else1086 1087 // remove images from other boxes1088 for(i = 0; i < boxes.length; i++){1089 if(i != index){1090 boxes[i].classList.remove("enemy2left");1091 boxes[i].classList.remove("enemy2right");1092 } //if1093 } //for1094 1095 // moving right1096 if(direction == "right"){1097 if(counter >= 1){10981099 currentLocationOfEnemy3++;1100 } // if1101 1102 // turn around if hit right side of animation1103 if(index == boxes.length - 1){1104 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1105 index--;1106 direction = "left";1107 } else{1108 index++;1109 } //else1110 1111 // moving left1112 } else{1113 if(counter >= 1){11141115 currentLocationOfEnemy3--;1116 } //if 1117 1118 // turn around if hit left side of animation1119 if(index == 0){1120 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1121 index++;1122 direction = "right";1123 } else{1124 index--;1125 } //else1126 1127 }// else1128 11291130 currentAnimation3 = setTimeout(function(){1131 animateEnemy3(boxes, index, direction);1132 }, 750);1133 1134 //counter++;11351136 // if enemy runs into player, end the game11371138 if(currentLocationOfHorse == currentLocationOfEnemy3){1139 document.getElementById("lose").style.display = "block";1140 startLocation1 = originalLocation1;1141 startLocation2 = originalLocation2;1142 startLocation3 = originalLocation3;1143 clearTimeout(currentProjectile3);1144 clearTimeout(currentProjectile2);1145 clearTimeout(currentProjectile1);1146 clearTimeout(currentAnimation1);1147 clearTimeout(currentAnimation2);1148 clearTimeout(currentAnimation3);1149 clearTimeout(currentAnimation4);1150 clearTimeout(currentAnimation5);1151 clearTimeout(currentAnimation6);1152 clearTimeout(currentAnimation7);1153 clearTimeout(currentAnimation8);1154 clearTimeout(currentAnimation9);1155 clearTimeout(currentAnimation10);1156 clearTimeout(currentAnimation11);1157 clearTimeout(currentAnimation12);1158 clearTimeout(currentAnimation13);1159 clearTimeout(currentAnimation14);1160 clearTimeout(currentAnimation15);1161 clearTimeout(currentAnimation16);1162 canMove = false;1163 return; 1164 } //if1165}// animateEnemy311661167// animate enemy left to right1168// boxes - array of grid boxes that include animation1169// index - current location of animation1170// direction - current direction of animation1171// enemy - type of enemy displayed1172function animateEnemy4(boxes, index, direction){///////////////////1173 1174 if(counter == 0){1175 currentLocationOfEnemy4 = enemyStart4;1176 } // if1177 1178 // exits function if no animation1179 if(boxes.length <= 0){ return;}1180 if(currentLevel == 1){ return;}1181 if(currentLevel == 2){ return;}1182 1183 // update the images1184 if(direction == "right"){1185 boxes[index].classList.add("enemy2right");1186 } else{1187 boxes[index].classList.add("enemy2left");1188 } //else1189 1190 // remove images from other boxes1191 for(i = 0; i < boxes.length; i++){1192 if(i != index){1193 boxes[i].classList.remove("enemy2left");1194 boxes[i].classList.remove("enemy2right");1195 } //if1196 } //for1197 1198 // moving right1199 if(direction == "right"){1200 if(counter >= 1){12011202 currentLocationOfEnemy4++;1203 } // if1204 1205 // turn around if hit right side of animation1206 if(index == boxes.length - 1){1207 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1208 index--;1209 direction = "left";1210 } else{1211 index++;1212 } //else1213 1214 // moving left1215 } else{1216 if(counter >= 1){12171218 currentLocationOfEnemy4--;1219 } //if 1220 1221 // turn around if hit left side of animation1222 if(index == 0){1223 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1224 index++;1225 direction = "right";1226 } else{1227 index--;1228 } //else1229 1230 }// else1231 12321233 currentAnimation4 = setTimeout(function(){1234 animateEnemy4(boxes, index, direction);1235 }, 750);1236 1237 //counter++;12381239 // if enemy runs into player, end the game12401241 if(currentLocationOfHorse == currentLocationOfEnemy4){1242 document.getElementById("lose").style.display = "block";1243 startLocation1 = originalLocation1;1244 startLocation2 = originalLocation2;1245 startLocation3 = originalLocation3;1246 clearTimeout(currentProjectile3);1247 clearTimeout(currentProjectile2);1248 clearTimeout(currentProjectile1);1249 clearTimeout(currentAnimation1);1250 clearTimeout(currentAnimation2);1251 clearTimeout(currentAnimation3);1252 clearTimeout(currentAnimation4);1253 clearTimeout(currentAnimation5);1254 clearTimeout(currentAnimation6);1255 clearTimeout(currentAnimation7);1256 clearTimeout(currentAnimation8);1257 clearTimeout(currentAnimation9);1258 clearTimeout(currentAnimation10);1259 clearTimeout(currentAnimation11);1260 clearTimeout(currentAnimation12);1261 clearTimeout(currentAnimation13);1262 clearTimeout(currentAnimation14);1263 clearTimeout(currentAnimation15);1264 clearTimeout(currentAnimation16);1265 canMove = false;1266 return; 1267 } //if1268}// animateEnemy412691270// animate enemy left to right1271// boxes - array of grid boxes that include animation1272// index - current location of animation1273// direction - current direction of animation1274// enemy - type of enemy displayed1275function animateEnemy5(boxes, index, direction){///////////////////1276 1277 if(counter == 0){1278 currentLocationOfEnemy5 = enemyStart5;1279 } // if1280 1281 // exits function if no animation1282 if(boxes.length <= 0){ return;}1283 if(currentLevel == 1){ return;}1284 if(currentLevel == 2){ return;}1285 1286 // update the images1287 if(direction == "right"){1288 boxes[index].classList.add("enemy2right");1289 } else if (direction == "left"){1290 boxes[index].classList.add("enemy2left");1291 } else if (direction == "up"){1292 boxes[index].classList.add("enemy2up");1293 } else if (direction == "down"){1294 boxes[index].classList.add("enemy2down");1295 } //else1296 1297 // remove images from other boxes1298 for(i = 0; i < boxes.length; i++){1299 if(i != index){1300 boxes[i].classList.remove("enemy2left");1301 boxes[i].classList.remove("enemy2right");1302 boxes[i].classList.remove("enemy2up");1303 boxes[i].classList.remove("enemy2down");1304 } //if1305 } //for1306 1307 // moving right1308 if(direction == "right"){1309 if(counter >= 1){13101311 currentLocationOfEnemy5++;1312 } // if1313 1314 // turn around if hit right side of animation1315 if(index == boxes.length - 1){1316 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1317 index--;1318 direction = "left";1319 } else{1320 index++;1321 } //else1322 1323 // moving left1324 } else if (direction == "left"){1325 if(counter >= 1){13261327 currentLocationOfEnemy5--;1328 } //if 1329 1330 // turn around if hit left side of animation1331 if(index == 0){1332 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1333 index++;1334 direction = "right";1335 } else{1336 index--;1337 } //else1338 1339 }else if (direction == "up"){1340 if(counter >= 1){1341 currentLocationOfEnemy5 = currentLocationOfEnemy5 - widthOfBoard;1342 } //if 1343 1344 // turn around if hit left side of animation1345 if(index == 0){1346 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1347 index++;1348 direction = "down";1349 } else{1350 index--;1351 1352 } //else1353 1354 } else if (direction == "down"){1355 if (counter >= 1){1356 currentLocationOfEnemy5 = currentLocationOfEnemy5 + widthOfBoard;1357 }1358 // turn around if hit left side of animation1359 if(index == boxes.length - 1){13601361 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1362 index--;1363 direction = "up";1364 } else{1365 index++;1366 } //else1367 1368 }// else136913701371 currentAnimation5 = setTimeout(function(){1372 animateEnemy5(boxes, index, direction);1373 }, 750);1374 1375 //counter++;13761377 // if enemy runs into player, end the game13781379 if(currentLocationOfHorse == currentLocationOfEnemy5){1380 document.getElementById("lose").style.display = "block";1381 startLocation1 = originalLocation1;1382 startLocation2 = originalLocation2;1383 startLocation3 = originalLocation3;1384 clearTimeout(currentProjectile3);1385 clearTimeout(currentProjectile2);1386 clearTimeout(currentProjectile1);1387 clearTimeout(currentAnimation1);1388 clearTimeout(currentAnimation2);1389 clearTimeout(currentAnimation3);1390 clearTimeout(currentAnimation4);1391 clearTimeout(currentAnimation5);1392 clearTimeout(currentAnimation6);1393 clearTimeout(currentAnimation7);1394 clearTimeout(currentAnimation8);1395 clearTimeout(currentAnimation9);1396 clearTimeout(currentAnimation10);1397 clearTimeout(currentAnimation11);1398 clearTimeout(currentAnimation12);1399 clearTimeout(currentAnimation13);1400 clearTimeout(currentAnimation14);1401 clearTimeout(currentAnimation15);1402 clearTimeout(currentAnimation16);1403 canMove = false;1404 return; 1405 } //if1406}// animateEnemy514071408// animate enemy left to right1409// boxes - array of grid boxes that include animation1410// index - current location of animation1411// direction - current direction of animation1412// enemy - type of enemy displayed1413function animateEnemy6(boxes, index, direction){///////////////////1414 1415 if(counter == 0){1416 currentLocationOfEnemy6 = enemyStart6;1417 } // if1418 1419 // exits function if no animation1420 if(boxes.length <= 0){ return;}1421 if(currentLevel == 2){ return;}1422 if(currentLevel == 0){ return;}1423 // update the images1424 if(direction == "right"){1425 boxes[index].classList.add("enemy2right");1426 } else if (direction == "left"){1427 boxes[index].classList.add("enemy2left");1428 } else if (direction == "up"){1429 boxes[index].classList.add("enemy2up");1430 } else if (direction == "down"){1431 boxes[index].classList.add("enemy2down");1432 } //else1433 1434 // remove images from other boxes1435 for(i = 0; i < boxes.length; i++){1436 if(i != index){1437 boxes[i].classList.remove("enemy2left");1438 boxes[i].classList.remove("enemy2right");1439 boxes[i].classList.remove("enemy2up");1440 boxes[i].classList.remove("enemy2down");1441 } //if1442 } //for1443 1444 // moving right1445 if(direction == "right"){1446 if(counter >= 1){1447 currentLocationOfEnemy6++;1448 } // if1449 1450 // turn around if hit right side of animation1451 if(index == boxes.length - 1){1452 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1453 index--;1454 direction = "left";1455 } else{1456 index++;1457 } //else1458 1459 // moving left1460 } else if (direction == "left"){1461 if(counter >= 1){14621463 currentLocationOfEnemy6--;1464 } //if 1465 1466 // turn around if hit left side of animation1467 if(index == 0){1468 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1469 index++;1470 direction = "right";1471 } else{1472 index--;1473 } //else1474 1475 }else if (direction == "up"){1476 if(counter >= 1){1477 currentLocationOfEnemy6 = currentLocationOfEnemy6 - widthOfBoard;1478 1479 } //if 1480 1481 // turn around if hit left side of animation1482 if(index == 0){1483 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1484 direction = "down";1485 index++;1486 1487 } else{1488 index--;1489 1490 } //else1491 1492 } else if (direction == "down"){1493 if (counter >= 1){1494 currentLocationOfEnemy6 = currentLocationOfEnemy6 + widthOfBoard;1495 1496 }1497 // turn around if hit left side of animation1498 if(index == boxes.length - 1){1499 direction = "up";1500 index--;1501 1502 } else{1503 index++;1504 } //else1505 1506 }// else15071508 // if enemy runs into player, end the game15091510 if(currentLocationOfHorse == currentLocationOfEnemy6){1511 document.getElementById("lose").style.display = "block";1512 startLocation1 = originalLocation1;1513 startLocation2 = originalLocation2;1514 startLocation3 = originalLocation3;1515 clearTimeout(currentProjectile3);1516 clearTimeout(currentProjectile2);1517 clearTimeout(currentProjectile1);1518 clearTimeout(currentAnimation1);1519 clearTimeout(currentAnimation2);1520 clearTimeout(currentAnimation3);1521 clearTimeout(currentAnimation4);1522 clearTimeout(currentAnimation5);1523 clearTimeout(currentAnimation6);1524 clearTimeout(currentAnimation7);1525 clearTimeout(currentAnimation8);1526 clearTimeout(currentAnimation9);1527 clearTimeout(currentAnimation10);1528 clearTimeout(currentAnimation11);1529 clearTimeout(currentAnimation12);1530 clearTimeout(currentAnimation13);1531 clearTimeout(currentAnimation14);1532 clearTimeout(currentAnimation15);1533 clearTimeout(currentAnimation16);1534 canMove = false;1535 return; 1536 } //if 153715381539 currentAnimation6 = setTimeout(function(){1540 counter++;1541 animateEnemy6(boxes, index, direction);1542 }, 750);1543 1544 //counter++;154515461547}// animateEnemy615481549// animate enemy left to right1550// boxes - array of grid boxes that include animation1551// index - current location of animation1552// direction - current direction of animation1553// enemy - type of enemy displayed1554function animateEnemy7(boxes, index, direction){///////////////////1555 1556 if(counter == 0){1557 currentLocationOfEnemy7 = enemyStart7;1558 } // if1559 1560 // exits function if no animation1561 if(boxes.length <= 0){ return;}1562 if(currentLevel == 2){ return;}1563 if(currentLevel == 0){ return;}1564 1565 // update the images1566 if(direction == "right"){1567 boxes[index].classList.add("enemy2right");1568 } else if (direction == "left"){1569 boxes[index].classList.add("enemy2left");1570 } else if (direction == "up"){1571 boxes[index].classList.add("enemy2up");1572 } else if (direction == "down"){1573 boxes[index].classList.add("enemy2down");1574 } //else1575 1576 // remove images from other boxes1577 for(i = 0; i < boxes.length; i++){1578 if(i != index){1579 boxes[i].classList.remove("enemy2left");1580 boxes[i].classList.remove("enemy2right");1581 boxes[i].classList.remove("enemy2up");1582 boxes[i].classList.remove("enemy2down");1583 } //if1584 } //for1585 1586 // moving right1587 if(direction == "right"){1588 if(counter >= 1){15891590 currentLocationOfEnemy7++;1591 } // if1592 1593 // turn around if hit right side of animation1594 if(index == boxes.length - 1){1595 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1596 index--;1597 direction = "left";1598 } else{1599 index++;1600 } //else1601 1602 // moving left1603 } else if (direction == "left"){1604 if(counter >= 1){16051606 currentLocationOfEnemy7--;1607 } //if 1608 1609 // turn around if hit left side of animation1610 if(index == 0){1611 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1612 index++;1613 direction = "right";1614 } else{1615 index--;1616 } //else1617 1618 }else if (direction == "up"){1619 if(counter >= 1){1620 currentLocationOfEnemy7 = currentLocationOfEnemy7 - widthOfBoard;1621 } //if 1622 1623 // turn around if hit left side of animation1624 if(index == 0){1625 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1626 index++;1627 direction = "down";1628 } else{1629 index--;1630 1631 } //else1632 1633 } else if (direction == "down"){1634 if (counter >= 1){1635 currentLocationOfEnemy7 = currentLocationOfEnemy7 + widthOfBoard;1636 }1637 // turn around if hit left side of animation1638 if(index == boxes.length - 1){16391640 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1641 index--;1642 direction = "up";1643 } else{1644 index++;1645 } //else1646 1647 }// else16481649165016511652 currentAnimation7 = setTimeout(function(){1653 animateEnemy7(boxes, index, direction);1654 }, 750);1655 1656 //counter++;16571658 // if enemy runs into player, end the game16591660 if(currentLocationOfHorse == currentLocationOfEnemy7){1661 document.getElementById("lose").style.display = "block";1662 startLocation1 = originalLocation1;1663 startLocation2 = originalLocation2;1664 startLocation3 = originalLocation3;1665 clearTimeout(currentProjectile3);1666 clearTimeout(currentProjectile2);1667 clearTimeout(currentProjectile1);1668 clearTimeout(currentAnimation1);1669 clearTimeout(currentAnimation2);1670 clearTimeout(currentAnimation3);1671 clearTimeout(currentAnimation4);1672 clearTimeout(currentAnimation5);1673 clearTimeout(currentAnimation6);1674 clearTimeout(currentAnimation7);1675 clearTimeout(currentAnimation8);1676 clearTimeout(currentAnimation9);1677 clearTimeout(currentAnimation10);1678 clearTimeout(currentAnimation11);1679 clearTimeout(currentAnimation12);1680 clearTimeout(currentAnimation13);1681 clearTimeout(currentAnimation14);1682 clearTimeout(currentAnimation15);1683 clearTimeout(currentAnimation16);1684 canMove = false;1685 return; 1686 } //if1687}// animateEnemy716881689// animate enemy left to right1690// boxes - array of grid boxes that include animation1691// index - current location of animation1692// direction - current direction of animation1693// enemy - type of enemy displayed1694function animateEnemy8(boxes, index, direction){///////////////////1695 1696 if(counter == 0){1697 currentLocationOfEnemy8 = enemyStart8;1698 } // if1699 1700 // exits function if no animation1701 if(boxes.length <= 0){ return;}1702 if(currentLevel == 2){ return;}1703 if(currentLevel == 0){ return;}1704 // update the images1705 if(direction == "right"){1706 boxes[index].classList.add("enemy2right");1707 } else if (direction == "left"){1708 boxes[index].classList.add("enemy2left");1709 } else if (direction == "up"){1710 boxes[index].classList.add("enemy2up");1711 } else if (direction == "down"){1712 boxes[index].classList.add("enemy2down");1713 } //else1714 1715 // remove images from other boxes1716 for(i = 0; i < boxes.length; i++){1717 if(i != index){1718 boxes[i].classList.remove("enemy2left");1719 boxes[i].classList.remove("enemy2right");1720 boxes[i].classList.remove("enemy2up");1721 boxes[i].classList.remove("enemy2down");1722 } //if1723 } //for1724 1725 // moving right1726 if(direction == "right"){1727 if(counter >= 1){17281729 currentLocationOfEnemy8++;1730 } // if1731 1732 // turn around if hit right side of animation1733 if(index == boxes.length - 1){1734 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1735 index--;1736 direction = "left";1737 } else{1738 index++;1739 } //else1740 1741 // moving left1742 } else if (direction == "left"){1743 if(counter >= 1){17441745 currentLocationOfEnemy8--;1746 } //if 1747 1748 // turn around if hit left side of animation1749 if(index == 0){1750 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1751 index++;1752 direction = "right";1753 } else{1754 index--;1755 } //else1756 1757 }else if (direction == "up"){1758 if(counter >= 1){1759 currentLocationOfEnemy8 = currentLocationOfEnemy8 - widthOfBoard;1760 } //if 1761 1762 // turn around if hit left side of animation1763 if(index == 0){1764 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1765 index++;1766 direction = "down";1767 } else{1768 index--;1769 1770 } //else1771 1772 } else if (direction == "down"){1773 if (counter >= 1){1774 currentLocationOfEnemy8 = currentLocationOfEnemy8 + widthOfBoard;1775 }1776 // turn around if hit left side of animation1777 if(index == boxes.length - 1){17781779 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1780 index--;1781 direction = "up";1782 } else{1783 index++;1784 } //else1785 1786 }// else17871788 1789 currentAnimation8 = setTimeout(function(){1790 animateEnemy8(boxes, index, direction);1791 }, 750);1792 1793 //counter++;17941795 // if enemy runs into player, end the game17961797 if(currentLocationOfHorse == currentLocationOfEnemy8){1798 document.getElementById("lose").style.display = "block";1799 startLocation1 = originalLocation1;1800 startLocation2 = originalLocation2;1801 startLocation3 = originalLocation3;1802 clearTimeout(currentProjectile3);1803 clearTimeout(currentProjectile2);1804 clearTimeout(currentProjectile1);1805 clearTimeout(currentAnimation1);1806 clearTimeout(currentAnimation2);1807 clearTimeout(currentAnimation3);1808 clearTimeout(currentAnimation4);1809 clearTimeout(currentAnimation5);1810 clearTimeout(currentAnimation6);1811 clearTimeout(currentAnimation7);1812 clearTimeout(currentAnimation8);1813 clearTimeout(currentAnimation9);1814 clearTimeout(currentAnimation10);1815 clearTimeout(currentAnimation11);1816 clearTimeout(currentAnimation12);1817 clearTimeout(currentAnimation13);1818 clearTimeout(currentAnimation14);1819 clearTimeout(currentAnimation15);1820 clearTimeout(currentAnimation16);1821 canMove = false;1822 return; 1823 } //if1824}// animateEnemy818251826// animate enemy left to right1827// boxes - array of grid boxes that include animation1828// index - current location of animation1829// direction - current direction of animation1830// enemy - type of enemy displayed1831function animateEnemy9(boxes, index, direction){///////////////////1832 1833 if(counter == 0){1834 currentLocationOfEnemy9 = enemyStart9;1835 } // if1836 1837 // exits function if no animation1838 if(boxes.length <= 0){ return;}1839 if(currentLevel == 2){ return;}1840 if(currentLevel == 0){ return;}1841 // update the images1842 if(direction == "right"){1843 boxes[index].classList.add("enemy2right");1844 } else if (direction == "left"){1845 boxes[index].classList.add("enemy2left");1846 } else if (direction == "up"){1847 boxes[index].classList.add("enemy2up");1848 } else if (direction == "down"){1849 boxes[index].classList.add("enemy2down");1850 } //else1851 1852 // remove images from other boxes1853 for(i = 0; i < boxes.length; i++){1854 if(i != index){1855 boxes[i].classList.remove("enemy2left");1856 boxes[i].classList.remove("enemy2right");1857 boxes[i].classList.remove("enemy2up");1858 boxes[i].classList.remove("enemy2down");1859 } //if1860 } //for1861 1862 // moving right1863 if(direction == "right"){1864 if(counter >= 1){18651866 currentLocationOfEnemy9++;1867 } // if1868 1869 // turn around if hit right side of animation1870 if(index == boxes.length - 1){1871 //currentLocationOfEnemy = currentLocationOfEnemy + 1;1872 index--;1873 direction = "left";1874 } else{1875 index++;1876 } //else1877 1878 // moving left1879 } else if (direction == "left"){1880 if(counter >= 1){18811882 currentLocationOfEnemy9--;1883 } //if 1884 1885 // turn around if hit left side of animation1886 if(index == 0){1887 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1888 index++;1889 direction = "right";1890 } else{1891 index--;1892 } //else1893 1894 }else if (direction == "up"){1895 if(counter >= 1){1896 currentLocationOfEnemy9 = currentLocationOfEnemy9 - widthOfBoard;1897 } //if 1898 1899 // turn around if hit left side of animation1900 if(index == 0){1901 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1902 index++;1903 direction = "down";1904 } else{1905 index--;1906 1907 } //else1908 1909 } else if (direction == "down"){1910 if (counter >= 1){1911 currentLocationOfEnemy9 = currentLocationOfEnemy9 + widthOfBoard;1912 }1913 // turn around if hit left side of animation1914 if(index == boxes.length - 1){19151916 // currentLocationOfEnemy = currentLocationOfEnemy - 1;1917 index--;1918 direction = "up";1919 } else{1920 index++;1921 } //else1922 1923 }// else19241925 currentAnimation9 = setTimeout(function(){1926 animateEnemy9(boxes, index, direction);1927 }, 750);1928 1929 //counter++;19301931 // if enemy runs into player, end the game19321933 if(currentLocationOfHorse == currentLocationOfEnemy9){1934 document.getElementById("lose").style.display = "block";1935 startLocation1 = originalLocation1;1936 startLocation2 = originalLocation2;1937 startLocation3 = originalLocation3;1938 clearTimeout(currentProjectile3);1939 clearTimeout(currentProjectile2);1940 clearTimeout(currentProjectile1);1941 clearTimeout(currentAnimation1);1942 clearTimeout(currentAnimation2);1943 clearTimeout(currentAnimation3);1944 clearTimeout(currentAnimation4);1945 clearTimeout(currentAnimation5);1946 clearTimeout(currentAnimation6);1947 clearTimeout(currentAnimation7);1948 clearTimeout(currentAnimation8);1949 clearTimeout(currentAnimation9);1950 clearTimeout(currentAnimation10);1951 clearTimeout(currentAnimation11);1952 clearTimeout(currentAnimation12);1953 clearTimeout(currentAnimation13);1954 clearTimeout(currentAnimation14);1955 clearTimeout(currentAnimation15);1956 clearTimeout(currentAnimation16);1957 canMove = false;1958 return; 1959 } //if1960}// animateEnemy919611962// animate enemy left to right1963// boxes - array of grid boxes that include animation1964// index - current location of animation1965// direction - current direction of animation1966// enemy - type of enemy displayed1967function animateEnemy10(boxes, index, direction){///////////////////1968 1969 if(counter == 0){1970 currentLocationOfEnemy10 = enemyStart10;1971 } // if1972 1973 // exits function if no animation1974 if(boxes.length <= 0){ return;}1975 if(currentLevel == 2){ return;}1976 if(currentLevel == 0){ return;}1977 // update the images1978 if(direction == "right"){1979 boxes[index].classList.add("enemy2right");1980 } else if (direction == "left"){1981 boxes[index].classList.add("enemy2left");1982 } else if (direction == "up"){1983 boxes[index].classList.add("enemy2up");1984 } else if (direction == "down"){1985 boxes[index].classList.add("enemy2down");1986 } //else1987 1988 // remove images from other boxes1989 for(i = 0; i < boxes.length; i++){1990 if(i != index){1991 boxes[i].classList.remove("enemy2left");1992 boxes[i].classList.remove("enemy2right");1993 boxes[i].classList.remove("enemy2up");1994 boxes[i].classList.remove("enemy2down");1995 } //if1996 } //for1997 1998 // moving right1999 if(direction == "right"){2000 if(counter >= 1){20012002 currentLocationOfEnemy10++;2003 } // if2004 2005 // turn around if hit right side of animation2006 if(index == boxes.length - 1){2007 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2008 index--;2009 direction = "left";2010 } else{2011 index++;2012 } //else2013 2014 // moving left2015 } else if (direction == "left"){2016 if(counter >= 1){20172018 currentLocationOfEnemy10--;2019 } //if 2020 2021 // turn around if hit left side of animation2022 if(index == 0){2023 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2024 index++;2025 direction = "right";2026 } else{2027 index--;2028 } //else2029 2030 }else if (direction == "up"){2031 if(counter >= 1){2032 currentLocationOfEnemy10 = currentLocationOfEnemy10 - widthOfBoard;2033 } //if 2034 2035 // turn around if hit left side of animation2036 if(index == 0){2037 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2038 index++;2039 direction = "down";2040 } else{2041 index--;2042 2043 } //else2044 2045 } else if (direction == "down"){2046 if (counter >= 1){2047 currentLocationOfEnemy10 = currentLocationOfEnemy10 + widthOfBoard;2048 }2049 // turn around if hit left side of animation2050 if(index == boxes.length - 1){20512052 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2053 index--;2054 direction = "up";2055 } else{2056 index++;2057 } //else2058 2059 }// else206020612062 currentAnimation10 = setTimeout(function(){2063 animateEnemy10(boxes, index, direction);2064 }, 750);2065 2066 //counter++;20672068 // if enemy runs into player, end the game20692070 if(currentLocationOfHorse == currentLocationOfEnemy10){2071 document.getElementById("lose").style.display = "block";2072 startLocation1 = originalLocation1;2073 startLocation2 = originalLocation2;2074 startLocation3 = originalLocation3;2075 clearTimeout(currentProjectile3);2076 clearTimeout(currentProjectile2);2077 clearTimeout(currentProjectile1);2078 clearTimeout(currentAnimation1);2079 clearTimeout(currentAnimation2);2080 clearTimeout(currentAnimation3);2081 clearTimeout(currentAnimation4);2082 clearTimeout(currentAnimation5);2083 clearTimeout(currentAnimation6);2084 clearTimeout(currentAnimation7);2085 clearTimeout(currentAnimation8);2086 clearTimeout(currentAnimation9);2087 clearTimeout(currentAnimation10);2088 clearTimeout(currentAnimation11);2089 clearTimeout(currentAnimation12);2090 clearTimeout(currentAnimation13);2091 clearTimeout(currentAnimation14);2092 clearTimeout(currentAnimation15);2093 clearTimeout(currentAnimation16);2094 canMove = false;2095 return; 2096 } //if2097}// animateEnemy1020982099// animate enemy left to right2100// boxes - array of grid boxes that include animation2101// index - current location of animation2102// direction - current direction of animation2103// enemy - type of enemy displayed2104function animateEnemy11(boxes, index, direction){///////////////////2105 2106 if(counter == 0){2107 currentLocationOfEnemy11 = enemyStart11;2108 } // if2109 2110 // exits function if no animation2111 if(boxes.length <= 0){ return;}2112 if(currentLevel == 0){ return;}2113 if(currentLevel == 1){ return;}2114 2115 // update the images2116 if(direction == "right"){2117 boxes[index].classList.add("enemy2right");2118 } else if (direction == "left"){2119 boxes[index].classList.add("enemy2left");2120 } else if (direction == "up"){2121 boxes[index].classList.add("enemy2up");2122 } else if (direction == "down"){2123 boxes[index].classList.add("enemy2down");2124 } //else2125 2126 // remove images from other boxes2127 for(i = 0; i < boxes.length; i++){2128 if(i != index){2129 boxes[i].classList.remove("enemy2left");2130 boxes[i].classList.remove("enemy2right");2131 boxes[i].classList.remove("enemy2up");2132 boxes[i].classList.remove("enemy2down");2133 } //if2134 } //for2135 2136 // moving right2137 if(direction == "right"){2138 if(counter >= 1){21392140 currentLocationOfEnemy11++;2141 } // if2142 2143 // turn around if hit right side of animation2144 if(index == boxes.length - 1){2145 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2146 index--;2147 direction = "left";2148 } else{2149 index++;2150 } //else2151 2152 // moving left2153 } else if (direction == "left"){2154 if(counter >= 1){21552156 currentLocationOfEnemy11--;2157 } //if 2158 2159 // turn around if hit left side of animation2160 if(index == 0){2161 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2162 index++;2163 direction = "right";2164 } else{2165 index--;2166 } //else2167 2168 }else if (direction == "up"){2169 if(counter >= 1){2170 currentLocationOfEnemy11 = currentLocationOfEnemy11 - widthOfBoard;2171 } //if 2172 2173 // turn around if hit left side of animation2174 if(index == 0){2175 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2176 index++;2177 direction = "down";2178 } else{2179 index--;2180 2181 } //else2182 2183 } else if (direction == "down"){2184 if (counter >= 1){2185 currentLocationOfEnemy11 = currentLocationOfEnemy11 + widthOfBoard;2186 }2187 // turn around if hit left side of animation2188 if(index == boxes.length - 1){21892190 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2191 index--;2192 direction = "up";2193 } else{2194 index++;2195 } //else2196 2197 }// else21982199 22002201counter++;2202 currentAnimation11 = setTimeout(function(){2203 animateEnemy11(boxes, index, direction);2204 }, 750);2205 2206 //counter++;22072208 // if enemy runs into player, end the game22092210 if(currentLocationOfHorse == currentLocationOfEnemy11){2211 document.getElementById("lose").style.display = "block";2212 startLocation1 = originalLocation1;2213 startLocation2 = originalLocation2;2214 startLocation3 = originalLocation3;2215 clearTimeout(currentProjectile3);2216 clearTimeout(currentProjectile2);2217 clearTimeout(currentProjectile1);2218 clearTimeout(currentAnimation1);2219 clearTimeout(currentAnimation2);2220 clearTimeout(currentAnimation3);2221 clearTimeout(currentAnimation4);2222 clearTimeout(currentAnimation5);2223 clearTimeout(currentAnimation6);2224 clearTimeout(currentAnimation7);2225 clearTimeout(currentAnimation8);2226 clearTimeout(currentAnimation9);2227 clearTimeout(currentAnimation10);2228 clearTimeout(currentAnimation11);2229 clearTimeout(currentAnimation12);2230 clearTimeout(currentAnimation13);2231 clearTimeout(currentAnimation14);2232 clearTimeout(currentAnimation15);2233 clearTimeout(currentAnimation16);2234 canMove = false;2235 return; 2236 } //if2237}// animateEnemy1122382239// animate enemy left to right2240// boxes - array of grid boxes that include animation2241// index - current location of animation2242// direction - current direction of animation2243// enemy - type of enemy displayed2244function animateEnemy12(boxes, index, direction){///////////////////2245 2246 if(counter == 0){2247 currentLocationOfEnemy12 = enemyStart12;2248 } // if2249 2250 // exits function if no animation2251 if(boxes.length <= 0){ return;}2252 if(currentLevel == 0){ return;}2253 if(currentLevel == 1){ return;}2254 2255 // update the images2256 if(direction == "right"){2257 boxes[index].classList.add("enemy2right");2258 } else if (direction == "left"){2259 boxes[index].classList.add("enemy2left");2260 } else if (direction == "up"){2261 boxes[index].classList.add("enemy2up");2262 } else if (direction == "down"){2263 boxes[index].classList.add("enemy2down");2264 } //else2265 2266 // remove images from other boxes2267 for(i = 0; i < boxes.length; i++){2268 if(i != index){2269 boxes[i].classList.remove("enemy2left");2270 boxes[i].classList.remove("enemy2right");2271 boxes[i].classList.remove("enemy2up");2272 boxes[i].classList.remove("enemy2down");2273 } //if2274 } //for2275 2276 // moving right2277 if(direction == "right"){2278 if(counter >= 1){22792280 currentLocationOfEnemy12++;2281 } // if2282 2283 // turn around if hit right side of animation2284 if(index == boxes.length - 1){2285 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2286 index--;2287 direction = "left";2288 } else{2289 index++;2290 } //else2291 2292 // moving left2293 } else if (direction == "left"){2294 if(counter >= 1){22952296 currentLocationOfEnemy12--;2297 } //if 2298 2299 // turn around if hit left side of animation2300 if(index == 0){2301 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2302 index++;2303 direction = "right";2304 } else{2305 index--;2306 } //else2307 2308 }else if (direction == "up"){2309 if(counter >= 1){2310 currentLocationOfEnemy12 = currentLocationOfEnemy12 - widthOfBoard;2311 } //if 2312 2313 // turn around if hit left side of animation2314 if(index == 0){2315 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2316 index++;2317 direction = "down";2318 } else{2319 index--;2320 2321 } //else2322 2323 } else if (direction == "down"){2324 if (counter >= 1){2325 currentLocationOfEnemy12 = currentLocationOfEnemy12 + widthOfBoard;2326 }2327 // turn around if hit left side of animation2328 if(index == boxes.length - 1){23292330 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2331 index--;2332 direction = "up";2333 } else{2334 index++;2335 } //else2336 2337 }// else23382339 234023412342 currentAnimation12 = setTimeout(function(){2343 animateEnemy12(boxes, index, direction);2344 }, 750);2345 2346 //counter++;23472348 // if enemy runs into player, end the game23492350 if(currentLocationOfHorse == currentLocationOfEnemy12){2351 document.getElementById("lose").style.display = "block";2352 startLocation1 = originalLocation1;2353 startLocation2 = originalLocation2;2354 startLocation3 = originalLocation3;2355 clearTimeout(currentProjectile3);2356 clearTimeout(currentProjectile2);2357 clearTimeout(currentProjectile1);2358 clearTimeout(currentAnimation1);2359 clearTimeout(currentAnimation2);2360 clearTimeout(currentAnimation3);2361 clearTimeout(currentAnimation4);2362 clearTimeout(currentAnimation5);2363 clearTimeout(currentAnimation6);2364 clearTimeout(currentAnimation7);2365 clearTimeout(currentAnimation8);2366 clearTimeout(currentAnimation9);2367 clearTimeout(currentAnimation10);2368 clearTimeout(currentAnimation11);2369 clearTimeout(currentAnimation12);2370 clearTimeout(currentAnimation13);2371 clearTimeout(currentAnimation14);2372 clearTimeout(currentAnimation15);2373 clearTimeout(currentAnimation16);2374 canMove = false;2375 return; 2376 } //if2377}// animateEnemy1223782379// animate enemy left to right2380// boxes - array of grid boxes that include animation2381// index - current location of animation2382// direction - current direction of animation2383// enemy - type of enemy displayed2384function animateEnemy13(boxes, index, direction){///////////////////2385 2386 if(counter == 0){2387 currentLocationOfEnemy13 = enemyStart13;2388 } // if2389 2390 // exits function if no animation2391 if(boxes.length <= 0){ return;}2392 if(currentLevel == 0){ return;}2393 if(currentLevel == 1){ return;}2394 2395 // update the images2396 if(direction == "right"){2397 boxes[index].classList.add("enemy2right");2398 } else if (direction == "left"){2399 boxes[index].classList.add("enemy2left");2400 } else if (direction == "up"){2401 boxes[index].classList.add("enemy2up");2402 } else if (direction == "down"){2403 boxes[index].classList.add("enemy2down");2404 } //else2405 2406 // remove images from other boxes2407 for(i = 0; i < boxes.length; i++){2408 if(i != index){2409 boxes[i].classList.remove("enemy2left");2410 boxes[i].classList.remove("enemy2right");2411 boxes[i].classList.remove("enemy2up");2412 boxes[i].classList.remove("enemy2down");2413 } //if2414 } //for2415 2416 // moving right2417 if(direction == "right"){2418 if(counter >= 1){24192420 currentLocationOfEnemy13++;2421 } // if2422 2423 // turn around if hit right side of animation2424 if(index == boxes.length - 1){2425 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2426 index--;2427 direction = "left";2428 } else{2429 index++;2430 } //else2431 2432 // moving left2433 } else if (direction == "left"){2434 if(counter >= 1){24352436 currentLocationOfEnemy13--;2437 } //if 2438 2439 // turn around if hit left side of animation2440 if(index == 0){2441 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2442 index++;2443 direction = "right";2444 } else{2445 index--;2446 } //else2447 2448 }else if (direction == "up"){2449 if(counter >= 1){2450 currentLocationOfEnemy13 = currentLocationOfEnemy13 - widthOfBoard;2451 } //if 2452 2453 // turn around if hit left side of animation2454 if(index == 0){2455 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2456 index++;2457 direction = "down";2458 } else{2459 index--;2460 2461 } //else2462 2463 } else if (direction == "down"){2464 if (counter >= 1){2465 currentLocationOfEnemy13 = currentLocationOfEnemy13 + widthOfBoard;2466 }2467 // turn around if hit left side of animation2468 if(index == boxes.length - 1){24692470 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2471 index--;2472 direction = "up";2473 } else{2474 index++;2475 } //else2476 2477 }// else24782479 248024812482 currentAnimation13 = setTimeout(function(){2483 animateEnemy13(boxes, index, direction);2484 }, 750);2485 2486 //counter++;24872488 // if enemy runs into player, end the game24892490 if(currentLocationOfHorse == currentLocationOfEnemy13){2491 document.getElementById("lose").style.display = "block";2492 startLocation1 = originalLocation1;2493 startLocation2 = originalLocation2;2494 startLocation3 = originalLocation3;2495 clearTimeout(currentProjectile3);2496 clearTimeout(currentProjectile2);2497 clearTimeout(currentProjectile1);2498 clearTimeout(currentAnimation1);2499 clearTimeout(currentAnimation2);2500 clearTimeout(currentAnimation3);2501 clearTimeout(currentAnimation4);2502 clearTimeout(currentAnimation5);2503 clearTimeout(currentAnimation6);2504 clearTimeout(currentAnimation7);2505 clearTimeout(currentAnimation8);2506 clearTimeout(currentAnimation9);2507 clearTimeout(currentAnimation10);2508 clearTimeout(currentAnimation11);2509 clearTimeout(currentAnimation12);2510 clearTimeout(currentAnimation13);2511 clearTimeout(currentAnimation14);2512 clearTimeout(currentAnimation15);2513 clearTimeout(currentAnimation16);2514 canMove = false;2515 return; 2516 } //if2517}// animateEnemy1325182519// animate enemy left to right2520// boxes - array of grid boxes that include animation2521// index - current location of animation2522// direction - current direction of animation2523// enemy - type of enemy displayed2524function animateEnemy14(boxes, index, direction){///////////////////2525 2526 if(counter == 0){2527 currentLocationOfEnemy14 = enemyStart14;2528 } // if2529 2530 // exits function if no animation2531 if(boxes.length <= 0){ return;}2532 if(currentLevel == 0){ return;}2533 if(currentLevel == 1){ return;}2534 2535 // update the images2536 if(direction == "right"){2537 boxes[index].classList.add("enemy2right");2538 } else if (direction == "left"){2539 boxes[index].classList.add("enemy2left");2540 } else if (direction == "up"){2541 boxes[index].classList.add("enemy2up");2542 } else if (direction == "down"){2543 boxes[index].classList.add("enemy2down");2544 } //else2545 2546 // remove images from other boxes2547 for(i = 0; i < boxes.length; i++){2548 if(i != index){2549 boxes[i].classList.remove("enemy2left");2550 boxes[i].classList.remove("enemy2right");2551 boxes[i].classList.remove("enemy2up");2552 boxes[i].classList.remove("enemy2down");2553 } //if2554 } //for2555 2556 // moving right2557 if(direction == "right"){2558 if(counter >= 1){25592560 currentLocationOfEnemy14++;2561 } // if2562 2563 // turn around if hit right side of animation2564 if(index == boxes.length - 1){2565 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2566 index--;2567 direction = "left";2568 } else{2569 index++;2570 } //else2571 2572 // moving left2573 } else if (direction == "left"){2574 if(counter >= 1){25752576 currentLocationOfEnemy14--;2577 } //if 2578 2579 // turn around if hit left side of animation2580 if(index == 0){2581 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2582 index++;2583 direction = "right";2584 } else{2585 index--;2586 } //else2587 2588 }else if (direction == "up"){2589 if(counter >= 1){2590 currentLocationOfEnemy14 = currentLocationOfEnemy14 - widthOfBoard;2591 } //if 2592 2593 // turn around if hit left side of animation2594 if(index == 0){2595 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2596 index++;2597 direction = "down";2598 } else{2599 index--;2600 2601 } //else2602 2603 } else if (direction == "down"){2604 if (counter >= 1){2605 currentLocationOfEnemy14 = currentLocationOfEnemy14 + widthOfBoard;2606 }2607 // turn around if hit left side of animation2608 if(index == boxes.length - 1){26092610 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2611 index--;2612 direction = "up";2613 } else{2614 index++;2615 } //else2616 2617 }// else26182619 262026212622 currentAnimation14 = setTimeout(function(){2623 animateEnemy14(boxes, index, direction);2624 }, 750);2625 2626 //counter++;26272628 // if enemy runs into player, end the game26292630 if(currentLocationOfHorse == currentLocationOfEnemy14){2631 document.getElementById("lose").style.display = "block";2632 startLocation1 = originalLocation1;2633 startLocation2 = originalLocation2;2634 startLocation3 = originalLocation3;2635 clearTimeout(currentProjectile3);2636 clearTimeout(currentProjectile2);2637 clearTimeout(currentProjectile1);2638 clearTimeout(currentAnimation1);2639 clearTimeout(currentAnimation2);2640 clearTimeout(currentAnimation3);2641 clearTimeout(currentAnimation4);2642 clearTimeout(currentAnimation5);2643 clearTimeout(currentAnimation6);2644 clearTimeout(currentAnimation7);2645 clearTimeout(currentAnimation8);2646 clearTimeout(currentAnimation9);2647 clearTimeout(currentAnimation10);2648 clearTimeout(currentAnimation11);2649 clearTimeout(currentAnimation12);2650 clearTimeout(currentAnimation13);2651 clearTimeout(currentAnimation14);2652 clearTimeout(currentAnimation15);2653 clearTimeout(currentAnimation16);2654 canMove = false;2655 return; 2656 } //if2657}// animateEnemy1426582659// animate enemy left to right2660// boxes - array of grid boxes that include animation2661// index - current location of animation2662// direction - current direction of animation2663// enemy - type of enemy displayed2664function animateEnemy15(boxes, index, direction){///////////////////2665 2666 if(counter == 0){2667 currentLocationOfEnemy15 = enemyStart15;2668 } // if2669 2670 // exits function if no animation2671 if(boxes.length <= 0){ return;}2672 if(currentLevel == 0){ return;}2673 if(currentLevel == 1){ return;}2674 2675 // update the images2676 if(direction == "right"){2677 boxes[index].classList.add("enemy2right");2678 } else if (direction == "left"){2679 boxes[index].classList.add("enemy2left");2680 } else if (direction == "up"){2681 boxes[index].classList.add("enemy2up");2682 } else if (direction == "down"){2683 boxes[index].classList.add("enemy2down");2684 } //else2685 2686 // remove images from other boxes2687 for(i = 0; i < boxes.length; i++){2688 if(i != index){2689 boxes[i].classList.remove("enemy2left");2690 boxes[i].classList.remove("enemy2right");2691 boxes[i].classList.remove("enemy2up");2692 boxes[i].classList.remove("enemy2down");2693 } //if2694 } //for2695 2696 // moving right2697 if(direction == "right"){2698 if(counter >= 1){26992700 currentLocationOfEnemy15++;2701 } // if2702 2703 // turn around if hit right side of animation2704 if(index == boxes.length - 1){2705 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2706 index--;2707 direction = "left";2708 } else{2709 index++;2710 } //else2711 2712 // moving left2713 } else if (direction == "left"){2714 if(counter >= 1){27152716 currentLocationOfEnemy15--;2717 } //if 2718 2719 // turn around if hit left side of animation2720 if(index == 0){2721 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2722 index++;2723 direction = "right";2724 } else{2725 index--;2726 } //else2727 2728 }else if (direction == "up"){2729 if(counter >= 1){2730 currentLocationOfEnemy15 = currentLocationOfEnemy15 - widthOfBoard;2731 } //if 2732 2733 // turn around if hit left side of animation2734 if(index == 0){2735 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2736 index++;2737 direction = "down";2738 } else{2739 index--;2740 2741 } //else2742 2743 } else if (direction == "down"){2744 if (counter >= 1){2745 currentLocationOfEnemy15 = currentLocationOfEnemy15 + widthOfBoard;2746 }2747 // turn around if hit left side of animation2748 if(index == boxes.length - 1){27492750 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2751 index--;2752 direction = "up";2753 } else{2754 index++;2755 } //else2756 2757 }// else275827592760 currentAnimation15 = setTimeout(function(){2761 animateEnemy15(boxes, index, direction);2762 }, 750);2763 2764 //counter++;27652766 // if enemy runs into player, end the game27672768 if(currentLocationOfHorse == currentLocationOfEnemy15){2769 document.getElementById("lose").style.display = "block";2770 startLocation1 = originalLocation1;2771 startLocation2 = originalLocation2;2772 startLocation3 = originalLocation3;2773 clearTimeout(currentProjectile3);2774 clearTimeout(currentProjectile2);2775 clearTimeout(currentProjectile1);2776 clearTimeout(currentAnimation1);2777 clearTimeout(currentAnimation2);2778 clearTimeout(currentAnimation3);2779 clearTimeout(currentAnimation4);2780 clearTimeout(currentAnimation5);2781 clearTimeout(currentAnimation6);2782 clearTimeout(currentAnimation7);2783 clearTimeout(currentAnimation8);2784 clearTimeout(currentAnimation9);2785 clearTimeout(currentAnimation10);2786 clearTimeout(currentAnimation11);2787 clearTimeout(currentAnimation12);2788 clearTimeout(currentAnimation13);2789 clearTimeout(currentAnimation14);2790 clearTimeout(currentAnimation15);2791 clearTimeout(currentAnimation16);2792 canMove = false;2793 return; 2794 } //if2795}// animateEnemy1527962797// animate enemy left to right2798// boxes - array of grid boxes that include animation2799// index - current location of animation2800// direction - current direction of animation2801// enemy - type of enemy displayed2802function animateEnemy16(boxes, index, direction){///////////////////2803 2804 if(counter == 0){2805 currentLocationOfEnemy15 = enemyStart15;2806 } // if2807 2808 // exits function if no animation2809 if(boxes.length <= 0){ return;}2810 if(currentLevel == 0){ return;}2811 if(currentLevel == 1){ return;}2812 2813 // update the images2814 if(direction == "right"){2815 boxes[index].classList.add("enemy2right");2816 } else if (direction == "left"){2817 boxes[index].classList.add("enemy2left");2818 } else if (direction == "up"){2819 boxes[index].classList.add("enemy2up");2820 } else if (direction == "down"){2821 boxes[index].classList.add("enemy2down");2822 } //else2823 2824 // remove images from other boxes2825 for(i = 0; i < boxes.length; i++){2826 if(i != index){2827 boxes[i].classList.remove("enemy2left");2828 boxes[i].classList.remove("enemy2right");2829 boxes[i].classList.remove("enemy2up");2830 boxes[i].classList.remove("enemy2down");2831 } //if2832 } //for2833 2834 // moving right2835 if(direction == "right"){2836 if(counter >= 1){28372838 currentLocationOfEnemy16++;2839 } // if2840 2841 // turn around if hit right side of animation2842 if(index == boxes.length - 1){2843 //currentLocationOfEnemy = currentLocationOfEnemy + 1;2844 index--;2845 direction = "left";2846 } else{2847 index++;2848 } //else2849 2850 // moving left2851 } else if (direction == "left"){2852 if(counter >= 1){28532854 currentLocationOfEnemy16--;2855 } //if 2856 2857 // turn around if hit left side of animation2858 if(index == 0){2859 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2860 index++;2861 direction = "right";2862 } else{2863 index--;2864 } //else2865 2866 }else if (direction == "up"){2867 if(counter >= 1){2868 currentLocationOfEnemy16 = currentLocationOfEnemy16 - widthOfBoard;2869 } //if 2870 2871 // turn around if hit left side of animation2872 if(index == 0){2873 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2874 index++;2875 direction = "down";2876 } else{2877 index--;2878 2879 } //else2880 2881 } else if (direction == "down"){2882 if (counter >= 1){2883 currentLocationOfEnemy16 = currentLocationOfEnemy16 + widthOfBoard;2884 }2885 // turn around if hit left side of animation2886 if(index == boxes.length - 1){28872888 // currentLocationOfEnemy = currentLocationOfEnemy - 1;2889 index--;2890 direction = "up";2891 } else{2892 index++;2893 } //else2894 2895 }// else2896 currentAnimation16 = setTimeout(function(){2897 animateEnemy16(boxes, index, direction);2898 }, 750);2899 2900 //counter++;29012902 // if enemy runs into player, end the game29032904 if(currentLocationOfHorse == currentLocationOfEnemy16){2905 document.getElementById("lose").style.display = "block";2906 startLocation1 = originalLocation1;2907 startLocation2 = originalLocation2;2908 startLocation3 = originalLocation3;2909 clearTimeout(currentProjectile3);2910 clearTimeout(currentProjectile2);2911 clearTimeout(currentProjectile1);2912 clearTimeout(currentAnimation1);2913 clearTimeout(currentAnimation2);2914 clearTimeout(currentAnimation3);2915 clearTimeout(currentAnimation4);2916 clearTimeout(currentAnimation5);2917 clearTimeout(currentAnimation6);2918 clearTimeout(currentAnimation7);2919 clearTimeout(currentAnimation8);2920 clearTimeout(currentAnimation9);2921 clearTimeout(currentAnimation10);2922 clearTimeout(currentAnimation11);2923 clearTimeout(currentAnimation12);2924 clearTimeout(currentAnimation13);2925 clearTimeout(currentAnimation14);2926 clearTimeout(currentAnimation15);2927 clearTimeout(currentAnimation16);2928 canMove = false;2929 return; 2930 } //if2931}// animateEnemy162932
...
index.js
Source:index.js
...13 onSlideChangeEnd: function(swiper){14 swiperAnimate(swiper); //æ¯ä¸ªslideåæ¢ç»ææ¶ä¹è¿è¡å½åslideå¨ç»15 switch(swiper.activeIndex){16 case 7:17 clearTimeout(timer1);18 clearTimeout(timer2);19 clearTimeout(timer4);20 timer1=setTimeout(function(){21 document.getElementById('box8_nianxin').style=" animation: flash 1s linear 0s infinite";22 clearTimeout(timer1);23 clearTimeout(timer2);24 clearTimeout(timer4);25 },2500);26 break;27 case 8:28 clearTimeout(timer1);29 clearTimeout(timer2);30 clearTimeout(timer4);31 timer1=setTimeout(function(){32 document.getElementById('box9_nianxin').style=" animation: flash 1s linear 0s infinite";33 clearTimeout(timer1);34 clearTimeout(timer2);35 clearTimeout(timer4);36 },2500);37 break;38 case 9:39 clearTimeout(timer1);40 clearTimeout(timer2);41 clearTimeout(timer4);42 timer2=setTimeout(function(){43 document.getElementById('box10_nianxin1').style=" animation: flash 1s linear 0s infinite";44 document.getElementById('box10_nianxin2').style=" animation: flash 1s linear 0s infinite";45 clearTimeout(timer1);46 clearTimeout(timer2);47 clearTimeout(timer4);48 },2000);49 break;50 case 10:51 clearTimeout(timer1);52 clearTimeout(timer2);53 clearTimeout(timer4);54 timer2=setTimeout(function(){55 document.getElementById('box11_zw').style=" animation: flash 1s linear 0s infinite";56 document.getElementById('box11_yuexin2').style=" animation: flash 1s linear 0s infinite";57 clearTimeout(timer1);58 clearTimeout(timer2);59 clearTimeout(timer4);60 },2000);61 break;62 case 11:63 clearTimeout(timer1);64 clearTimeout(timer2);65 clearTimeout(timer4);66 timer2=setTimeout(function(){67 document.getElementById('box12_word4').style=" animation: flash 1.1s linear 0s infinite";68 clearTimeout(timer1);69 clearTimeout(timer2);70 },3700);71 timer4=setTimeout(function(){72 document.getElementById('box12_word5').style=" animation: flash 1.1s linear 0s infinite";73 clearTimeout(timer1);74 clearTimeout(timer2);75 clearTimeout(timer4);76 },3900);77 break;78 case 12:79 clearTimeout(timer1);80 clearTimeout(timer2);81 clearTimeout(timer4);82 timer2=setTimeout(function(){83 document.getElementById('box13_yuexin').style=" animation: flash 1s linear 0s infinite";84 clearTimeout(timer1);85 clearTimeout(timer2);86 clearTimeout(timer4);87 },2500);88 break;89 }90 }91 });92 var ad=document.getElementById('ad');93 var yinfu = document.getElementById('yinfu');94 var yinbiao=document.getElementById('yinbiao');95 yinfu.onclick=function(){96 if(ad.paused)97 {98 ad.play();99 yinfu.style.animationPlayState='running';100 yinbiao.style.background=' url("../image/yinfu.gif") no-repeat';...
newage.js
Source:newage.js
...15$('.roundabout-moveable-item1').click(function(){ 16for (var colpr = 1; colpr <= col_li; colpr++){$('.pr'+colpr).fadeOut(); }17$('.pr1').fadeIn(); 18for (var i = 0; i < 10; i++){ 19 clearTimeout(window['id1'+i]);20 clearTimeout(window['id2'+i]);21 clearTimeout(window['id3'+i]);22 clearTimeout(window['id4'+i]);23 clearTimeout(window['id5'+i]);24} 25$('.ul').roundabout("stopAutoplay");26}); 27$('.roundabout-moveable-item2').click(function(){ 28for (var colpr = 1; colpr <= col_li; colpr++){$('.pr'+colpr).fadeOut(); }29$('.pr2').fadeIn(); 30for (var i = 0; i < 10; i++){ 31 clearTimeout(window['id1'+i]);32 clearTimeout(window['id2'+i]);33 clearTimeout(window['id3'+i]);34 clearTimeout(window['id4'+i]);35 clearTimeout(window['id5'+i]);36} 37$('.ul').roundabout("stopAutoplay");38}); 39$('.roundabout-moveable-item3').click(function(){ 40for (var colpr = 1; colpr <= col_li; colpr++){$('.pr'+colpr).fadeOut(); }41$('.pr3').fadeIn(); 42for (var i = 0; i < 10; i++){ 43 clearTimeout(window['id1'+i]);44 clearTimeout(window['id2'+i]);45 clearTimeout(window['id3'+i]);46 clearTimeout(window['id4'+i]);47 clearTimeout(window['id5'+i]);48} 49$('.ul').roundabout("stopAutoplay");50}); 51$('.roundabout-moveable-item4').click(function(){ 52for (var colpr = 1; colpr <= col_li; colpr++){$('.pr'+colpr).fadeOut(); }53$('.pr4').fadeIn(); 54for (var i = 0; i < 10; i++){ 55 clearTimeout(window['id1'+i]);56 clearTimeout(window['id2'+i]);57 clearTimeout(window['id3'+i]);58 clearTimeout(window['id4'+i]);59 clearTimeout(window['id5'+i]);60} 61$('.ul').roundabout("stopAutoplay");62}); 63$('.roundabout-moveable-item5').click(function(){ 64for (var colpr = 1; colpr <= col_li; colpr++){$('.pr'+colpr).fadeOut(); }65$('.pr5').fadeIn(); 66for (var i = 0; i < 10; i++){ 67 clearTimeout(window['id1'+i]);68 clearTimeout(window['id2'+i]);69 clearTimeout(window['id3'+i]);70 clearTimeout(window['id4'+i]);71 clearTimeout(window['id5'+i]);72} 73$('.ul').roundabout("stopAutoplay");74}); 75var coltime = 0;76var time1 = 15000;77var time3 = 6000;78var time4 = 9000;79var time5 = 12000;80var time2 = 3000;81while (coltime <= 10){ 82 83window['id1'+coltime] = setTimeout(function() {84 for (var i = 1; i <= col_li; i++){ 85 $('.pr'+i).fadeOut(); ...
clearMoves.js
Source:clearMoves.js
1const clearMovesArr = [clearMoves1, clearMoves2, clearMoves3, clearMoves4, clearMoves5, clearMoves6]2function clearMoves1(){//ok3 clearInterval(ratMove)4 clearTimeout(rat11)5 clearTimeout(rat12)6 clearTimeout(rat13)7 clearTimeout(rat14)8 clearTimeout(rat15)9 clearTimeout(rat16)10 clearTimeout(rat17)11 clearTimeout(rat18)12}13function clearMoves2(){14 clearInterval(ratMove)15 clearTimeout(rat21)16 clearTimeout(rat22)17 clearTimeout(rat23)18 clearTimeout(rat24)19 clearTimeout(rat25)20 clearTimeout(rat26)21}22function clearMoves3(){23 clearInterval(ratMove)24 clearInterval(agentMove)25 clearTimeout(rat31)26 clearTimeout(rat32)27 clearTimeout(rat33)28 clearTimeout(rat34)29 clearTimeout(rat35)30 clearTimeout(rat36)31 clearTimeout(agent31)32 clearTimeout(agent32)33 clearTimeout(agent33)34 clearTimeout(agent34)35 clearTimeout(agent35)36 clearTimeout(agent36)37 clearTimeout(agent37)38 clearTimeout(agent38)39 clearTimeout(agent39)40 clearTimeout(agent310)41 clearTimeout(agent311)42 clearTimeout(agent312)43 clearTimeout(agent313)44 clearTimeout(agent314)45 clearTimeout(agent315)46 clearTimeout(agent316)47}48function clearMoves4(){49 clearInterval(agentMove)50 clearInterval(agentMove1)51 clearInterval(agentMove2)52 clearTimeout(agent41)53 clearTimeout(agent42)54 clearTimeout(agent43)55 clearTimeout(agent44)56 clearTimeout(agent45)57 clearTimeout(agent46)58 clearTimeout(agent141)59 clearTimeout(agent142)60 clearTimeout(agent143)61 clearTimeout(agent144)62 clearTimeout(agent145)63 clearTimeout(agent146)64 clearTimeout(agent147)65 clearTimeout(agent148)66 clearTimeout(agent241)67 clearTimeout(agent242)68 clearTimeout(agent243)69 clearTimeout(agent244)70 clearTimeout(agent245)71 clearTimeout(agent246)72 clearTimeout(agent247)73 clearTimeout(agent248)74}75function clearMoves5(){76 clearInterval(agentMove)77 clearInterval(agentMove1)78 clearInterval(jagMove)79 clearTimeout(agent51)80 clearTimeout(agent52)81 clearTimeout(agent53)82 clearTimeout(agent54)83 clearTimeout(agent55)84 clearTimeout(agent56)85 clearTimeout(agent57)86 clearTimeout(agent58)87 clearTimeout(agent151)88 clearTimeout(agent152)89 clearTimeout(agent153)90 clearTimeout(agent154)91 clearTimeout(agent155)92 clearTimeout(agent156)93 clearTimeout(agent157)94 clearTimeout(agent158)95 clearTimeout(jag41)96 clearTimeout(jag42)97 clearTimeout(jag43)98 clearTimeout(jag44)99 clearTimeout(jag45)100 clearTimeout(jag46)101 clearTimeout(jag47)102 clearTimeout(jag48)103 clearTimeout(jag49)104 clearTimeout(jag410)105 clearTimeout(jag411)106 clearTimeout(jag412)107}108function clearMoves6(){109 fase = 0...
Using AI Code Generation
1var timer = setTimeout(function() {2 console.log("Hello World");3}, 2000);4clearTimeout(timer);5var timer = global.setTimeout(function() {6 console.log("Hello World");7}, 2000);8global.clearTimeout(timer);9var timer = timer.setTimeout(function() {10 console.log("Hello World");11}, 2000);12timer.clearTimeout(timer);13var timer = global.timer.setTimeout(function() {14 console.log("Hello World");15}, 2000);16global.timer.clearTimeout(timer);17var timer = root.timer.setTimeout(function() {18 console.log("Hello World");19}, 2000);20root.timer.clearTimeout(timer);21var timer = root.global.timer.setTimeout(function() {22 console.log("Hello World");23}, 2000);24root.global.timer.clearTimeout(timer);25var timer = global.root.timer.setTimeout(function() {26 console.log("Hello World");27}, 2000);28global.root.timer.clearTimeout(timer);29var timer = global.root.timer.setTimeout(function() {30 console.log("Hello World");31}, 2000);32global.root.timer.clearTimeout(timer);33var timer = global.root.timer.setTimeout(function() {34 console.log("Hello World");35}, 2000);36global.root.timer.clearTimeout(timer);37var timer = global.root.timer.setTimeout(function() {38 console.log("Hello World");39}, 2000);40global.root.timer.clearTimeout(timer);41var timer = global.root.timer.setTimeout(function() {42 console.log("Hello World");43}, 2000);44global.root.timer.clearTimeout(timer);
Using AI Code Generation
1var timer = setTimeout(function(){2 console.log("Hello World!");3}, 2000);4clearTimeout(timer);5var timer = window.setTimeout(function(){6 console.log("Hello World!");7}, 2000);8clearTimeout(timer);9var timer = global.setTimeout(function(){10 console.log("Hello World!");11}, 2000);12clearTimeout(timer);13clearInterval(timer);14var timer = setInterval(function(){15 console.log("Hello World!");16}, 2000);17clearInterval(timer);18var timer = window.setInterval(function(){19 console.log("Hello World!");20}, 2000);21clearInterval(timer);22var timer = global.setInterval(function(){23 console.log("Hello World!");24}, 2000);25clearInterval(timer);26clearImmediate(timer);27var timer = setImmediate(function(){28 console.log("Hello World!");29});30clearImmediate(timer);31var timer = window.setImmediate(function(){32 console.log("Hello World!");33});34clearImmediate(timer);35var timer = global.setImmediate(function(){36 console.log("Hello World!");37});38clearImmediate(timer);
Using AI Code Generation
1var id = setTimeout(function(){2 console.log('Hello World');3}, 1000);4clearTimeout(id);5var id = setTimeout(function(){6 console.log('Hello World');7}, 1000);8var child = require('child_process').fork('./test.js');9child.on('message', function(m) {10 if(m === 'stop') {11 child.clearTimeout(id);12 }13});14child.send('stop');15var id = setInterval(function(){16 console.log('Hello World');17}, 1000);18clearInterval(id);19var id = setInterval(function(){20 console.log('Hello World');21}, 1000);22var child = require('child_process').fork('./test.js');23child.on('message', function(m) {24 if(m === 'stop') {25 child.clearInterval(id);26 }27});28child.send('stop');29setImmediate(function(){30 console.log('Hello World');31});32var child = require('child_process').fork('./test.js');33child.on('message', function(m) {34 if(m === 'stop') {35 child.setImmediate(function(){36 console.log('Hello World');37 });38 }39});40child.send('stop');41var id = setImmediate(function(){42 console.log('Hello World');43});44clearImmediate(id);45var id = setImmediate(function(){46 console.log('Hello World');47});48var child = require('child_process').fork('./test.js');49child.on('message', function(m) {50 if(m === 'stop') {51 child.clearImmediate(id);52 }53});54child.send('stop');55var id = setTimeout(function(){56 console.log('Hello World');57}, 1000);58id.unref();59var id = setTimeout(function(){60 console.log('Hello World');61}, 1000);62var child = require('child_process').fork('./test.js');63child.on('message', function(m) {64 if(m ===
Using AI Code Generation
1setTimeout(function() {2 console.log('Hello World');3}, 2000);4var obj = {5};6obj.setTimeout(function() {7 console.log('Hello World');8}, 2000);9var obj = {10};11obj.setTimeout(function() {12 console.log('Hello World');13}, 2000);14var obj = {15};16obj.setTimeout(function() {17 console.log('Hello World');18}, 2000);19var obj = {20};21obj.setTimeout(function() {22 console.log('Hello World');23}, 2000);24var obj = {25};26obj.setTimeout(function() {27 console.log('Hello World');28}, 2000);29var obj = {30};31obj.setTimeout(function() {32 console.log('Hello World');33}, 2000);34var obj = {35};36obj.setTimeout(function() {37 console.log('Hello World');38}, 2000);39var obj = {40};41obj.setTimeout(function() {42 console.log('Hello World');43}, 2000);44var obj = {45};46obj.setTimeout(function() {47 console.log('Hello World');48}, 2000);49var obj = {50};51obj.setTimeout(function() {52 console.log('Hello World');53}, 2000);54var obj = {55};56obj.setTimeout(function() {57 console.log('Hello World');58}, 2000);59var obj = {60};61obj.setTimeout(function() {62 console.log('Hello World');63}, 2000);64var obj = {65};66obj.setTimeout(function() {67 console.log('Hello World');68}, 2000);
Using AI Code Generation
1app.run(function($rootScope) {2 $rootScope.timer = setTimeout(function() {3 console.log("Timeout");4 }, 1000);5});6app.run(function($rootScope) {7 $rootScope.$on("$routeChangeStart", function() {8 clearTimeout($rootScope.timer);9 });10});11app.config(function($routeProvider) {12 .when("/route1", {13 })14 .when("/route2", {15 })16 .otherwise({17 });18});19app.controller("RouteController", function($scope) {20 $scope.message = "Hello World";21});22 <h1>{{message}}</h1>23 <h1>{{message}}</h1>
Using AI Code Generation
1console.log("Program Started");2var t=setTimeout(function()3{4 console.log("Hello");5},3000);6clearTimeout(t);7console.log("Program Ended");8console.log("Program Started");9var t=setInterval(function()10{11 console.log("Hello");12},3000);13console.log("Program Ended");14console.log("Program Started");15var t=setInterval(function()16{17 console.log("Hello");18},3000);19clearInterval(t);20console.log("Program Ended");21console.log("Program Started");22console.log("Program Ended");23console.log("Program Started");24console.error("Program Ended");25console.log("Program Started");26console.warn("Program Ended");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!