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
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 * Rook class.
29 *
30 * @author Matthew Smalley
31 */
32 public class Rook extends Piece {
33
34 /*** White starting positions. * */
35 public static final String WHITE_STARTING_POSITIONS = "a1:h1";
36
37 /*** Black starting positions. * */
38 public static final String BLACK_STARTING_POSITIONS = "a8:h8";
39
40 /***
41 * Constructs the Rook.
42 *
43 * @param team
44 * the team.
45 */
46 public Rook(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 if (!move.isStraight()) {
68 throw new InvalidMoveException(
69 "Invalid move. Rooks can only move in a straight line!");
70 }
71
72 }
73
74 }