umar_ahmad

rook1.java

Feb 28th, 2020
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package chess;
  2.  
  3. public class Rook extends Piece{
  4. public Rook(PieceColour colour){
  5. this.colour = colour;
  6. if (colour == PieceColour.WHITE){
  7. setSymbol("\u2656");
  8. }
  9. else {
  10. setSymbol("\u265C");
  11. }
  12. }
  13.  
  14. @Override
  15. public boolean isLegitMove(int iIn, int jIn, int iOut, int jOut){
  16. if ((iIn == iOut) || (jIn == jOut)){
  17. if (iIn == iOut){
  18. if ((jIn - jOut) > 0){
  19. for (int x = jIn - jOut - 1; x > 0; x--){
  20. if (Board.getBoard()[iIn][jIn-x].hasPiece()){
  21. return false;
  22. }
  23. else{
  24. return true;
  25. }
  26. }
  27. }
  28. else{
  29. for (int x = jOut - jIn - 1; x > 0; x--){
  30. if (Board.getBoard()[iIn][jIn+x].hasPiece()){
  31. return false;
  32. }
  33. else{
  34. return true;
  35. }
  36. }
  37. }
  38. }
  39. if (jIn == jOut){
  40. if ((iIn - iOut) > 0){
  41. for (int x = iIn - iOut - 1; x == 0; x--){
  42. if (Board.getBoard()[iIn-x][jIn].hasPiece()){
  43. return false;
  44. }
  45. else{
  46. return true;
  47. }
  48. }
  49. }
  50. else{
  51. for (int x = jOut - jIn - 1; x == 0; x--){
  52. if (Board.getBoard()[iIn+x][jIn].hasPiece()){
  53. return false;
  54. }
  55. else{
  56. return true;
  57. }
  58. }
  59. }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. return false;
  76. }
  77. }
RAW Paste Data