Best JavaScript code snippet using stryker-parent
pm18Functions.js
Source:pm18Functions.js
1/**2 * Creates graphs for PM183 * Calculates data for both Pm18 and PM194 * 5 */6/**7 * There are 4 types of mode8 * Mode 0: This is used when the page loads for the 1st time. Calculates Menu Text Only9 * Mode 1: Regional Performance Points and data10 * Mode 2: Corridor Performance Points and data11 * Mode 3: Corridor Data only, data for benchmark12 * * Mode 4: AOI13 */14function pm18Data(mode, ex) {15 let data_for_php = {};16 //stores graph values17 var pm18data = {18 //barGraph19 classA: [0, 0, 0, 0, 0],20 classB: [0, 0, 0, 0, 0],21 classC: [0, 0, 0, 0, 0],22 classO: [0, 0, 0, 0, 0],23 //line graph24 killed: [0, 0, 0, 0, 0],25 killed_Driving: [0, 0, 0, 0, 0],26 killed_walking: [0, 0, 0, 0, 0],27 killed_freight: [0, 0, 0, 0, 0],28 killed_biking: [0, 0, 0, 0, 0],29 //Dynamic Variables30 crashCount: 0,31 crashCountDK: 0,32 crashCountWK: 0,33 crashCountFK: 0,34 crashCountBK: 0,35 // Deaths Total per category36 dtot: 0,37 ftot: 0,38 wtot: 0,39 btot: 0,40 currentCorridor: 'Entire Region',41 dtextPercent: 0,42 dtextFatality: 0,43 latestYear: 044 }45 //let data_for_php = 0;46 let shape = "shape";47 let php_handler = "mwt_handler.php";48 let key = "";49 if (mode == 4) {50 data_for_php = ex;51 php_handler = "./backend/AOI.php";52 }53 if (mode == 0 || mode == 1) {54 key = 'all_pm18_19';55 data_for_php = {56 key: key57 };58 } else if (mode == 2 || mode == 3) {59 shape = 'ST_AsText(SHAPE)';60 php_handler = "corridor_handlerB.php";61 data_for_php = {62 key: 18,63 corridors_selected: ex,64 tableName: "pm18_19"65 };66 }67 let image = "./img/markers/crash.png";68 $.get(php_handler, data_for_php, function (data) {69 let latestYear = 0;70 //get latest year71 for (index in data.shape_arr) {72 let year = data.shape_arr[index].crash_year;73 if (latestYear < year) {74 latestYear = year;75 }76 }77 //crash counts78 let crashCountD = 0;79 let crashCountF = 0;80 let crashCountW = 0;81 let crashCountB = 0;82 pm18data.latestYear = latestYear;83 for (index in data.shape_arr) {84 let holder = [];85 let type = data.shape_arr[index]['type'];86 let crash_year = parseInt(data.shape_arr[index]['crash_year']);87 let killed = parseInt(data.shape_arr[index]['killed']);88 let classA = parseInt(data.shape_arr[index]['classA']);89 let classB = parseInt(data.shape_arr[index]['classB']);90 let classC = parseInt(data.shape_arr[index]['classC']);91 let classO = parseInt(data.shape_arr[index]['classO']);92 let ogrID = parseInt(data.shape_arr[index]['OGR_FID']);93 if (mode == 1 || mode == 2 || mode == 4) { // mode 1 and 2 allows us to draw points 94 holder.push(wktFormatterPoint(data.shape_arr[index][shape]));95 holder = holder[0][0]; // Fixes BLOBs96 let to_visualize = {97 lat: parseFloat(holder[0].lat),98 lng: parseFloat(holder[0].lng)99 };100 let point = new google.maps.Marker({101 position: to_visualize,102 title: "Year: " + crash_year + " \nSerious Injuries " + classA + " \nNon-Incapacitating Injuries: " + classB + "\nPossible Injuries: " + classC + "\nkilled: " + killed,103 value: ogrID,104 icon: image105 });106 //filter crashes/points107 if (currentType == "walking") {108 if ((type == "Pedestrian" || type == "PED" || type == "PED_COMV") && killed > 0) {109 point.setMap(map);110 points.push(point);111 }112 } else if (currentType == "freight") {113 if ((type == "COMV" || type == "Commerical_Vehicles" || type == "BIKE_COMV" || type == "PED_COMV") && killed > 0) {114 point.setMap(map);115 points.push(point);116 }117 } else if (currentType == "driving") {118 if (type == "GEN" && killed > 0) {119 point.setMap(map);120 points.push(point);121 }122 } else if (currentType == "biking") {123 if ((type == "Pedcyclists" || type == "BIKE" || type == "BIKE_COMV") && killed > 0) {124 point.setMap(map);125 points.push(point);126 }127 }128 }129 if (killed > 0 || classA > 0 || classB > 0 || classC > 0 || classO > 0) {130 pm18data.crashCount++;131 // crash counts132 if (type == "Pedestrian" || type == "PED") {133 crashCountW++;134 } else if (type == "Commerical_Vehicles" || type == "COMV") {135 crashCountF++;136 } else if (type == "GEN") {137 crashCountD++;138 } else if (type == "Pedcyclists" || type == "BIKE") {139 crashCountB++;140 } else if (type == "BIKE_COMV") {141 crashCountB++;142 crashCountB++;143 } else if (type == "PED_COMV") {144 crashCountF++;145 crashCountW++;146 }147 if (crash_year == latestYear - 4) {148 //for bar graph149 pm18data.killed[0] += killed;150 pm18data.classA[0] += classA;151 pm18data.classB[0] += classB;152 pm18data.classC[0] += classC;153 pm18data.classO[0] += classO;154 if (killed > 0) { //for line graph155 if (type == "Pedestrian" || type == "PED") {156 pm18data.killed_walking[0] += killed;157 pm18data.crashCountWK++; //count crash158 } else if (type == "Commerical_Vehicles" || type == "COMV") {159 pm18data.killed_freight[0] += killed;160 pm18data.crashCountFK++; //count crash161 } else if (type == "GEN") {162 pm18data.killed_Driving[0] += killed;163 pm18data.crashCountDK++; //count crash164 } else if (type == "Pedcyclists" || type == "BIKE") {165 pm18data.killed_biking[0] += killed;166 pm18data.crashCountBK++; //count crash167 } else if (type == "BIKE_COMV") {168 pm18data.killed_biking[0] += killed;169 pm18data.killed_freight[0] += killed;170 pm18data.crashCountBK++; //count crash171 pm18data.crashCountFK++;172 pm18data.crashCountBK++; //count crash173 } else if (type == "PED_COMV") {174 pm18data.killed_walking[0] += killed;175 pm18data.killed_freight[0] += killed;176 pm18data.crashCountFK++;177 pm18data.crashCountWK++;178 } else {179 console.log(type);180 }181 }182 } else if (crash_year == latestYear - 3) {183 //for bar graph184 pm18data.killed[1] += killed;185 pm18data.classA[1] += classA;186 pm18data.classB[1] += classB;187 pm18data.classC[1] += classC;188 pm18data.classO[1] += classO;189 if (killed > 0) { //for line graph190 if (type == "Pedestrian" || type == "PED") {191 pm18data.killed_walking[1] += killed;192 pm18data.crashCountWK++; //count crash193 } else if (type == "Commerical_Vehicles" || type == "COMV") {194 pm18data.killed_freight[1] += killed;195 pm18data.crashCountFK++; //count crash196 } else if (type == "GEN") {197 pm18data.killed_Driving[1] += killed;198 pm18data.crashCountDK++; //count crash199 } else if (type == "Pedcyclists" || type == "BIKE") {200 pm18data.killed_biking[1] += killed;201 pm18data.crashCountBK++; //count crash202 } else if (type == "BIKE_COMV") {203 pm18data.killed_biking[1] += killed;204 pm18data.killed_freight[1] += killed;205 pm18data.crashCountBK++; //count crash206 pm18data.crashCountFK++;207 pm18data.crashCountBK++; //count crash208 } else if (type == "PED_COMV") {209 pm18data.killed_walking[1] += killed;210 pm18data.killed_freight[1] += killed;211 pm18data.crashCountFK++;212 pm18data.crashCountWK++;213 } else {214 console.log(type);215 }216 }217 } else if (crash_year == latestYear - 2) {218 //for bar graph219 pm18data.killed[2] += killed;220 pm18data.classA[2] += classA;221 pm18data.classB[2] += classB;222 pm18data.classC[2] += classC;223 pm18data.classO[2] += classO;224 if (killed > 0) { //for line graph225 if (type == "Pedestrian" || type == "PED") {226 pm18data.killed_walking[2] += killed;227 pm18data.crashCountWK++; //count crash228 } else if (type == "Commerical_Vehicles" || type == "COMV") {229 pm18data.killed_freight[2] += killed;230 pm18data.crashCountFK++; //count crash231 } else if (type == "GEN") {232 pm18data.killed_Driving[2] += killed;233 pm18data.crashCountDK++; //count crash234 } else if (type == "Pedcyclists" || type == "BIKE") {235 pm18data.killed_biking[2] += killed;236 pm18data.crashCountBK++; //count crash237 } else if (type == "BIKE_COMV") {238 pm18data.killed_biking[2] += killed;239 pm18data.killed_freight[2] += killed;240 pm18data.crashCountBK++; //count crash241 pm18data.crashCountFK++;242 pm18data.crashCountBK++; //count crash243 } else if (type == "PED_COMV") {244 pm18data.killed_walking[2] += killed;245 pm18data.killed_freight[2] += killed;246 pm18data.crashCountFK++;247 pm18data.crashCountWK++;248 } else {249 console.log(type);250 }251 }252 } else if (crash_year == latestYear - 1) {253 //for bar graph254 pm18data.killed[3] += killed;255 pm18data.classA[3] += classA;256 pm18data.classB[3] += classB;257 pm18data.classC[3] += classC;258 pm18data.classO[3] += classO;259 if (killed > 0) { //for line graph260 if (type == "Pedestrian" || type == "PED") {261 pm18data.killed_walking[3] += killed;262 pm18data.crashCountWK++; //count crash263 } else if (type == "Commerical_Vehicles" || type == "COMV") {264 pm18data.killed_freight[3] += killed;265 pm18data.crashCountFK++; //count crash266 } else if (type == "GEN") {267 pm18data.killed_Driving[3] += killed;268 pm18data.crashCountDK++; //count crash269 } else if (type == "Pedcyclists" || type == "BIKE") {270 pm18data.killed_biking[3] += killed;271 pm18data.crashCountBK++; //count crash272 } else if (type == "BIKE_COMV") {273 pm18data.killed_biking[3] += killed;274 pm18data.killed_freight[3] += killed;275 pm18data.crashCountBK++; //count crash276 pm18data.crashCountFK++;277 pm18data.crashCountBK++; //count crash278 } else if (type == "PED_COMV") {279 pm18data.killed_walking[3] += killed;280 pm18data.killed_freight[3] += killed;281 pm18data.crashCountFK++;282 pm18data.crashCountWK++;283 } else {284 console.log(type);285 }286 }287 } else if (crash_year == latestYear) {288 //for bar graph289 pm18data.killed[4] += killed;290 pm18data.classA[4] += classA;291 pm18data.classB[4] += classB;292 pm18data.classC[4] += classC;293 pm18data.classO[4] += classO;294 if (killed > 0) { //for line graph295 if (type == "Pedestrian" || type == "PED") {296 pm18data.killed_walking[4] += killed;297 pm18data.crashCountWK++; //count crash298 } else if (type == "Commerical_Vehicles" || type == "COMV") {299 pm18data.killed_freight[4] += killed;300 pm18data.crashCountFK++; //count crash301 } else if (type == "GEN") {302 pm18data.killed_Driving[4] += killed;303 pm18data.crashCountDK++; //count crash304 } else if (type == "Pedcyclists" || type == "BIKE") {305 pm18data.killed_biking[4] += killed;306 pm18data.crashCountBK++; //count crash307 } else if (type == "BIKE_COMV") {308 pm18data.killed_biking[4] += killed;309 pm18data.killed_freight[4] += killed;310 pm18data.crashCountBK++; //count crash311 pm18data.crashCountFK++;312 pm18data.crashCountBK++; //count crash313 } else if (type == "PED_COMV") {314 pm18data.killed_walking[4] += killed;315 pm18data.killed_freight[4] += killed;316 pm18data.crashCountFK++;317 pm18data.crashCountWK++;318 } else {319 console.log(type);320 }321 }322 }323 }324 }325 //calculations for menu Text, summations326 pm18data.dtot = pm18data.killed_Driving.reduce((a, b) => a + b, 0);327 pm18data.ftot = pm18data.killed_freight.reduce((a, b) => a + b, 0);328 pm18data.wtot = pm18data.killed_walking.reduce((a, b) => a + b, 0);329 pm18data.btot = pm18data.killed_biking.reduce((a, b) => a + b, 0);330 if (mode == 0) { // menu text, this is only done once331 let drivingValue = {332 name: "pm18DrivingText",333 value: pm18data.dtot334 };335 let freightValue = {336 name: "pm18FreightText",337 value: pm18data.ftot338 };339 let walkingValue = {340 name: "pm18WalkingText",341 value: pm18data.wtot342 };343 let bikeValue = {344 name: "pm18BikeText",345 value: pm18data.btot346 };347 menu.push(drivingValue);348 menu.push(freightValue);349 menu.push(walkingValue);350 menu.push(bikeValue);351 }352 //calculations for static text353 if (currentType == 'driving') {354 pm18data.dtextPercent = (pm18data.crashCountDK / crashCountD) * 100;355 } else if (currentType == 'walking') {356 pm18data.dtextPercent = (pm18data.crashCountWK / crashCountW) * 100;357 } else if (currentType == 'biking') {358 pm18data.dtextPercent = (pm18data.crashCountBK / crashCountB) * 100;359 } else if (currentType == 'freight') {360 pm18data.dtextPercent = (pm18data.crashCountFK / crashCountF) * 100;361 }362 let corr = translateCorridor(data_for_php.corridors_selected); // what corridor are we on?363 if (mode == 1) {364 regionalText(pm18data);365 } else if (mode == 2) {366 pm18data.currentCorridor = corr;367 dynamicCorridorText(corr, pm18data); // Send graph data and current corridor to dynamic text for corridors368 } else if (mode == 3) {369 let data = {370 pm: '18',371 type: currentType,372 title: "Fatalities 2013 - 2017",373 corridor: corr,374 value: pm18data.dtot375 }376 benchmarkData.push(data);377 } else if (mode == 4) {378 dynamicCorridorText("AOI", pm18data); // Send graph data and current corridor to dynamic text for corridors379 }380 });381}382function pm18chartLine(ctx, data) {383 var pm18_graphTitle;384 var pm18_graphValues = [];385 //line chart data386 if (currentType == 'driving') { // if Driving is clicked387 pm18_graphValues[0] = data.killed_Driving[0];388 pm18_graphValues[1] = data.killed_Driving[1];389 pm18_graphValues[2] = data.killed_Driving[2];390 pm18_graphValues[3] = data.killed_Driving[3];391 pm18_graphValues[4] = data.killed_Driving[4];392 pm18_graphTitle = 'Driving Fatalities';393 } else if (currentType == 'freight') { // if Freight is clicked394 pm18_graphValues[0] = data.killed_freight[0];395 pm18_graphValues[1] = data.killed_freight[1];396 pm18_graphValues[2] = data.killed_freight[2];397 pm18_graphValues[3] = data.killed_freight[3];398 pm18_graphValues[4] = data.killed_freight[4];399 pm18_graphTitle = 'Freight Fatalities';400 } else if (currentType == 'walking') {401 pm18_graphValues[0] = data.killed_walking[0];402 pm18_graphValues[1] = data.killed_walking[1];403 pm18_graphValues[2] = data.killed_walking[2];404 pm18_graphValues[3] = data.killed_walking[3];405 pm18_graphValues[4] = data.killed_walking[4];406 pm18_graphTitle = 'Pedestrian Fatalities';407 } else if (currentType == 'biking') {408 pm18_graphValues[0] = data.killed_biking[0];409 pm18_graphValues[1] = data.killed_biking[1];410 pm18_graphValues[2] = data.killed_biking[2];411 pm18_graphValues[3] = data.killed_biking[3];412 pm18_graphValues[4] = data.killed_biking[4];413 pm18_graphTitle = 'Bicycle Fatalities';414 }415 var data = {416 labels: [data.latestYear - 4, data.latestYear - 3, data.latestYear - 2, data.latestYear - 1, data.latestYear],417 datasets: [{418 label: pm18_graphTitle,419 data: pm18_graphValues,420 backgroundColor: "purple",421 borderColor: "lightblue",422 fill: false,423 lineTension: 0,424 radius: 5425 },426 {427 label: "Total Fatalities",428 data: data.killed,429 //data: [data.tot13, data.tot14, data.tot15, data.tot16, data.tot17],430 backgroundColor: "green",431 borderColor: "lightgreen",432 fill: false,433 lineTension: 0,434 radius: 5435 }436 ]437 };438 //options439 var options = {440 responsive: true,441 title: {442 /*display: true,443 position: "top",444 text: title;445 fontSize: 12,446 fontColor: "#111"*/447 },448 legend: {449 display: true,450 position: "bottom",451 labels: {452 fontColor: "#333",453 fontSize: 12,454 boxWidth: 10455 }456 }457 };458 //create Chart class object459 var chart = new Chart(ctx, {460 type: "line",461 data: data,462 options: options463 });464}465function pm18StackedChart(ctx, data) {466 let titleH = data.currentCorridor;467 if (titleH != 'Entire Region') { //if corridor, fix wording468 titleH = wordFix(titleH + " Corridor");469 }470 var barChartData = {471 labels: [data.latestYear - 4, data.latestYear - 3, data.latestYear - 2, data.latestYear - 1, data.latestYear],472 datasets: [{473 label: 'Fatalities',474 backgroundColor: 'rgba(255,82,0,0.5)',475 data: data.killed476 }, {477 label: 'Serious Injuries',478 backgroundColor: 'rgba(92,187,3,0.5)rgba(92,187,3,0.5)',479 data: data.classA480 }, {481 label: 'Non-Incapacitating Injuries',482 backgroundColor: 'rgba(117,36,221,0.5)',483 data: data.classB484 }, {485 label: 'Possible Injuries',486 backgroundColor: 'rgba(255,235,59,1)',487 data: data.classC488 }]489 };490 var chartBar = new Chart(ctx, {491 type: "bar",492 data: barChartData,493 options: {494 legend: {495 display: true,496 position: "bottom",497 labels: {498 fontColor: "#333",499 fontSize: 10,500 boxWidth: 6501 }502 },503 title: {504 display: true,505 text: titleH,506 fontSize: 10507 //fontColor: "#111"508 },509 tooltips: {510 mode: 'index',511 intersect: false512 },513 responsive: true,514 scales: {515 xAxes: [{516 stacked: true,517 }],518 yAxes: [{519 stacked: true,520 ticks: {521 //max:45000522 }523 }]524 }525 }526 });...
monsters.js
Source:monsters.js
1var Monsters = function() {2 var inBossBattle = false;3 var monsterList = [4 //First Tier5 {name:"Rat", killed:0},6 {name:"Bat", killed:0},7 {name:"Slime", killed:0},8 {name:"Kobold", killed:0},9 {name:"Wolf", killed:0},10 {name:"Lizard", killed:0},11 {name:"Goblin", killed:0},12 {name:"Bandit", killed:0},13 {name:"Spider", killed:0},14 {name:"Eagle", killed:0},15 //Second Tier16 {name:"Bear", killed:0},17 {name:"Snake", killed:0},18 {name:"Troll", killed:0},19 {name:"Kobold Warrior", killed:0},20 {name:"Giant Wolf", killed:0},21 {name:"Ghoul", killed:0},22 {name:"Alligator", killed:0},23 {name:"Giant Lizard", killed:0},24 {name:"Giant Rat", killed: 0},25 {name:"Orc Child", killed:0},26 //Third Tier27 {name: "Stone Golem", killed: 0},28 {name: "Lesser Elemental", killed: 0},29 {name: "Kobold Chieftain", killed: 0},30 {name: "Weakened Minotaur", killed: 0},31 {name: "Troll Warrior", killed: 0},32 {name: "Wisp", killed: 0},33 {name: "Dragon Hatchling", killed: 0},34 {name: "Goblin Shaman", killed: 0},35 {name: "Giant Snake", killed: 0},36 {name: "Mummy", killed: 0},37 //Fourth Tier38 {name: "Elemental", killed: 0},39 {name: "Lesser Imp", killed: 0},40 {name: "Lizardman", killed: 0},41 {name: "Orc", killed: 0},42 {name: "Troll Chieftain", killed: 0},43 {name: "Cyclops", killed: 0},44 {name: "Young Vampire", killed: 0},45 {name: "Harpy", killed: 0},46 {name: "Empowered Wisp", killed: 0},47 {name: "Ancient Mummy", killed: 0},48 //Fifth Tier49 {name: "Imp", killed: 0},50 {name: "Orc Soldier", killed: 0},51 {name: "Young Minotaur", killed: 0},52 {name: "Floating Eye", killed: 0},53 {name: "Banshee", killed: 0},54 {name: "Young Dragon", killed: 0},55 {name: "Cyclops Warrior", killed: 0},56 {name: "Lizardman Archer", killed: 0},57 {name: "Living Armor", killed: 0},58 {name: "Frenzied Goblin", killed: 0}59 ];60 var bossList = [61 {name: "The First Guardian, Alstroemeria", currentHealth: 91204, maximumHealth: 91204, strength: 151, dexterity: 151, constitution: 151, status: 0},62 {name: "The Second Guardian, Bouvardia", currentHealth: 372100, maximumHealth: 372100, strength: 305, dexterity: 305, constitution: 305, status: 0},63 {name: "The Third Guardian, Clarkia", currentHealth: 864900, maximumHealth: 864900, strength: 465, dexterity: 465, constitution: 465, status: 0},64 {name: "The Fourth Guardian, Dianthus", currentHealth: 1638400, maximumHealth: 1638400, strength: 640, dexterity: 640, constitution: 640, status: 0},65 {name: "The Fifth Guardian, Erigeron", currentHealth: 2930944, maximumHealth: 2930944, strength: 856, dexterity: 856, constitution: 856, status: 0}66 ];67 var instancedMonster = {68 name: "",69 currentHealth: 0,70 maximumHealth: 0,71 strength: 0,72 dexterity: 0,73 constitution: 0,74 status: 075 };76 var self = this;77 //Save Method78 self.save = function() {79 var monstersSave = {80 savedMonsterList: monsterList,81 savedInstancedMonster: instancedMonster,82 savedInBossBattle: inBossBattle83 };84 localStorage.setItem("monstersSave",JSON.stringify(monstersSave));85 };86 //Load Method87 self.load = function() {88 var monstersSave = JSON.parse(localStorage.getItem("monstersSave"));89 if (monstersSave) {90 if (monstersSave.savedMonsterList !== undefined) {91 loadMonsterList(monstersSave.savedMonsterList);92 }93 if (monstersSave.savedInstancedMonster !== undefined) {94 loadInstancedMonster(monstersSave.savedInstancedMonster);95 }96 if (monstersSave.savedInBossBattle !== undefined) {97 inBossBattle = monstersSave.savedInBossBattle;98 }99 }100 };101 var loadMonsterList = function(savedMonsterList) {102 for (var i = 0; i < savedMonsterList.length; i++) {103 if (i == monsterList.length) {104 break;105 }106 if (savedMonsterList[i].killed !== undefined) {107 monsterList[i].killed = savedMonsterList[i].killed;108 }109 }110 };111 var loadInstancedMonster = function(savedInstancedMonster) {112 if (savedInstancedMonster.name !== undefined) {113 instancedMonster.name = savedInstancedMonster.name;114 }115 if (savedInstancedMonster.currentHealth !== undefined) {116 instancedMonster.currentHealth = savedInstancedMonster.currentHealth;117 }118 if (savedInstancedMonster.maximumHealth !== undefined) {119 instancedMonster.maximumHealth = savedInstancedMonster.maximumHealth;120 }121 if (savedInstancedMonster.strength !== undefined) {122 instancedMonster.strength = savedInstancedMonster.strength;123 }124 if (savedInstancedMonster.dexterity !== undefined) {125 instancedMonster.dexterity = savedInstancedMonster.dexterity;126 }127 if (savedInstancedMonster.constitution !== undefined) {128 instancedMonster.constitution = savedInstancedMonster.constitution;129 }130 if (savedInstancedMonster.status !== undefined) {131 instancedMonster.status = savedInstancedMonster.status;132 }133 };134 //Getters135 self.getMonsterList = function() {136 return monsterList;137 };138 self.getInstancedMonster = function() {139 return instancedMonster;140 };141 self.getBossMonster = function(number) {142 return bossList[number];143 };144 self.getInBossBattle = function() {145 return inBossBattle;146 };147 //Setters148 self.setInstancedMonster = function(updatedMonster) {149 instancedMonster = updatedMonster;150 };151 self.setInBossBattle = function(boolean) {152 inBossBattle = boolean;153 };154 //Other Methods155 self.attackMelee = function() {156 if(player.getInBattle()) {157 self.battle(instancedMonster, false);158 }159 };160 self.loadMonsterInfo = function(monster) {161 if (monster !== undefined) {162 document.getElementById("monstername").innerHTML = monster.name;163 document.getElementById("monsterhp").innerHTML = Math.round(monster.currentHealth);164 document.getElementById("monsterstr").innerHTML = monster.strength;165 document.getElementById("monsterdex").innerHTML = monster.dexterity;166 document.getElementById("monstercon").innerHTML = monster.constitution;167 document.getElementById("monsterbar").style.width = 100*(monster.currentHealth/monster.maximumHealth) + "%";168 if (!inBossBattle) {169 document.getElementById("combatlog").innerHTML = "You are attacked by a " + monster.name + "!<br>";170 }171 else {172 document.getElementById("combatlog").innerHTML = "You challenge a floor boss! You begin fighting " + monster.name + "!<br>";173 }174 player.setInBattle(true);175 }176 else {177 document.getElementById("monstername").innerHTML = "None";178 document.getElementById("monsterhp").innerHTML = "0";179 document.getElementById("monsterstr").innerHTML = "0";180 document.getElementById("monsterdex").innerHTML = "0";181 document.getElementById("monstercon").innerHTML = "0";182 document.getElementById("monsterbar").style.width = "0%";183 }184 };185 self.battle = function(monster, spellCast) {186 if(!player.getInBattle()) {187 player.setInBattle(true);188 player.loadRestButton();189 player.loadExploreButton();190 self.loadMonsterInfo(monster);191 if (buffs.getCastFireballInBattle()) {192 spells.castSpell("fireball");193 }194 }195 else {196 var isDead = false;197 if (!spellCast) {198 document.getElementById("combatlog").innerHTML = '';199 if (buffs.getCastCureInBattle() && player.getHealthCurrentValue() <= player.getHealthMaximumValue()/2) {200 if (!spells.castSpell("cure")) {201 isDead = playerAttacks(monster);202 }203 else {204 buffs.updateTemporaryBuffs(true);205 return true;206 }207 }208 else {209 isDead = playerAttacks(monster);210 }211 }212 if (!isDead) {213 isDead = monsterAttacks(monster);214 }215 }216 buffs.updateTemporaryBuffs(true);217 };218 var playerAttacks = function(monster) {219 var damage = damageFormula(player.getStrengthLevel() + player.getStrengthBonus(), player.getDexterityLevel() + player.getDexterityBonus(), monster.constitution, monster.currentHealth);220 if (buffs.getRageTimeLeft() !== 0) {221 damage *= 5;222 }223 if (damage >= monster.currentHealth) {224 damage = monster.currentHealth;225 }226 document.getElementById("combatlog").innerHTML += "You dealt " + Math.round(damage) + " damage to the " + monster.name + ".<br>";227 player.gainExperience(monster, true);228 return self.monsterTakeDamage(monster, damage);229 };230 self.monsterTakeDamage = function(monster, damage) {231 monster.currentHealth -= damage;232 document.getElementById("monsterhp").innerHTML = Math.floor(monster.currentHealth);233 document.getElementById("monsterbar").style.width = 100*(monster.currentHealth/monster.maximumHealth) + "%";234 if (monster.currentHealth <= 0) {235 monsterDeath(monster);236 return true;237 }238 return false;239 };240 var monsterDeath = function(monster) {241 player.setInBattle(false);242 if (!inBossBattle) {243 document.getElementById("combatlog").innerHTML += "You have defeated the " + monster.name + "!<br>";244 if (Math.floor(Math.random()*100) < 10) {245 monsterCrystalDrop(monster);246 inventory.updateInventory();247 }248 updateMonsterKilled(monster.name);249 }250 else {251 document.getElementById("combatlog").innerHTML += "You have defeated a floor boss! " + monster.name + " recognizes your strength and allows you to advance.";252 tower.setBossFound(false);253 tower.setLastBossDefeated(player.getCurrentFloor());254 tower.bossDefeated();255 inBossBattle = false;256 }257 upgrades.gainExcelia(monster);258 player.loadRestButton();259 player.loadExploreButton();260 self.loadMonsterInfo();261 };262 var monsterCrystalDrop = function(monster) {263 var type = Math.floor(Math.random()*5);264 var experience = monster.strength + monster.dexterity + monster.constitution;265 if (type === 0) {266 inventory.createCrystal("Strength", experience);267 }268 else if (type == 1) {269 inventory.createCrystal("Dexterity", experience);270 }271 else if (type == 2) {272 inventory.createCrystal("Constitution", experience);273 }274 else if (type == 3) {275 inventory.createCrystal("Speed", experience);276 }277 else if (type == 4) {278 inventory.createCrystal("Magic", experience);279 }280 document.getElementById("combatlog").innerHTML += "The " + monster.name + " has left an experience crystal behind!<br>";281 }282 var updateMonsterKilled = function(name) {283 for (var i = 0; i < monsterList.length; i++) {284 if (monsterList[i].name == name) {285 monsterList[i].killed++;286 }287 }288 };289 var damageFormula = function(attackerStrength, attackerDexterity, defenderConstitution, defenderHealth) {290 var strengthWeigth = 2;291 var dexterityWeigth = 0.1;292 var constitutionWeigth = 0.5;293 var damage = ((attackerStrength * strengthWeigth) - (defenderConstitution * constitutionWeigth)) * (attackerDexterity * dexterityWeigth);294 if (damage < 0) {295 damage = 0;296 }297 else if (damage > defenderHealth) {298 damage = defenderHealth;299 }300 return damage;301 };302 var monsterAttacks = function(monster) {303 var damage = damageFormula(monster.strength, monster.dexterity, player.getConstitutionLevel() + player.getConstitutionBonus(), player.getHealthCurrentValue());304 if (buffs.getRageTimeLeft() !== 0) {305 damage = damage*2;306 }307 if (buffs.getAegisTimeLeft() === 0) {308 var barrier = buffs.getBarrierLeft();309 if (barrier > 0) {310 if (barrier >= damage) {311 buffs.setBarrierLeft(barrier - damage);312 document.getElementById("combatlog").innerHTML += "Your barrier absorbed " + Math.round(damage) + " damage from " + monster.name + "'s attack.<br>";313 buffs.updateTemporaryBuffs(false);314 return false;315 }316 else {317 document.getElementById("combatlog").innerHTML += "Your barrier absorbed " + Math.round(barrier) + " damage from " + monster.name + "'s attack.<br>";318 document.getElementById("combatlog").innerHTML += "Your barrier has shattered.<br>";319 damage -= barrier;320 buffs.setBarrierLeft(0);321 buffs.updateTemporaryBuffs(false);322 }323 }324 player.setHealthCurrentValue(player.getHealthCurrentValue() - damage);325 document.getElementById("combatlog").innerHTML += "You took " + Math.round(damage) + " damage from the " + monster.name + "'s attack.<br>";326 if (player.getHealthCurrentValue() === 0) {327 player.death(monster);328 return true;329 }330 }331 else {332 document.getElementById("combatlog").innerHTML += "Aegis absorbed " + Math.round(damage) + " damage from " + monster.name + "'s attack.<br>";333 }334 player.gainExperience(monster, false);335 return false;336 };337 self.battleChance = function(boolean) {338 if (boolean) {339 rollMonster();340 return true;341 }342 else {343 var check = Math.random()*100;344 if (check <= tower.getFloorMonsterDensity(player.getCurrentFloor())) {345 rollMonster();346 return true;347 }348 return false;349 }350 };351 var rollMonster = function() {352 var tier = Math.floor((player.getCurrentFloor()-1)/10);353 var monster = Math.floor(Math.random()*10);354 while(monster == 10) {355 monster = Math.floor(Math.random()*10);356 }357 instancedMonster = createMonster((tier*10) + monster);358 self.battle(instancedMonster, false);359 };360 var createMonster = function(number) {361 var tempMonster = {name: "", currentHealth: 0, maximumHealth:0 , strength: 0, dexterity: 0, constitution: 0, status: 0};362 var statPool = Math.round((player.getCurrentFloor() * 15) + Math.pow(1.1, player.getCurrentFloor() - 1) - 1);363 tempMonster.name = monsterList[number].name;364 tempMonster.strength++;365 tempMonster.dexterity++;366 tempMonster.constitution++;367 statPool -= 3;368 distributeStats(tempMonster, statPool);369 tempMonster.maximumHealth = calculateHealth(tempMonster.constitution);370 tempMonster.currentHealth = tempMonster.maximumHealth;371 return tempMonster;372 };373 var distributeStats = function(monster, statPool) {374 var choice;375 while (statPool !== 0) {376 choice = Math.floor(Math.random()*3);377 while (choice == 3) {378 choice = Math.floor(Math.random()*3);379 }380 if (choice === 0) {381 monster.strength++;382 }383 else if (choice == 1) {384 monster.dexterity++;385 }386 else if (choice == 2) {387 monster.constitution++;388 }389 statPool--;390 }391 };392 var calculateHealth = function(constitution) {393 return (Math.pow(constitution, 2) * 4);394 };395 self.runAway = function() {396 if (player.getInBattle()) {397 document.getElementById("combatlog").innerHTML = "";398 var runRoll = Math.random() * (instancedMonster.strength + instancedMonster.dexterity + instancedMonster.constitution);399 if (runRoll < player.getSpeedLevel()) {400 document.getElementById("combatlog").innerHTML += "You escaped from the battle against " + instancedMonster.name + ".";401 self.loadMonsterInfo();402 player.setSpeedExperience(player.getSpeedExperience() + runRoll);403 player.setInBattle(false);404 player.loadExploreButton();405 player.loadRestButton();406 }407 else {408 document.getElementById("combatlog").innerHTML += "You failed to run away.<br>";409 self.battle(instancedMonster, true);410 }411 }412 if (inBossBattle) {413 inBossBattle = false;414 }415 }416};...
Game.js
Source:Game.js
1import React from 'react';2import Board from './Board';3import BoardInitializer from './BoardInitializer';4import KilledPieces from './KilledPieces';5export default class Game extends React.Component {6 constructor() {7 super()8 this.state = {9 squares: BoardInitializer(),10 status: '',11 selection: false,12 whiteKilledPieces: [],13 blackKilledPieces: [],14 killed: false,15 player: 1,16 srcIndex: -1,17 warning: '',18 turn: 'White',19 checkmate: ''20 };21 }22 swap = (input, index_A, index_B) => {23 let temp = input[index_A];24 input[index_A] = input[index_B];25 input[index_B] = temp;26 input[index_A] = null27 }28 srcHandeler = (squares, srcIndex, player, i) => {29 if (squares[i] && squares[i].player === this.state.player) {30 squares[i].style = { ...squares[i].style, backgroundColor: "rgb(247, 248, 132)" }31 this.setState({32 srcIndex: i,33 warning: 'Now Choose Your Destination'34 })35 } else {36 this.setState({37 warning: `Select Player ${this.state.player} Pieces`38 })39 }40 }41 destHandeler = (squares, player, srcIndex, i) => {42 let destIndex = i43 const destOccupied = squares[i] ? true : false;44 const ispossibleMove = squares[srcIndex].possibleMove(srcIndex, destIndex, destOccupied)45 const destPath = squares[srcIndex].destPath(srcIndex, destIndex)46 const jumpPossible = this.pieceJumphHandeler(destPath)47 const whiteKilledPieces = this.state.whiteKilledPieces.slice();48 const blackKilledPieces = this.state.blackKilledPieces.slice();49 if (ispossibleMove && jumpPossible) {50 if (squares[destIndex] !== null && squares[destIndex].player !== player) {51 if (squares[destIndex].player === 1) {52 whiteKilledPieces.push(squares[destIndex]);53 this.setState({54 whiteKilledPieces: whiteKilledPieces,55 killed: true56 })57 }58 else {59 blackKilledPieces.push(squares[destIndex]);60 this.setState({61 blackKilledPieces: blackKilledPieces,62 killed: true63 })64 }65 }66 if (squares[destIndex] && squares[destIndex].constructor.name === 'King' && squares[destIndex].player !== player) {67 this.setState({68 checkmate: `${this.state.turn} Player Won the Game ð`69 })70 setTimeout(() => {71 // window.location.reload()72 this.setState({73 squares: BoardInitializer(),74 status: '',75 selection: false,76 whiteKilledPieces: [],77 blackKilledPieces: [],78 killed: false,79 player: 1,80 srcIndex: -1,81 warning: '',82 turn: 'White',83 checkmate: ''84 });85 }, 3000);86 }87 if (squares[destIndex] && squares[destIndex].player === squares[srcIndex].player) {88 this.srcHandeler(squares, srcIndex, player, i)89 squares[srcIndex].style = { ...squares[srcIndex].style, backgroundColor: "" }90 } else {91 squares[srcIndex].style = { ...squares[srcIndex].style, backgroundColor: "" }92 this.swap(squares, srcIndex, destIndex);93 console.log(srcIndex, destIndex)94 this.setState({95 srcIndex: -1,96 turn: player === 1 ? 'Black' : 'White',97 player: player === 1 ? 2 : 1,98 })99 }100 } else {101 this.setState({102 warning: 'Wrong Destination'103 })104 }105 }106 clickHandeler = (i) => {107 let { squares, player, srcIndex } = this.state108 this.setState({109 warning: ''110 })111 //src selection112 if (srcIndex === -1) {113 this.srcHandeler(squares, srcIndex, player, i)114 }115 // destination selection116 else {117 this.destHandeler(squares, player, srcIndex, i)118 }119 }120 resetHandeler = () => {121 this.setState({122 squares: BoardInitializer(),123 status: '',124 selection: false,125 whiteKilledPieces: [],126 blackKilledPieces: [],127 killed: false,128 player: 1,129 srcIndex: -1,130 warning: '',131 turn: 'White',132 checkmate: ''133 });134 }135 pieceJumphHandeler = (destPath) => {136 let jump = true;137 for (let i = 0; i < destPath.length; i++) {138 if (this.state.squares[destPath[i]] !== null) {139 jump = false;140 }141 }142 return jump;143 }144 render() {145 return (146 <>147 <div className="main">148 <div className="game-board">149 <Board150 squares={this.state.squares}151 onClick={(i) => this.clickHandeler(i)}152 />153 </div>154 <div className="game-info">155 <h4>Turn of Player</h4>156 <div className="player-turn-box" style={{ backgroundColor: this.state.turn }}></div>157 <div className="game-status">158 <h3>{this.state.warning}</h3>159 <h3>{this.state.checkmate}</h3>160 </div>161 <button className="btn btn-success" onClick={this.resetHandeler}>Reset Pieces</button>162 {!this.state.killed ? '' : <h4>Killed Pieces</h4>}163 <div className="killed">164 <div className="pieces">165 <KilledPieces166 whiteKilledPieces={this.state.whiteKilledPieces}167 blackKilledPieces={this.state.blackKilledPieces}168 />169 </div>170 </div>171 </div>172 </div>173 </>174 )175 }...
Using AI Code Generation
1killed();2killed();3killed();4killed();5killed();6killed();7killed();8killed();9killed();10killed();11killed();12killed();13killed();14killed();15killed();16killed();17killed();18killed();19killed();20killed();21killed();22killed();23killed();
Using AI Code Generation
1const { killed } = require('stryker-parent');2killed();3const { killed } = require('stryker-parent');4killed();5### killed()6### killedByTimeout()7### killedByMutant()8### killedByMutantAndTimeout()9MIT © [Guillaume Lucciani](
Using AI Code Generation
1const strykerParent = require('stryker-parent');2strykerParent.killed();3module.exports = function(config) {4 config.set({5 commandRunner: {6 }7 });8};9const strykerParent = require('stryker-parent');10strykerParent.killed();11module.exports = function(config) {12 config.set({13 commandRunner: {14 }15 });16};17const strykerParent = require('stryker-parent');18strykerParent.killed();19module.exports = function(config) {20 config.set({21 commandRunner: {22 }23 });24};25const strykerParent = require('stryker-parent');26strykerParent.killed();27module.exports = function(config) {28 config.set({29 commandRunner: {30 }31 });32};33const strykerParent = require('stryker-parent');34strykerParent.killed();35module.exports = function(config) {36 config.set({37 commandRunner: {38 }39 });40};41const strykerParent = require('stryker-parent');42strykerParent.killed();43module.exports = function(config) {44 config.set({
Using AI Code Generation
1var killed = require('stryker-parent').killed;2killed(function () {3 console.log('Killed');4});5module.exports = function (config) {6 config.set({7 mochaOptions: {8 }9 });10};11 at Object.require (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\utils\objectUtils.js:23:19)12 at PluginLoader.require (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\di\pluginLoader.ts:25:30)13 at PluginLoader.load (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\di\pluginLoader.ts:19:22)14 at PluginLoader.load (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\di\pluginLoader.ts:16:17)15 at PluginCreator.create (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\di\pluginCreator.ts:31:33)16 at PluginCreator.create (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\di\pluginCreator.ts:21:17)17 at PluginCreator.create (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\src\di\pluginCreator.ts:21:17)18 at PluginCreator.create (C:\Users\kyle\Documents\stryker-test\node_modules\stryker\
Using AI Code Generation
1var stryker = require('stryker-parent');2stryker.killed(1, 'file1.js');3var stryker = require('stryker-parent');4stryker.killed(1, 'file2.js');5var stryker = require('stryker-parent');6stryker.killed(1, 'file3.js');7var stryker = require('stryker-parent');8stryker.killed(1, 'file4.js');9var stryker = require('stryker-parent');10stryker.killed(1, 'file5.js');11var stryker = require('stryker-parent');12stryker.killed(1, 'file6.js');13var stryker = require('stryker-parent');14stryker.killed(1, 'file7.js');15var stryker = require('stryker-parent');16stryker.killed(1, 'file8.js');17var stryker = require('stryker-parent');18stryker.killed(1, 'file9.js');19var stryker = require('stryker-parent');20stryker.killed(1, 'file10.js');21var stryker = require('stryker-parent');22stryker.killed(1, 'file11.js');23var stryker = require('stryker-parent');24stryker.killed(1, 'file12.js');
Using AI Code Generation
1var Parent = require('stryker-parent');2var parent = new Parent();3parent.killed();4var Parent = require('stryker-parent');5var parent = new Parent();6parent.killed();7var Parent = require('stryker-parent');8var parent = new Parent();9parent.killed();10var Parent = require('stryker-parent');11var parent = new Parent();12parent.killed();13var Parent = require('stryker-parent');14var parent = new Parent();15parent.killed();16var Parent = require('stryker-parent');17var parent = new Parent();18parent.killed();19var Parent = require('stryker-parent');20var parent = new Parent();21parent.killed();22var Parent = require('stryker-parent');23var parent = new Parent();24parent.killed();25var Parent = require('stryker-parent');26var parent = new Parent();27parent.killed();28var Parent = require('stryker-parent');29var parent = new Parent();30parent.killed();31var Parent = require('stryker-parent');32var parent = new Parent();33parent.killed();34var Parent = require('stryker-parent');35var parent = new Parent();36parent.killed();37var Parent = require('stryker-parent');38var parent = new Parent();39parent.killed();
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!!