webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java
author Jaroslav Tulach <jtulach@netbeans.org>
Fri, 11 Sep 2009 20:32:15 +0200
changeset 77 d574ac6e44cc
parent 48 webidor/src/main/java/cz/xelfi/quoridor/webidor/GameResult.java@69e897fe8140
child 100 8b899ed24f9f
permissions -rw-r--r--
Displaying who is supposed to move on a given board in the index page
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,
jtulach@77
    39
    blackWon;
jtulach@77
    40
jtulach@77
    41
    /** Creates appropriate status of the game based on the state
jtulach@77
    42
     * on the board.
jtulach@77
    43
     *
jtulach@77
    44
     * @param board the board
jtulach@77
    45
     * @return status describing the situation on the board
jtulach@77
    46
     */
jtulach@77
    47
    public static GameStatus valueOf(Board board) {
jtulach@77
    48
        if (board.getWinner() != null) {
jtulach@77
    49
            return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon;
jtulach@77
    50
        } else {
jtulach@77
    51
            return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove;
jtulach@77
    52
        }
jtulach@77
    53
    }
jaroslav@48
    54
}