View Javadoc

1   /**************************************************************************
2    Copyright 2005 Webstersmalley
3   
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7   
8    http://www.apache.org/licenses/LICENSE-2.0
9   
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15   *************************************************************************/
16  /*
17   * Created on 23-Aug-2005
18   */
19  package com.webstersmalley.chessweb.model.pieces;
20  
21  import com.webstersmalley.chessweb.model.Board;
22  import com.webstersmalley.chessweb.model.InvalidMoveException;
23  import com.webstersmalley.chessweb.model.Move;
24  import com.webstersmalley.chessweb.model.Piece;
25  import com.webstersmalley.chessweb.model.Team;
26  
27  /***
28   * Queen class.
29   * 
30   * @author Matthew Smalley
31   */
32  public class Queen extends Piece {
33  
34      /*** White starting positions. * */
35      public static final String WHITE_STARTING_POSITIONS = "d1";
36  
37      /*** Black starting positions. * */
38      public static final String BLACK_STARTING_POSITIONS = "d8";
39  
40      /***
41       * Constructs the Queen.
42       * 
43       * @param team
44       *            the team.
45       */
46      public Queen(final Team team) {
47          super(team);
48          if (team == Team.WHITE) {
49              setStartingPositions(WHITE_STARTING_POSITIONS);
50          } else {
51              setStartingPositions(BLACK_STARTING_POSITIONS);
52          }
53      }
54  
55      /***
56       * Validates the direction.
57       * 
58       * @param move
59       *            the move
60       * @param board
61       *            the board
62       * @throws InvalidMoveException
63       *             if the move is invalid.
64       */
65      public final void validateDirection(final Move move, final Board board)
66              throws InvalidMoveException {
67  
68          if (move.isDiagonal() || move.isStraight()) {
69              return;
70          }
71          throw new InvalidMoveException(
72                  "Invalid move. Queens must move in a diagonal "
73                      + "or a straight line!");
74      }
75  
76  }