1nextsrc= '' 2 3 function removeA(arr) { 4 var what, a = arguments, L = a.length, ax; 5 while (L > 1 && arr.length) { 6 what = a[--L]; 7 while ((ax= arr.indexOf(what)) !== -1) { 8 arr.splice(ax, 1); 9 } 10 } 11 return arr; 12 } 13 14 15 function setTankSources(rightsrc,leftsrc,downsrc,color,num,turn){ 16 if (rightsrc.includes(num)) 17 { 18 if(turn == 'tilt') 19 { 20 nextsrc = "static/imgLudo/" + color + "TankUp.png"; 21 } 22 else 23 { 24 nextsrc = "static/imgLudo/" + color + "TankDown.png"; 25 } 26 tanksrc = "static/imgLudo/" + color + "TankRight.png"; 27 otherBluesrc = "static/imgLudo/blueTankRight.png" 28 otherRedsrc = "static/imgLudo/redTankRight.png" 29 otherYellowsrc = "static/imgLudo/yellowTankRight.png" 30 otherGreensrc = "static/imgLudo/greenTankRight.png" 31 } 32 else if (leftsrc.includes(num)) 33 { 34 if(turn == 'tilt') 35 { 36 nextsrc = "static/imgLudo/" + color + "TankDown.png"; 37 } 38 else 39 { 40 nextsrc = "static/imgLudo/" + color + "TankUp.png"; 41 } 42 tanksrc = "static/imgLudo/" + color + "TankLeft.png"; 43 otherBluesrc = "static/imgLudo/blueTankLeft.png" 44 otherRedsrc = "static/imgLudo/redTankLeft.png" 45 otherYellowsrc = "static/imgLudo/yellowTankLeft.png" 46 otherGreensrc = "static/imgLudo/greenTankLeft.png" 47 } 48 else if (downsrc.includes(num)) 49 { 50 if(turn == 'tilt') 51 { 52 nextsrc = "static/imgLudo/" + color + "TankRight.png"; 53 } 54 else 55 { 56 nextsrc = "static/imgLudo/" + color + "TankLeft.png"; 57 } 58 tanksrc = "static/imgLudo/" + color + "TankDown.png"; 59 otherBluesrc = "static/imgLudo/blueTankDown.png" 60 otherRedsrc = "static/imgLudo/redTankDown.png" 61 otherYellowsrc = "static/imgLudo/yellowTankDown.png" 62 otherGreensrc = "static/imgLudo/greenTankDown.png" 63 } 64 else 65 { 66 if(turn == 'tilt') 67 { 68 nextsrc = "static/imgLudo/" + color + "TankLeft.png"; 69 } 70 else 71 { 72 nextsrc = "static/imgLudo/" + color + "TankRight.png"; 73 } 74 tanksrc = "static/imgLudo/" + color + "TankUp.png"; 75 otherBluesrc = "static/imgLudo/blueTankUp.png" 76 otherRedsrc = "static/imgLudo/redTankUp.png" 77 otherYellowsrc = "static/imgLudo/yellowTankUp.png" 78 otherGreensrc = "static/imgLudo/greenTankUp.png" 79 } 80 81 82 } 83 84 function moveloop(tank,path,tankcolor,start,end) 85 { 86 87 pauseInLoop = 0; 88 var nextTank = new Image(); 89 var otherTank = new Image(); 90 91 for(i = start;i<end;i++) 92 { 93 94 x1 = ((path[i].x1+4.67)/1280)*screenWidth 95 y1 = ((path[i].y1+4.67)/800)*screenHeight 96 x2 = ((path[i+1].x1+4.67)/1280)*screenWidth 97 y2 = ((path[i+1].y1+4.67)/800)*screenHeight 98 if((y2-y1) == 0) 99 { 100 distance = Math.round(Math.abs(x2-x1)) 101 } 102 else 103 { 104 distance = Math.round(Math.abs(y2-y1)) 105 } 106 if (leftTilt.includes(i)) 107 { 108 setTimeout(function() 109 { 110 if(pauseInLoop == 1) 111 { 112 console.log("time pass") 113 } 114 else if(pauseClick == 1) 115 { 116 pauseInLoop = 1; 117 } 118 else 119 { 120 x1 = ((path[num].x1+4.67)/1280)*screenWidth 121 y1= ((path[num].y1+4.67)/800)*screenHeight 122 x2 = ((path[num+1].x1+4.67)/1280)*screenWidth 123 y2 = ((path[num+1].y1+4.67)/800)*screenHeight 124 125 setTankSources(rightsrc,leftsrc,downsrc,tankcolor,num,'tilt'); 126 rotateTank(tanksrc,x1,y1,0,-45) 127 128 129 if(tankcolor == 'red') 130 { 131 check1 = green 132 check1src = otherGreensrc 133 check2 = yellow 134 check2src = otherYellowsrc 135 check3 = blue 136 check3src = otherBluesrc 137 check4 = red 138 check4src = otherRedsrc 139 } 140 else if(tankcolor == 'green') 141 { 142 check1 = red 143 check1src = otherRedsrc 144 check2 = yellow 145 check2src = otherYellowsrc 146 check3 = blue 147 check3src = otherBluesrc 148 check4 = green 149 check4src = otherGreensrc 150 } 151 else if(tankcolor == 'yellow') 152 { 153 check1 = red 154 check1src = otherRedsrc 155 check2 = green 156 check2src = otherGreensrc 157 check3 = blue 158 check3src = otherBluesrc 159 check4 = yellow 160 check4src = otherYellowsrc 161 } 162 else if(tankcolor == 'blue') 163 { 164 check1 = red 165 check1src = otherRedsrc 166 check2 = yellow 167 check2src = otherYellowsrc 168 check3 = green 169 check3src = otherGreensrc 170 check4 = blue 171 check4src = otherBluesrc 172 } 173 setTimeout(function() 174 { 175 checkTankAvailability(tank,path,check1,check2,check3,check4,check1src,check2src,check3src,check4src,tanksrc,"across"); 176 setTimeout(function() 177 { 178 rotateTank(tanksrc,x2,y2,-45,-90) 179 setTimeout(function() 180 { 181 if(pauseClick == 0) 182 { 183 context.clearRect(x2,y2,tankWr,tankHr);
184 context.restore(); 185 context.save(); 186 nextTank.src = nextsrc 187 188 context.drawImage(nextTank,x2,y2,tankWr,tankHr); 189 num = num + 1 190 if (num==end) 191 { 192 193 moveSound.stop() 194 if(SoundData == 2) 195 { 196 bombSound.play() 197 } 198 else if (SoundData ==3) 199 { 200 tankIn.play() 201 } 202 else if (SoundData == 4) 203 { 204 victory.play() 205 } 206 } 207 } 208 209 },230) 210 211 }, Math.round(Math.abs(y2-y1))*5 + 10) 212 },230) 213 } 214 215 },time) 216 time = time + 850 217 } 218 else if (rightTurn.includes(i)) 219 { 220 221 setTimeout(function() 222 { 223 if(pauseInLoop == 1) 224 { 225 226 console.log("time pass") 227 } 228 else if(pauseClick == 1) 229 { 230 pauseInLoop = 1; 231 } 232 else 233 { 234 x1 = ((path[num].x1+4.67)/1280)*screenWidth 235 y1= ((path[num].y1+4.67)/800)*screenHeight 236 x2 = ((path[num+1].x1+4.67)/1280)*screenWidth 237 y2 = ((path[num+1].y1+4.67)/800)*screenHeight 238 if((y2-y1) == 0) 239 { 240 distance = Math.round(Math.abs(x2-x1)) 241 } 242 else 243 { 244 distance = Math.round(Math.abs(y2-y1)) 245 } 246 setTankSources(rightsrc,leftsrc,downsrc,tankcolor,num,'right'); 247 if(tankcolor == 'red') 248 { 249 check1 = green 250 check1src = otherGreensrc 251 check2 = yellow 252 check2src = otherYellowsrc 253 check3 = blue 254 check3src = otherBluesrc 255 check4 = red 256 check4src = otherRedsrc 257 } 258 else if(tankcolor == 'green') 259 { 260 check1 = red 261 check1src = otherRedsrc 262 check2 = yellow 263 check2src = otherYellowsrc 264 check3 = blue 265 check3src = otherBluesrc 266 check4 = green 267 check4src = otherGreensrc 268 } 269 else if(tankcolor == 'yellow') 270 { 271 check1 = red 272 check1src = otherRedsrc 273 check2 = green 274 check2src = otherGreensrc 275 check3 = blue 276 check3src = otherBluesrc 277 check4 = yellow 278 check4src = otherYellowsrc 279 } 280 else if(tankcolor == 'blue') 281 { 282 check1 = red 283 check1src = otherRedsrc 284 check2 = yellow 285 check2src = otherYellowsrc 286 check3 = green 287 check3src = otherGreensrc 288 check4 = blue 289 check4src = otherBluesrc 290 } 291 checkTankAvailability(tank,path,check1,check2,check3,check4,check1src,check2src,check3src,check4src,tanksrc,"straight"); 292 293 294 setTimeout(function() 295 { 296 rotateTank(tanksrc,x2,y2,0,90) 297 setTimeout(function() 298 { 299 if(pauseClick == 0) 300 { 301 context.clearRect(x2-1,y2-1,tankWr+2,tankHr+2); 302 context.restore(); 303 context.save(); 304 nextTank.src = nextsrc 305 306 context.drawImage(nextTank,x2,y2,tankWr,tankHr); 307 num = num + 1 308 if (num==end) 309 { 310 311 moveSound.stop() 312 if (SoundData == 2) 313 { 314 bombSound.play() 315 } 316 else if (SoundData ==3) 317 { 318 tankIn.play() 319 } 320 else if (SoundData == 4) 321 { 322 victory.play() 323 } 324 } 325 } 326 327 },460) 328 329 },distance*5 + 30) 330 } 331 332 },time) 333 time = time + 850 334 } 335 else 336 { 337 setTimeout(function() 338 { 339 340 if(pauseInLoop == 1) 341 { 342 343 console.log("time pass") 344 } 345 else if(pauseClick == 1) 346 { 347 pauseInLoop = 1; 348 } 349 else 350 { 351 x1 = ((path[num].x1+4.67)/1280)*screenWidth 352 y1= ((path[num].y1+4.67)/800)*screenHeight 353 x2 = ((path[num+1].x1+4.67)/1280)*screenWidth 354 y2 = ((path[num+1].y1+4.67)/800)*screenHeight 355 if((y2-y1) == 0) 356 { 357 distance = Math.round(Math.abs(x2-x1)) 358 } 359 else 360 { 361 distance = Math.round(Math.abs(y2-y1)) 362 } 363 setTankSources(rightsrc,leftsrc,downsrc,tankcolor,num,'straight'); 364 if(tankcolor == 'red') 365 { 366 check1 = green 367 check1src = otherGreensrc 368 check2 = yellow 369 check2src = otherYellowsrc 370 check3 = blue 371 check3src = otherBluesrc 372 check4 = red 373 check4src = otherRedsrc 374 } 375 else if(tankcolor == 'green') 376 { 377 check1 = red 378 check1src = otherRedsrc 379 check2 = yellow 380 check2src = otherYellowsrc 381 check3 = blue 382 check3src = otherBluesrc 383 check4 = green 384 check4src = otherGreensrc 385 } 386 else if(tankcolor == 'yellow') 387 { 388 check1 = red 389 check1src = otherRedsrc 390 check2 = green 391 check2src = otherGreensrc 392 check3 = blue 393 check3src = otherBluesrc 394 check4 = yellow 395 check4src = otherYellowsrc 396 } 397 else if(tankcolor == 'blue') 398 { 399 check1 = red 400 check1src = otherRedsrc 401 check2 = yellow 402 check2src = otherYellowsrc 403 check3 = green 404 check3src = otherGreensrc 405 check4 = blue 406 check4src = otherBluesrc 407 } 408 if(num+1 == end) 409 { 410 if (starloc.includes(end)) 411 { 412 starEnd = 1 413 } 414 else 415 { 416 starEnd = 0 417 } 418 } 419 else 420 { 421 starEnd = 0 422 } 423 checkTankAvailability(tank,path,check1,check2,check3,check4,check1src,check2src,check3src,check4src,tanksrc,"straight",starEnd); 424 num = num + 1 425 if(num==end) 426 { 427 428 setTimeout(function() 429 { 430 moveSound.stop() 431 if (SoundData == 2) 432 { 433 bombSound.play() 434 435 } 436 else if (SoundData ==3) 437 { 438 tankIn.play() 439 } 440 else if (SoundData == 4) 441 { 442 victory.play() 443 } 444 },distance*5 + 40) 445 } 446 } 447 448 },time) 449 time = time + distance*5 + 40 450 } 451 452 } 453 } 454 455 function supportCheckAvail(tanksrc,x1,y1,x2,y2,d,checksrc,moveType,AllStarTank,AllStarSrc,starTankArray,starTankSrcArray) { 456 if (moveType == "across"){ 457 moveAcross(tanksrc,x1,y1,x2,y2,-45,d,checksrc,AllStarTank,AllStarSrc) 458 } 459 else 460 moveTankStraight(tanksrc,x1,y1,x2,y2,d,checksrc,AllStarTank,AllStarSrc,starTankArray,starTankSrcArray) 461 462 } 463 464 function checkTankAvailability(currentTank,pathVar,check1,check2,check3,check4,check1src,check2src,check3src,check4src,tanksrc,moveType,starEnd) 465 { 466 starCheck4 = check4.slice();
467 removeA(check4, currentTank); 468 AllStarTank = [] 469 AllStarSrc = [] 470 starTankArray=[] 471 starTankSrcArray=[] 472 if(starEnd == 1) 473 { 474 starEntryNum = pathVar[num+1].starTanks.length 475 for(j=0;j<starEntryNum;j++) 476 { 477 starTankArray.push(pathVar[num+1].starTanks[j]) 478 if(check1.includes(starTankArray[j])) 479 { 480 starTankSrcArray.push(check1src) 481 } 482 else if(check2.includes(starTankArray[j])) 483 { 484 starTankSrcArray.push(check2src) 485 } 486 else if(check3.includes(starTankArray[j])) 487 { 488 starTankSrcArray.push(check3src) 489 } 490 else if(starCheck4.includes(starTankArray[j])) 491 { 492 starTankSrcArray.push(check4src) 493 } 494 else 495 { 496 console.log("this is else on loop number :",j) 497 } 498 } 499 } 500 if(starloc.includes(num)) 501 { 502 starTanksNum = (pathVar[num].starTanks).length 503 for(i=0;i<starTanksNum;i++) 504 { 505 AllStarTank.push(pathVar[num].starTanks[i]) 506 if(check1.includes(AllStarTank[i])) 507 { 508 AllStarSrc.push(check1src) 509 } 510 else if(check2.includes(AllStarTank[i])) 511 { 512 AllStarSrc.push(check2src) 513 } 514 else if(check3.includes(AllStarTank[i])) 515 { 516 AllStarSrc.push(check3src) 517 } 518 else if(check4.includes(AllStarTank[i])) 519 { 520 AllStarSrc.push(check4src) 521 } 522 } 523 524 supportCheckAvail(tanksrc,x1,y1,x2,y2,0,'none',moveType,AllStarTank,AllStarSrc,starTankArray,starTankSrcArray) 525 } 526 else 527 { 528 if(check1.includes(pathVar[num].tanks)) 529 { 530 supportCheckAvail(tanksrc,x1,y1,x2,y2,1,check1src,moveType,[],[],starTankArray,starTankSrcArray) 531 } 532 else if(check2.includes(pathVar[num].tanks)) 533 { 534 supportCheckAvail(tanksrc,x1,y1,x2,y2,1,check2src,moveType,[],[],starTankArray,starTankSrcArray) 535 } 536 else if(check3.includes(pathVar[num].tanks)) 537 { 538 supportCheckAvail(tanksrc,x1,y1,x2,y2,1,check3src,moveType,[],[],starTankArray,starTankSrcArray) 539 } 540 else if(check4.includes(pathVar[num].tanks)) 541 { 542 supportCheckAvail(tanksrc,x1,y1,x2,y2,1,check4src,moveType,[],[],starTankArray,starTankSrcArray) 543 } 544 else 545 { 546 supportCheckAvail(tanksrc,x1,y1,x2,y2,0,'none',moveType,[],[],starTankArray,starTankSrcArray) 547 } 548 } 549 check4.push(currentTank) 550 } 551 552 553 function getStateEnd(tankData,tank,diceNum){ 554 tankNumber = tank.match(/(\d+)/); 555 556 start = tankData['tank' + tankNumber[0]] - diceNum 557 end = tankData['tank' + tankNumber[0]] 558 559 560 return { 561 "start" : start, 562 "end" : end, 563 } 564 } 565 function alltankmove(color,tank,diceNum,SoundData) 566 { 567 moveSound.play(); 568 569 leftTilt = [4,17,30,43] // Constant 570 rightTurn = [9,11,,22,24,35,37,48,49] // Constant 571 blue = ['blue1','blue2','blue3','blue4'] // Constant 572 red = ['red1','red2','red3','red4'] // Constant 573 green = ['green1','green2','green3','green4'] // Constant 574 yellow = ['yellow1','yellow2','yellow3','yellow4'] // Constant 575 var start; 576 var end; 577 if(color=='red') 578 { 579 rightTurn = [9,11,22,24,35,37,48,49] // Constant 580 rightsrc = [0,1,2,3,4,10,11,18,19,20,21,22,50,51,52,53,54,55,56] 581 leftsrc = [25,26,27,28,29,30,36,37,,44,45,46,47,48] 582 upsrc = [5,6,7,8,9,38,39,40,41,42,43,49] 583 downsrc = [12,13,14,15,16,17,23,24,31,32,33,34,35] 584 Data = redData 585 Path = redPath 586 } 587 else if(color=='green') 588 { 589 leftsrc = [0,1,2,3,4,10,11,18,19,20,21,22,50,51,52,53,54,55,56] 590 rightsrc = [25,26,27,28,29,30,36,37,,44,45,46,47,48] 591 downsrc = [5,6,7,8,9,38,39,40,41,42,43,49] 592 upsrc = [12,13,14,15,16,17,23,24,31,32,33,34,35] 593 Data = greenData 594 Path = greenPath 595 } 596 else if(color=='yellow') 597 { 598 upsrc = [0,1,2,3,4,10,11,18,19,20,21,22,50,51,52,53,54,55,56] 599 downsrc = [25,26,27,28,29,30,36,37,,44,45,46,47,48] 600 leftsrc = [5,6,7,8,9,38,39,40,41,42,43,49] 601 rightsrc = [12,13,14,15,16,17,23,24,31,32,33,34,35] 602 Data = yellowData 603 Path = yellowPath 604 } 605 else if(color=='blue') 606 { 607 downsrc = [0,1,2,3,4,10,11,18,19,20,21,22,50,51,52,53,54,55,56] 608 upsrc = [25,26,27,28,29,30,36,37,,44,45,46,47,48] 609 rightsrc = [5,6,7,8,9,38,39,40,41,42,43,49] 610 leftsrc = [12,13,14,15,16,17,23,24,31,32,33,34,35] 611 Data = blueData 612 Path = bluePath 613 } 614 var retdata = getStateEnd(Data,tank,diceNum); 615 start = retdata['start'] 616 end = retdata['end'] 617 num=start 618 time=0 619 620 621 moveloop(tank,Path,color,start,end,SoundData); 622 } 623 624
625function Not6automove(tanknum,tankcode,tankData,path,color,winnerXr,winnerYr,rollXr,rollYr,diceXr,diceYr,nextColor,rollNextXr,rollNextYr,diceNextXr,diceNextYr,diceNum) 626{ 627 gameWon = 0 628 colorArray = ['red','green','blue','yellow'] 629 removeA(colorArray,color); 630 631 roll = new Image(); 632 roll.src = "static/imgLudo/roll.png" 633 dice = new Image(); 634 dice.src = "static/imgLudo/blankDice.png" 635 winner = new Image(); 636 chance = 0; 637 if(starloc.includes(tankData[tanknum]+diceNum)) 638 { 639 SoundData = 1 640 } 641 else if(path[tankData[tanknum] + diceNum].tanks !='none') 642 { 643 SoundData = 2 644 } 645 else if(tankData[tanknum]+ diceNum == 56) 646 { 647 SoundData = 3 648 } 649 else 650 { 651 SoundData = 0 652 } 653 tankData[tanknum] = tankData[tanknum]+diceNum 654 if (tankData[tanknum] == 56) 655 { 656 chance = 1 657 sixRoll = 1; 658 } 659 660 Gchance=0; 661 Bchance=0; 662 Ychance=0; 663 Rchance=0; 664 665 for (i = 0; i < colorArray.length ; i++){ 666 if (colorArray[i] == 'red'){ 667 Rchance = colorCut(path,tankData,tanknum,"static/imgLudo/redTankDown.png",colorArray[i],redTank1Xr,redTank1Yr,redTank2Xr,redTank2Yr,redTank3Xr,redTank3Yr,redTank4Xr,redTank4Yr,redData) 668 } 669 else if(colorArray[i] == 'green'){ 670 Gchance = colorCut(path,tankData,tanknum,"static/imgLudo/greenTankUp.png",colorArray[i],greenTank1Xr,greenTank1Yr,greenTank2Xr,greenTank2Yr,greenTank3Xr,greenTank3Yr,greenTank4Xr,greenTank4Yr,greenData) 671 } 672 else if(colorArray[i] == 'blue'){ 673 Bchance = colorCut(path,tankData,tanknum,"static/imgLudo/blueTankLeft.png",colorArray[i],blueTank1Xr,blueTank1Yr,blueTank2Xr,blueTank2Yr,blueTank3Xr,blueTank3Yr,blueTank4Xr,blueTank4Yr,blueData) 674 } 675 else if(colorArray[i] == 'yellow'){ 676 Ychance = colorCut(path,tankData,tanknum,"static/imgLudo/yellowTankRight.png",colorArray[i],yellowTank1Xr,yellowTank1Yr,yellowTank2Xr,yellowTank2Yr,yellowTank3Xr,yellowTank3Yr,yellowTank4Xr,yellowTank4Yr,yellowData) 677 } 678 679 680 } 681 682 // Gchance = GreenCut(path,tankData,tanknum) 683 // Bchance = BlueCut(path,tankData,tanknum) 684 // Ychance = YellowCut(path,tankData,tanknum) 685 if(Gchance == 1 || Bchance == 1 || Ychance == 1 || Rchance == 1) 686 { 687 chance = 1; 688 sixRoll = 1; 689 } 690 if (starloc.includes(tankData[tanknum]-diceNum)) 691 { 692 removeA((path[tankData[tanknum]-diceNum]).starTanks,tankcode); 693 } 694 695 if (starloc.includes(tankData[tanknum])) 696 { 697 path[tankData[tanknum]].starTanks.push(tankcode); 698 } 699 700 path[tankData[tanknum]- diceNum].tanks ='none' 701 path[tankData[tanknum]].tanks = tankcode 702 if (tankData.tank1 == 56 && tankData.tank2 == 56 && tankData.tank3 == 56 && tankData.tank4 == 56) 703 { 704 chance = 0; 705 gameWon = 1; 706 SoundData = 4 707 console.log(" Player 1 is the winner of the game.") 708 709 } 710 alltankmove(color,tankcode,diceNum,SoundData) 711 if(chance == 1) 712 { 713 playerturn = color 714 } 715 else 716 { 717 playerturn = nextColor; 718 } 719 setTimeout(function() 720 { 721 if(gameWon == 1) 722 { 723 rank.push(color) 724 if(localP.includes(color)) 725 { 726 removeA(localP,color) 727 } 728 if(playerMode == 2) 729 { 730 victory.play(); 731 if(color == 'red') 732 { 733 playerRank = ["static/imgLudo/'lPlayer1.png","static/imgLudo/lPlayer2.png"] 734 rank = ['red','green'] 735 gameOver = 1; 736 setTimeout(function() 737 { 738 leaderboard() 739 740 741 },200) 742 743 } 744 else 745 { 746 gameOver = 1; 747 playerRank = ["static/imgLudo/lPlayer2.png","static/imgLudo/lPlayer1.png"] 748 rank = ['green','red'] 749 setTimeout(function() 750 { 751 leaderboard() 752 },200) 753 } 754 } 755 else if(playerMode == 3) 756 { 757 if(color == 'red') 758 { 759 playerRank.push("static/imgLudo/'lPlayer1.png") 760 won1 = 1; 761 } 762 else if(color == 'yellow') 763 { 764 won2 = 1; 765 playerRank.push("static/imgLudo/lPlayer2.png") 766 } 767 else 768 { 769 won3 = 1; 770 playerRank.push("static/imgLudo/lPlayer3.png") 771 } 772 773 if(rank.length == 2 || localP.length == 0) 774 { 775 gameOver = 1; 776 if(won1 != 1) 777 { 778 rank.push('red') 779 playerRank.push("static/imgLudo/'lPlayer1.png") 780 } 781 if(won2 != 1) 782 { 783 rank.push('yellow') 784 playerRank.push("static/imgLudo/'lPlayer2.png") 785 }
786 if(won3 !=1) 787 { 788 rank.push('green') 789 playerRank.push("static/imgLudo/'lPlayer3.png") 790 } 791 setTimeout(function() 792 { 793 leaderboard() 794 },200) 795 } 796 else 797 { 798 setTimeout(function() 799 { 800 if(won1 + won2 + won3 == 1) 801 { 802 winner.src = "static/imgLudo/Rank1Badge.png" 803 } 804 else if(won1 + won2 + won3 == 2) 805 { 806 winner.src = "static/imgLudo/Rank2Badge.png" 807 } 808 context.restore(); 809 winner.onload = function() 810 { 811 context.drawImage(winner,winnerXr,winnerYr,winnerWr,winnerHr); 812 } 813 814 },100) 815 } 816 } 817 else if(playerMode == 4) 818 { 819 if(color == 'red') 820 { 821 playerRank.push("static/imgLudo/'lPlayer1.png") 822 won1 = 1; 823 } 824 else if(color == 'yellow') 825 { 826 playerRank.push("static/imgLudo/'lPlayer2.png") 827 won2 = 1; 828 } 829 else if(color == 'green') 830 { 831 playerRank.push("static/imgLudo/'lPlayer3.png") 832 won3 = 1; 833 } 834 else 835 { 836 playerRank.push("static/imgLudo/'lPlayer4.png") 837 won4 = 1; 838 } 839 if(rank.length == 3 || localP.length == 0) 840 { 841 if(won1 != 1) 842 { 843 rank.push('red') 844 playerRank.push("static/imgLudo/'lPlayer1.png") 845 } 846 if(won2 != 1) 847 { 848 rank.push('yellow') 849 playerRank.push("static/imgLudo/'lPlayer2.png") 850 } 851 if(won3 !=1) 852 { 853 rank.push('green') 854 playerRank.push("static/imgLudo/'lPlayer3.png") 855 } 856 if(won4 != 1) 857 { 858 rank.push('blue') 859 playerRank.push("static/imgLudo/'lPlayer4.png") 860 } 861 gameOver = 1; 862 setTimeout(function() 863 { 864 leaderboard() 865 },200) 866 } 867 else 868 { 869 setTimeout(function() 870 { 871 if(won1 + won2 + won3+ won4 == 1) 872 { 873 winner.src = "static/imgLudo/Rank1Badge.png" 874 } 875 else if(won1 + won2 + won3 + won4== 2) 876 { 877 winner.src = "static/imgLudo/Rank2Badge.png" 878 } 879 context.restore(); 880 winner.onload = function() 881 { 882 context.drawImage(winner,winnerXr,winnerYr,winnerWr,winnerHr); 883 } 884 885 },100) 886 } 887 } 888 } 889 if (chance == 1 && pauseInLoop == 0 && pauseClick == 0) 890 { 891 RollAnimate = setInterval(function() 892 { 893 setTimeout(function() 894 { 895 context.clearRect(roll,rollXr*screenWidth,rollYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 896 },200) 897 context.drawImage(roll,rollXr*screenWidth,rollYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 898 },400) 899 context.drawImage(dice,diceXr*screenWidth,diceYr*screenHeight,diceWr*screenWidth,diceHr*screenHeight) 900 } 901 902 else if (gameOver == 1) 903 { 904 context.restore(); 905 } 906 else if(pauseInLoop == 0) 907 { 908 context.restore(); 909 diceRemData = getdiceRemove(color) 910 diceRemDataXr = diceRemData[0]/1280; 911 diceRemDataYr = diceRemData[1]/800; 912 913 914 setTimeout(function() 915 { 916 if(pauseClick == 0 && pauseInLoop == 0) 917 { 918 RollAnimate = setInterval(function() 919 { 920 setTimeout(function() 921 { 922 context.clearRect(rollNextXr*screenWidth,rollNextYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 923 },200) 924 context.drawImage(roll,rollNextXr*screenWidth,rollNextYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 925 },400) 926 context.drawImage(dice,diceNextXr*screenWidth,diceNextYr*screenHeight,diceWr*screenWidth,diceHr*screenHeight) 927 context.clearRect(diceRemDataXr*screenWidth,diceRemDataYr*screenHeight,(193/1280)*screenWidth,(53/800)*screenHeight) 928 } 929 },20); 930 } 931 },diceNum*850); 932 return chance 933} 934 935 936 937function sixAutomove(tanknum,tankcode,home,tankData,path,tankImageSource,color,winnerXr,winnerYr,rollXr,rollYr,diceXr,diceYr,diceNum,nextColor,rollNextXr,rollNextYr,diceNextXr,diceNextYr) 938{ 939 gameWon = 0; 940 colorArray = ['red','green','blue','yellow'] 941 blue = ['blue1','blue2','blue3','blue4'] // Constant 942 red = ['red1','red2','red3','red4'] // Constant 943 green = ['green1','green2','green3','green4'] // Constant 944 yellow = ['yellow1','yellow2','yellow3','yellow4'] // Constant 945 removeA(colorArray,color); 946 if(color=='red') 947 { 948 direction = "Right" 949 } 950 else if(color=='green') 951 { 952 direction = "Left" 953 } 954 else if(color=='yellow') 955 { 956 direction = "Up" 957 } 958 else if(color=='blue') 959 { 960 direction = "Down" 961 } 962 963 roll = new Image(); 964 roll.src = "static/imgLudo/roll.png" 965 dice = new Image(); 966 dice.src = "static/imgLudo/blankDice.png" 967 winner = new Image(); 968 969 tank = new Image(); 970 starTankDraw = new Image(); 971 972 oldloc = tankbox(tankData,tanknum,path,home) 973 oldtank1x = oldloc[0]; 974 oldtank1y = oldloc[1]; 975 if (tankData[tanknum] == -1) 976 { 977 SoundData = 1 978 tankData[tanknum] = 0; 979 tank.src = tankImageSource; 980 path[tankData[tanknum]].tanks = tankcode 981 path[tankData[tanknum]].starTanks.push(tankcode) 982 homeStarTanks = [] 983 homeStarTankSRC = [] 984 985 986 homeStarTankNum = path[tankData[tanknum]].starTanks.length 987 for(j=0;j<homeStarTankNum;j++) 988 { 989 homeStarTanks.push(path[tankData[tanknum]].starTanks[j]) 990 if(red.includes(homeStarTanks[j])) 991 { 992 homeStarTankSRC.push("static/imgLudo/redTank" + direction + ".png") 993 } 994 else if(blue.includes(homeStarTanks[j])) 995 { 996 homeStarTankSRC.push("static/imgLudo/blueTank" + direction + ".png") 997 } 998 else if(green.includes(homeStarTanks[j])) 999 { 1000 homeStarTankSRC.push("static/imgLudo/greenTank" + direction + ".png") 1001 } 1002 else if(yellow.includes(homeStarTanks[j])) 1003 { 1004 homeStarTankSRC.push("static/imgLudo/yellowTank" + direction + ".png") 1005 } 1006 } 1007 } 1008 else 1009 { 1010 currentState = 'moving' 1011 if(starloc.includes(tankData[tanknum]+diceNum)) 1012 { 1013 SoundData = 1 1014 } 1015 else if(path[tankData[tanknum] + diceNum].tanks !='none') 1016 { 1017 SoundData = 2 1018 } 1019 else if(tankData[tanknum]+ diceNum == 56) 1020 { 1021 SoundData = 3 1022 } 1023 else 1024 { 1025 SoundData = 0 1026 } 1027 tankData[tanknum] = tankData[tanknum] + diceNum; 1028 1029 1030 for (i = 0; i < colorArray.length ; i++) 1031 { 1032 if (colorArray[i] == 'red'){ 1033 colorCut(path,tankData,tanknum,"static/imgLudo/redTankDown.png",colorArray[i],redTank1Xr,redTank1Yr,redTank2Xr,redTank2Yr,redTank3Xr,redTank3Yr,redTank4Xr,redTank4Yr,redData) 1034 } 1035 else if(colorArray[i] == 'green'){
1036 colorCut(path,tankData,tanknum,"static/imgLudo/greenTankUp.png",colorArray[i],greenTank1Xr,greenTank1Yr,greenTank2Xr,greenTank2Yr,greenTank3Xr,greenTank3Yr,greenTank4Xr,greenTank4Yr,greenData) 1037 } 1038 else if(colorArray[i] == 'blue'){ 1039 colorCut(path,tankData,tanknum,"static/imgLudo/blueTankLeft.png",colorArray[i],blueTank1Xr,blueTank1Yr,blueTank2Xr,blueTank2Yr,blueTank3Xr,blueTank3Yr,blueTank4Xr,blueTank4Yr,blueData) 1040 } 1041 else if(colorArray[i] == 'yellow'){ 1042 colorCut(path,tankData,tanknum,"static/imgLudo/yellowTankRight.png",colorArray[i],yellowTank1Xr,yellowTank1Yr,yellowTank2Xr,yellowTank2Yr,yellowTank3Xr,yellowTank3Yr,yellowTank4Xr,yellowTank4Yr,yellowData) 1043 } 1044 1045 1046 } 1047 // GreenCut(path,tankData,tanknum) 1048 // BlueCut(path,tankData,tanknum) 1049 // YellowCut(path,tankData,tanknum) 1050 path[tankData[tanknum] - diceNum].tanks ='none' 1051 path[tankData[tanknum]].tanks = tankcode 1052 if (starloc.includes(tankData[tanknum]-diceNum)) 1053 { 1054 removeA((path[tankData[tanknum]-diceNum]).starTanks,tankcode); 1055 } 1056 1057 if (starloc.includes(tankData[tanknum])) 1058 { 1059 path[tankData[tanknum]].starTanks.push(tankcode); 1060 } 1061 1062 1063 } 1064 newloc = tankdraw(tankData,tanknum,path,home) 1065 newtank1x = newloc[0]; 1066 newtank1y =newloc[1]; 1067 if (tankData.tank1 == 56 && tankData.tank2 == 56 && tankData.tank3 == 56 && tankData.tank4 == 56) 1068 { 1069 gameWon = 1; 1070 SoundData = 4; 1071 console.log(" Player 1 is the winner of the game.") 1072 1073 } 1074 if (tankData[tanknum] == 0 && pauseClick == 0) 1075 { 1076 gOpen.play() 1077 setTimeout(function() 1078 { 1079 1080 context.restore(); 1081 context.clearRect(oldtank1x,oldtank1y,BoxWd ,BoxHt) 1082 context.clearRect(newtank1x,newtank1y,tankWr,tankHr) 1083 1084 if((color == 'red'|| color == 'green')&& homeStarTanks.length == 2 ) 1085 { 1086 starTankDraw.src = homeStarTankSRC[0] 1087 context.drawImage(starTankDraw,newtank1x+tankWr/4,newtank1y,tankWr/2,tankHr/2) 1088 starTankDraw.src = homeStarTankSRC[1] 1089 context.drawImage(starTankDraw,newtank1x+tankWr/4,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1090 } 1091 else if((color == 'red'|| color == 'green')&& homeStarTanks.length == 3 ) 1092 { 1093 starTankDraw.src = homeStarTankSRC[0] 1094 context.drawImage(starTankDraw,newtank1x,newtank1y,tankWr/2,tankHr/2) 1095 starTankDraw.src = homeStarTankSRC[1] 1096 context.drawImage(starTankDraw,newtank1x,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1097 starTankDraw.src = homeStarTankSRC[2] 1098 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y+tankHr/4 ,tankWr/2,tankHr/2) 1099 } 1100 else if((color == 'red'|| color == 'green')&& homeStarTanks.length == 4 ) 1101 { 1102 starTankDraw.src = homeStarTankSRC[0] 1103 context.drawImage(starTankDraw,newtank1x,newtank1y,tankWr/2,tankHr/2) 1104 starTankDraw.src = homeStarTankSRC[1] 1105 context.drawImage(starTankDraw,newtank1x,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1106 starTankDraw.src = homeStarTankSRC[2] 1107 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y,tankWr/2,tankHr/2) 1108 starTankDraw.src = homeStarTankSRC[3] 1109 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y+tankHr/2,tankWr/2,tankHr/2) 1110 } 1111 else if((color == 'blue'|| color == 'yellow')&& homeStarTanks.length == 2 ) 1112 { 1113 starTankDraw.src = homeStarTankSRC[0] 1114 context.drawImage(starTankDraw,newtank1x,newtank1y+tankHr/4,tankWr/2,tankHr/2) 1115 starTankDraw.src = homeStarTankSRC[1] 1116 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y+tankHr/4 ,tankWr/2,tankHr/2) 1117 } 1118 else if((color == 'blue'|| color == 'yellow')&& homeStarTanks.length == 3 ) 1119 { 1120 starTankDraw.src = homeStarTankSRC[0] 1121 context.drawImage(starTankDraw,newtank1x+tankWr/4,newtank1y,tankWr/2,tankHr/2) 1122 starTankDraw.src = homeStarTankSRC[1] 1123 context.drawImage(starTankDraw,newtank1x,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1124 starTankDraw.src = homeStarTankSRC[2] 1125 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1126 } 1127 else if((color == 'blue'|| color == 'yellow')&& homeStarTanks.length == 4 ) 1128 { 1129 starTankDraw.src = homeStarTankSRC[0] 1130 context.drawImage(starTankDraw,newtank1x,newtank1y,tankWr/2,tankHr/2) 1131 starTankDraw.src = homeStarTankSRC[1] 1132 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y,tankWr/2,tankHr/2) 1133 starTankDraw.src = homeStarTankSRC[2] 1134 context.drawImage(starTankDraw,newtank1x,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1135 starTankDraw.src = homeStarTankSRC[3] 1136 context.drawImage(starTankDraw,newtank1x+tankWr/2,newtank1y+tankHr/2 ,tankWr/2,tankHr/2) 1137 } 1138 else 1139 { 1140 context.drawImage(tank,newtank1x,newtank1y,tankWr,tankHr) 1141 } 1142 RollAnimate = setInterval(function() 1143 { 1144 setTimeout(function() 1145 { 1146 context.clearRect(rollXr*screenWidth,rollYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 1147 },200) 1148 context.drawImage(roll,rollXr*screenWidth,rollYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 1149 },400) 1150 context.drawImage(dice,diceXr*screenWidth,diceYr*screenHeight,diceWr*screenWidth,diceHr*screenHeight) 1151 },400); 1152 } 1153 else if(pauseClick == 0) 1154 { 1155 setTimeout(function() 1156 { 1157 alltankmove(color,tankcode,diceNum,SoundData) 1158 },400)
1159 context.restore(); 1160 diceRemData = getdiceRemove(color) 1161 diceRemDataXr = diceRemData[0]/1280; 1162 diceRemDataYr = diceRemData[1]/800; 1163 setTimeout(function() 1164 { 1165 if(gameWon == 1) 1166 { 1167 rank.push(color) 1168 if(localP.includes(color)) 1169 { 1170 removeA(localP,color) 1171 } 1172 if(playerMode == 2) 1173 { 1174 if(color == 'red') 1175 { 1176 playerRank = ["static/imgLudo/'lPlayer1.png","static/imgLudo/'lPlayer2.png"] 1177 rank = ['red','green'] 1178 gameOver = 1; 1179 setTimeout(function() 1180 { 1181 leaderboard() 1182 },200) 1183 } 1184 else 1185 { 1186 playerRank = ["static/imgLudo/'lPlayer2.png","static/imgLudo/'lPlayer1.png"] 1187 rank = ['green','red']; 1188 gameOver = 1; 1189 setTimeout(function() 1190 { 1191 leaderboard() 1192 },200) 1193 } 1194 } 1195 else if(playerMode == 3) 1196 { 1197 if(color == 'red') 1198 { 1199 playerRank.push("static/imgLudo/'lPlayer1.png") 1200 won1 = 1; 1201 } 1202 else if(color == 'yellow') 1203 { 1204 playerRank.push("static/imgLudo/'lPlayer2.png") 1205 won2 = 1; 1206 } 1207 else 1208 { 1209 playerRank.push("static/imgLudo/'lPlayer3.png") 1210 won3 = 1; 1211 } 1212 if(rank.length == 2 || localP.length == 0) 1213 { 1214 if(won1 != 1) 1215 { 1216 rank.push('red') 1217 playerRank.push("static/imgLudo/'lPlayer1.png") 1218 } 1219 if(won2 != 1) 1220 { 1221 rank.push('yellow') 1222 playerRank.push("static/imgLudo/'lPlayer2.png") 1223 } 1224 if(won3 != 1) 1225 { 1226 rank.push('green') 1227 playerRank.push("static/imgLudo/'lPlayer3.png") 1228 } 1229 gameOver = 1; 1230 setTimeout(function() 1231 { 1232 leaderboard() 1233 },200) 1234 } 1235 else 1236 { 1237 setTimeout(function() 1238 { 1239 if(won1 + won2 + won3 == 1) 1240 { 1241 winner.src = "static/imgLudo/Rank1Badge.png" 1242 } 1243 else if(won1 + won2 + won3 == 2) 1244 { 1245 winner.src = "static/imgLudo/Rank2Badge.png" 1246 } 1247 context.restore(); 1248 winner.onload = function() 1249 { 1250 context.drawImage(winner,winnerXr,winnerYr,winnerWr,winnerHr) 1251 } 1252 1253 },100) 1254 } 1255 } 1256 else if(playerMode == 4) 1257 { 1258 if(color == 'red') 1259 { 1260 playerRank.push("static/imgLudo/'lPlayer1.png") 1261 won1 = 1; 1262 } 1263 else if(color == 'yellow') 1264 { 1265 playerRank.push("static/imgLudo/'lPlayer2.png") 1266 won2 = 1; 1267 } 1268 else if(color == 'green') 1269 { 1270 playerRank.push("static/imgLudo/'lPlayer3.png") 1271 won3 = 1; 1272 } 1273 else 1274 { 1275 playerRank.push("static/imgLudo/'lPlayer4.png") 1276 won4 = 1; 1277 } 1278 if(rank.length == 3 || localP.length == 0) 1279 { 1280 if(won1 != 1) 1281 { 1282 rank.push('red') 1283 playerRank.push("static/imgLudo/'lPlayer1.png") 1284 } 1285 if(won2 != 1) 1286 { 1287 rank.push('yellow') 1288 playerRank.push("static/imgLudo/'lPlayer2.png") 1289 } 1290 if(won3 !=1) 1291 { 1292 rank.push('green') 1293 playerRank.push("static/imgLudo/'lPlayer3.png") 1294 } 1295 if(won4 !=1) 1296 { 1297 rank.push('blue') 1298 playerRank.push("static/imgLudo/'lPlayer4.png") 1299 } 1300 gameOver = 1; 1301 setTimeout(function() 1302 { 1303 leaderboard() 1304 },200) 1305 } 1306 else 1307 { 1308 setTimeout(function() 1309 { 1310 if(won1 + won2 + won3 + won4 == 1) 1311 { 1312 winner.src = "static/imgLudo/Rank1Badge.png" 1313 } 1314 else if(won1 + won2 + won3 + won4== 2) 1315 { 1316 winner.src = "static/imgLudo/Rank2Badge.png" 1317 } 1318 context.restore(); 1319 winner.onload = function() 1320 { 1321 context.drawImage(winner,winnerXr,winnerYr,winnerWr,winnerHr) 1322 } 1323 1324 },100) 1325 } 1326 } 1327 1328 if (gameOver == 1) 1329 {
1330 context.restore(); 1331 } 1332 else 1333 { 1334 playerturn = nextColor 1335 1336 if(pauseClick == 0) 1337 { 1338 RollAnimate = setInterval(function() 1339 { 1340 setTimeout(function() 1341 { 1342 context.clearRect(rollNextXr*screenWidth,rollNextYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 1343 },200) 1344 context.drawImage(roll,rollNextXr*screenWidth,rollNextYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 1345 },400) 1346 context.drawImage(dice,diceNextXr*screenWidth,diceNextYr*screenHeight,diceWr*screenWidth,diceHr*screenHeight) 1347 context.clearRect(diceRemDataXr*screenWidth,diceRemDataYr*screenHeight,(193/1280)*screenWidth,(53/800)*screenHeight) 1348 } 1349 1350 } 1351 } 1352 1353 else if(pauseClick == 0) 1354 { 1355 RollAnimate = setInterval(function() 1356 { 1357 setTimeout(function() 1358 { 1359 context.clearRect(rollXr*screenWidth,rollYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 1360 },200) 1361 context.drawImage(roll,rollXr*screenWidth,rollYr*screenHeight,rollWr*screenWidth,rollHr*screenHeight) 1362 },400) 1363 context.drawImage(dice,diceXr*screenWidth,diceYr*screenHeight,diceWr*screenWidth,diceHr*screenHeight) 1364 } 1365 1366 },(diceNum-1)*850) 1367 } 1368 return gameWon 1369} 1370 1371 1372 1373
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.