View Javadoc

1   package net.sourceforge.simplegamenet.chess;
2   
3   public class ChessQueen extends ChessPiece {
4   
5       public ChessQueen(int participantOwnerIndex, int x, int y) {
6           super(participantOwnerIndex, x, y);
7       }
8   
9       public boolean isMoveAllowed(ChessPiece[] pieceGrid,
10                                   int destinationX, int destinationY) {
11          if (pieceGrid[destinationX * GRID_HEIGHT + destinationY] != null
12                  && pieceGrid[destinationX * GRID_HEIGHT + destinationY]
13                  .getParticipantsOwnerIndex() == participantOwnerIndex) {
14              return false;
15          } else {
16              if (x == destinationX) {
17                  for (int i = 1; i < Math.abs(y - destinationY); i++) {
18                      if (pieceGrid[x * GRID_HEIGHT
19                              + (y + (y < destinationY ? i : -i))] != null) {
20                          return false;
21                      }
22                  }
23                  return true;
24              } else if (y == destinationY) {
25                  for (int i = 1; i < Math.abs(x - destinationX); i++) {
26                      if (pieceGrid[(x + (x < destinationX ? i : -i)) * GRID_HEIGHT
27                              + y] != null) {
28                          return false;
29                      }
30                  }
31                  return true;
32              } else if (Math.abs(x - destinationX) == Math.abs(y - destinationY)) {
33                  for (int i = 1; i < Math.abs(x - destinationX); i++) {
34                      if (pieceGrid[(x + (x < destinationX ? i : -i)) * GRID_HEIGHT
35                              + (y + (y < destinationY ? i : -i))] != null) {
36                          return false;
37                      }
38                  }
39                  return true;
40              } else {
41                  return false;
42              }
43          }
44      }
45  
46      public int getPieceType() {
47          return ChessPieceType.QUEEN;
48      }
49  
50      public int getPieceValue() {
51          return 7;
52      }
53  
54  }