Isoraqathedh

Repetition

Jun 3rd, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Convert this */
  2.  
  3. case "P": // Pawn
  4.     var diff = (this.side === 1) ? 1 : -1; //Check south if black, north if white
  5.     game.detect.singleSquareCheck(this.xpos, this.ypos + 1, 0, legalMoves);
  6.     game.detect.singleSquareCheck(this.xpos, this.ypos - 1, 0, legalMoves);
  7.     game.detect.singleSquareCheck(this.xpos + 1, this.ypos, 0, legalMoves);
  8.     game.detect.singleSquareCheck(this.xpos - 1, this.ypos, 0, legalMoves);
  9.     game.detect.singleSquareCheck(this.xpos + 1, this.ypos - diff, 0, legalMoves);
  10.     game.detect.singleSquareCheck(this.xpos - 1, this.ypos - diff, 0, legalMoves);
  11.     game.detect.singleSquareCheck(this.xpos, this.ypos + 1, enemy, legalMoves);
  12.     game.detect.singleSquareCheck(this.xpos, this.ypos - 1, enemy, legalMoves);
  13.     game.detect.singleSquareCheck(this.xpos + 1, this.ypos, enemy, legalMoves);
  14.     game.detect.singleSquareCheck(this.xpos - 1, this.ypos, enemy, legalMoves);
  15.     game.detect.singleSquareCheck(this.xpos + 1, this.ypos - diff, enemy, legalMoves);
  16.     game.detect.singleSquareCheck(this.xpos - 1, this.ypos - diff, enemy, legalMoves);
  17. break;
  18.  
  19. /* Into a single call using a function similar to this */
  20.  
  21. "multiSquareCheck": function() {
  22.     var args = Array.prototype.slice.call(arguments);
  23.     for (i = 0; i < args.length; i++) {
  24.         game.detect.singleSquareCheck(args[i][0], args[i][1], args[i][2], args[i][3]);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment