1 package net.sourceforge.simplegamenet.chess;
2
3 public class ChessBishop extends ChessPiece {
4
5 public ChessBishop(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 if (Math.abs(x - destinationX) != Math.abs(y - destinationY)) {
16 return false;
17 } else {
18 for (int i = 1; i < Math.abs(x - destinationX); i++) {
19 if (pieceGrid[(x + (x < destinationX ? i : -i)) * GRID_HEIGHT
20 + (y + (y < destinationY ? i : -i))] != null) {
21 return false;
22 }
23 }
24 return true;
25 }
26 }
27
28 public int getPieceType() {
29 return ChessPieceType.BISHOP;
30 }
31
32 public int getPieceValue() {
33 return 3;
34 }
35
36 }