Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. if(!validMove){
  2. int location=0;
  3. if(startY ==0){
  4. location = startX;
  5. }
  6. else{
  7. location = (startY*8)+startX;
  8. }
  9. String pieceLocation = pieceName+".png";
  10. pieces = new JLabel( new ImageIcon(pieceLocation) );
  11. panels = (JPanel)chessBoard.getComponent(location);
  12. panels.add(pieces);
  13. }
  14. else{
  15. if(success){
  16. int location = 56 + (e.getX()/75);
  17. if (c instanceof JLabel){
  18. Container parent = c.getParent();
  19. parent.remove(0);
  20. pieces = new JLabel( new ImageIcon("WhiteQueen.png") );
  21. parent = (JPanel)chessBoard.getComponent(location);
  22. parent.add(pieces);
  23. }
  24. else{
  25. Container parent = (Container)c;
  26. pieces = new JLabel( new ImageIcon("WhiteQueen.png") );
  27. parent = (JPanel)chessBoard.getComponent(location);
  28. parent.add(pieces);
  29. }
  30. }
  31. else{
  32. if (c instanceof JLabel){
  33. Container parent = c.getParent();
  34. parent.remove(0);
  35. parent.add( chessPiece );
  36. }
  37. else {
  38. Container parent = (Container)c;
  39. parent.add( chessPiece );
  40. }
  41. chessPiece.setVisible(true);
  42. }
  43. }
  44.  
  45. //----------------------------------------------------Pawn Moves-------------------------------------------------------------
  46. //White Pawn
  47. if(pieceName.equals("WhitePawn")){
  48. if(startY == 1)
  49. {
  50. if((startX == (e.getX()/75))&&((((e.getY()/75)-startY)==1)||((e.getY()/75)-startY)==2))
  51. {
  52. if((((e.getY()/75)-startY)==2)){
  53. if((!piecePresent(e.getX(), (e.getY())))&&(!piecePresent(e.getX(), (e.getY()+75)))){
  54. validMove = true;
  55. }
  56. else{
  57. validMove = false;
  58. }
  59. }
  60. else{
  61. if((!piecePresent(e.getX(), (e.getY()))))
  62. {
  63. validMove = true;
  64. }
  65. else{
  66. validMove = false;
  67. }
  68. }
  69. }
  70. else{
  71. validMove = false;
  72. }
  73. }
  74. else{
  75. int newY = e.getY()/75;
  76. int newX = e.getX()/75;
  77. if((startX-1 >=0)||(startX +1 <=7))
  78. {
  79. if((piecePresent(e.getX(), (e.getY())))&&((((newX == (startX+1)&&(startX+1<=7)))||((newX == (startX-1))&&(startX-1 >=0)))))
  80. {
  81. if(checkWhiteOponent(e.getX(), e.getY())){
  82. validMove = true;
  83. if(startY == 6){
  84. success = true;
  85. }
  86. }
  87. else{
  88. validMove = false;
  89. }
  90. }
  91. else{
  92. if(!piecePresent(e.getX(), (e.getY()))){
  93. if((startX == (e.getX()/75))&&((e.getY()/75)-startY)==1){
  94. if(startY == 6){
  95. success = true;
  96. }
  97. validMove = true;
  98. }
  99. else{
  100. validMove = false;
  101. }
  102. }
  103. else{
  104. validMove = false;
  105. }
  106. }
  107. }
  108. else{
  109. validMove = false;
  110. }
  111. }
  112. }
  113. //Black Pawn
  114. if(pieceName.equals("BlackPawn")){
  115. if(startY == 6)
  116. {
  117. if((startX == (e.getX()/75))&&((((e.getY()/75)-startY)==-1)||((e.getY()/75)-startY)==-2))
  118. {
  119. if((((e.getY()/75)-startY)==-2)){
  120. if((!piecePresent(e.getX(), (e.getY())))&&(!piecePresent(e.getX(), (e.getY()+75)))){
  121. validMove = true;
  122. }
  123. else{
  124. validMove = false;
  125. }
  126. }
  127. else{
  128. if((!piecePresent(e.getX(), (e.getY()))))
  129. {
  130. validMove = true;
  131. }
  132. else{
  133. validMove = false;
  134. }
  135. }
  136. }
  137. else{
  138. validMove = false;
  139. }
  140. }
  141. else{
  142. int newY = e.getY()/75;
  143. int newX = e.getX()/75;
  144. if((startX-1 >=0)||(startX +1 <=7))
  145. {
  146. if((piecePresent(e.getX(), (e.getY())))&&((((newX == (startX+1)&&(startX+1<=7)))||((newX == (startX-1))&&(startX-1 >=0)))))
  147. {
  148. if(checkBlackOponent(e.getX(), e.getY())){
  149. validMove = true;
  150. if(startY == 1){
  151. success = true;
  152. }
  153. }
  154. else{
  155. validMove = false;
  156. }
  157. }
  158. else{
  159. if(!piecePresent(e.getX(), (e.getY()))){
  160. if((startX == (e.getX()/75))&&((e.getY()/75)-startY)==-1){
  161. if(startY == 2){
  162. success = true;
  163. }
  164. validMove = true;
  165. }
  166. else{
  167. validMove = false;
  168. }
  169. }
  170. else{
  171. validMove = false;
  172. }
  173. }
  174. }
  175. else{
  176. validMove = false;
  177. }
  178. }
  179. }
  180. //------------------------------------------------End of Pawn Moves----------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement