author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Tue, 14 Sep 2010 08:56:13 +0200 | |
changeset 264 | d60370059c3c |
parent 256 | 1758a7727278 |
permissions | -rw-r--r-- |
jaroslav@48 | 1 |
/* |
jaroslav@264 | 2 |
* Quoridor server and related libraries |
jaroslav@264 | 3 |
* Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@48 | 4 |
* |
jaroslav@264 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@264 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@264 | 7 |
* the Free Software Foundation, either version 3 of the License. |
jaroslav@48 | 8 |
* |
jaroslav@264 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@264 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@264 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@264 | 12 |
* GNU General Public License for more details. |
jaroslav@48 | 13 |
* |
jaroslav@264 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@264 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@264 | 16 |
* If not, see http://www.gnu.org/licenses/. |
jaroslav@48 | 17 |
*/ |
jaroslav@48 | 18 |
|
jaroslav@48 | 19 |
package cz.xelfi.quoridor.webidor; |
jaroslav@48 | 20 |
|
jtulach@77 | 21 |
import cz.xelfi.quoridor.Board; |
jtulach@77 | 22 |
|
jtulach@77 | 23 |
/** Possible states of the game. |
jaroslav@48 | 24 |
* |
jaroslav@48 | 25 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@48 | 26 |
*/ |
jtulach@77 | 27 |
public enum GameStatus { |
jtulach@77 | 28 |
whiteMove, |
jtulach@77 | 29 |
blackMove, |
jtulach@77 | 30 |
whiteWon, |
jaroslav@100 | 31 |
blackWon, |
jaroslav@100 | 32 |
history; |
jtulach@77 | 33 |
|
jtulach@77 | 34 |
/** Creates appropriate status of the game based on the state |
jtulach@77 | 35 |
* on the board. |
jtulach@77 | 36 |
* |
jtulach@77 | 37 |
* @param board the board |
jtulach@77 | 38 |
* @return status describing the situation on the board |
jtulach@77 | 39 |
*/ |
jtulach@77 | 40 |
public static GameStatus valueOf(Board board) { |
jtulach@77 | 41 |
if (board.getWinner() != null) { |
jtulach@77 | 42 |
return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon; |
jtulach@77 | 43 |
} else { |
jtulach@77 | 44 |
return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove; |
jtulach@77 | 45 |
} |
jtulach@77 | 46 |
} |
jaroslav@162 | 47 |
|
jaroslav@162 | 48 |
/** @return true if the game is in progress |
jaroslav@162 | 49 |
*/ |
jaroslav@162 | 50 |
public boolean isInProgress() { |
jaroslav@162 | 51 |
return this == whiteMove || this == blackMove; |
jaroslav@162 | 52 |
} |
jaroslav@48 | 53 |
} |