wsdor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Sep 2010 17:04:51 +0200
changeset 256 1758a7727278
parent 162 webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java@c1bfbe98152b
child 264 d60370059c3c
permissions -rw-r--r--
Splitting classes representing data types on the server into own module
jaroslav@48
     1
/*
jaroslav@48
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jaroslav@48
     3
 *
jaroslav@48
     4
 * The contents of this file are subject to the terms of either the GNU
jaroslav@48
     5
 * General Public License Version 2 only ("GPL") or the Common
jaroslav@48
     6
 * Development and Distribution License("CDDL") (collectively, the
jaroslav@48
     7
 * "License"). You may not use this file except in compliance with the
jaroslav@48
     8
 * License. You can obtain a copy of the License at
jaroslav@48
     9
 * http://www.netbeans.org/cddl-gplv2.html
jaroslav@48
    10
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jaroslav@48
    11
 * specific language governing permissions and limitations under the
jaroslav@48
    12
 * License.  When distributing the software, include this License Header
jaroslav@48
    13
 * Notice in each file and include the License file at
jaroslav@48
    14
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
jaroslav@48
    15
 * particular file as subject to the "Classpath" exception as provided
jaroslav@48
    16
 * by Sun in the GPL Version 2 section of the License file that
jaroslav@48
    17
 * accompanied this code. If applicable, add the following below the
jaroslav@48
    18
 * License Header, with the fields enclosed by brackets [] replaced by
jaroslav@48
    19
 * your own identifying information:
jaroslav@48
    20
 * "Portions Copyrighted [year] [name of copyright owner]"
jaroslav@48
    21
 *
jaroslav@48
    22
 * Contributor(s):
jaroslav@48
    23
 *
jaroslav@48
    24
 * Portions Copyrighted 2009 Jaroslav Tulach
jaroslav@48
    25
 */
jaroslav@48
    26
jaroslav@48
    27
package cz.xelfi.quoridor.webidor;
jaroslav@48
    28
jtulach@77
    29
import cz.xelfi.quoridor.Board;
jtulach@77
    30
jtulach@77
    31
/** Possible states of the game.
jaroslav@48
    32
 *
jaroslav@48
    33
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@48
    34
 */
jtulach@77
    35
public enum GameStatus {
jtulach@77
    36
    whiteMove,
jtulach@77
    37
    blackMove,
jtulach@77
    38
    whiteWon,
jaroslav@100
    39
    blackWon,
jaroslav@100
    40
    history;
jtulach@77
    41
jtulach@77
    42
    /** Creates appropriate status of the game based on the state
jtulach@77
    43
     * on the board.
jtulach@77
    44
     *
jtulach@77
    45
     * @param board the board
jtulach@77
    46
     * @return status describing the situation on the board
jtulach@77
    47
     */
jtulach@77
    48
    public static GameStatus valueOf(Board board) {
jtulach@77
    49
        if (board.getWinner() != null) {
jtulach@77
    50
            return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon;
jtulach@77
    51
        } else {
jtulach@77
    52
            return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove;
jtulach@77
    53
        }
jtulach@77
    54
    }
jaroslav@162
    55
jaroslav@162
    56
    /** @return true if the game is in progress
jaroslav@162
    57
     */
jaroslav@162
    58
    public boolean isInProgress() {
jaroslav@162
    59
        return this == whiteMove || this == blackMove;
jaroslav@162
    60
    }
jaroslav@48
    61
}