# HG changeset patch # User Jaroslav Tulach # Date 1252693935 -7200 # Node ID d574ac6e44cc36db51e420cb5c8db522c3a63e59 # Parent ff37bdeef2b3ecf136b06a315cb88a5199eb26f9 Displaying who is supposed to move on a given board in the index page diff -r ff37bdeef2b3 -r d574ac6e44cc freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt Fri Sep 11 14:53:12 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt Fri Sep 11 20:32:15 2009 +0200 @@ -24,11 +24,11 @@ <#assign play = false> - <#if doc.game.id.@result = "IN_PROGRESS" > + <#if doc.game.id.@status = "whiteMove" || doc.game.id.@status = "blackMove" > ${bundle("MOVE_WHO", doc.game.@currentPlayer?string)} <#assign play = user = doc.game.@currentPlayer> <#else> - <#if doc.game.id.@result = "WHITE_WON"> + <#if doc.game.id.@status = "whiteWon"> ${bundle("WON", doc.game.id.@white?string)} <#else> ${bundle("WON", doc.game.id.@black?string)} diff -r ff37bdeef2b3 -r d574ac6e44cc freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 14:53:12 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 20:32:15 2009 +0200 @@ -21,7 +21,23 @@
    <#list doc.gameIds.* as g> - <#if (g.@white = user || g.@black = user) && g.@result = "IN_PROGRESS" > + <#if (g.@white = user && g.@status = "whiteMove") || + (g.@black = user && g.@status = "blackMove") + > +
  1. + <@game g/> +
  2. + + +
+ +
${bundle.GAME_WAIT}
+ +
    + <#list doc.gameIds.* as g> + <#if (g.@white = user && g.@status = "blackMove") || + (g.@black = user && g.@status = "whiteMove") + >
  1. <@game g/>
  2. @@ -34,8 +50,8 @@
      <#list doc.gameIds.* as g> <#if - (g.@white = user && g.@result = "WHITE_WON") || - (g.@black = user && g.@result = "BLACK_WON") + (g.@white = user && g.@status = "whiteWon") || + (g.@black = user && g.@status = "blackWon") >
    1. <@game g/> @@ -49,8 +65,8 @@
        <#list doc.gameIds.* as g> <#if - (g.@white = user && g.@result = "BLACK_WON") || - (g.@black = user && g.@result = "WHITE_WON") + (g.@white = user && g.@status = "blackWon") || + (g.@black = user && g.@status = "whiteWon") >
      1. <@game g/> diff -r ff37bdeef2b3 -r d574ac6e44cc freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties Fri Sep 11 14:53:12 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties Fri Sep 11 20:32:15 2009 +0200 @@ -1,7 +1,8 @@ TITLE=Quoridor Community Server gameWhiteBlack={0} vs. {1} BOARD=QuoBoard -GAME_MOVE=In progress games +GAME_MOVE=Your move +GAME_WAIT=Opponent's move GAME_WON=Won games GAME_LOST=Lost games CREATE=Create! diff -r ff37bdeef2b3 -r d574ac6e44cc freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties Fri Sep 11 14:53:12 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties Fri Sep 11 20:32:15 2009 +0200 @@ -1,7 +1,8 @@ TITLE=Komunitn\u00ED server Quoridor gameWhiteBlack={0} proti {1} BOARD=Hrac\u00ED deska -GAME_MOVE=Otev\u0159en\u00E9 +GAME_MOVE=Na tahu +GAME_WAIT=\u010Cek\u00E1 se na tah GAME_WON=Vyhran\u00E9 GAME_LOST=Prohran\u00E9 CREATE=Vytvo\u0159 novou diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 14:53:12 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 20:32:15 2009 +0200 @@ -101,10 +101,7 @@ } board = getBoard().apply(m); - if (board.getWinner() != null) { - GameResult r = board.getWinner() == board.getPlayers().get(0) ? GameResult.WHITE_WON : GameResult.BLACK_WON; - id = new GameId(id.getId(), id.getWhite(), id.getBlack(), id.getStarted(), r); - } + id = new GameId(id.getId(), id.getWhite(), id.getBlack(), id.getStarted(), GameStatus.valueOf(board)); getMoves().add(m); } diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Fri Sep 11 14:53:12 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java Fri Sep 11 20:32:15 2009 +0200 @@ -48,7 +48,7 @@ @XmlAttribute private Date started; @XmlAttribute - private GameResult result; + private GameStatus status; @XmlID @XmlAttribute private String id; @@ -58,16 +58,16 @@ public GameId(String first, String second) { this( UUID.randomUUID().toString(), - first, second, new Date(), GameResult.IN_PROGRESS + first, second, new Date(), GameStatus.whiteMove ); } - public GameId(String id, String first, String second, Date started, GameResult result) { + public GameId(String id, String first, String second, Date started, GameStatus result) { this.white = first; this.black = second; this.id = id; this.started = started; - this.result = result; + this.status = result; } public String getId() { @@ -86,7 +86,7 @@ return started; } - public GameResult getResult() { - return result; + public GameStatus getStatus() { + return status; } } diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/main/java/cz/xelfi/quoridor/webidor/GameResult.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameResult.java Fri Sep 11 14:53:12 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * Portions Copyrighted 2009 Jaroslav Tulach - */ - -package cz.xelfi.quoridor.webidor; - -/** Possible results of the game. - * - * @author Jaroslav Tulach - */ -public enum GameResult { - IN_PROGRESS, WHITE_WON, BLACK_WON; -} diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java Fri Sep 11 20:32:15 2009 +0200 @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * Portions Copyrighted 2009 Jaroslav Tulach + */ + +package cz.xelfi.quoridor.webidor; + +import cz.xelfi.quoridor.Board; + +/** Possible states of the game. + * + * @author Jaroslav Tulach + */ +public enum GameStatus { + whiteMove, + blackMove, + whiteWon, + blackWon; + + /** Creates appropriate status of the game based on the state + * on the board. + * + * @param board the board + * @return status describing the situation on the board + */ + public static GameStatus valueOf(Board board) { + if (board.getWinner() != null) { + return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon; + } else { + return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove; + } + } +} diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java Fri Sep 11 14:53:12 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java Fri Sep 11 20:32:15 2009 +0200 @@ -57,7 +57,7 @@ private final Set types; - private final Class[] cTypes = {Game.class, GameId.class, GameResult.class }; + private final Class[] cTypes = {Game.class, GameId.class, GameStatus.class }; public JAXBContextResolver() throws Exception { this.types = new HashSet(Arrays.asList(cTypes)); diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 14:53:12 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 20:32:15 2009 +0200 @@ -188,7 +188,7 @@ throw new IOException("Missing white and black identification in " + f); } if (g == null) { - GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), GameResult.IN_PROGRESS); + GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), GameStatus.whiteMove); g = new Game(id); } if (line.equals("finish")) { @@ -222,7 +222,7 @@ PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(f))); pw.println("# white: " + g.getId().getWhite()); pw.println("# black: " + g.getId().getBlack()); - pw.println("# status: " + g.getId().getResult()); + pw.println("# status: " + g.getId().getStatus()); int cnt = 0; for (Move m : g.getMoves()) { pw.print(m.toString()); diff -r ff37bdeef2b3 -r d574ac6e44cc webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Fri Sep 11 14:53:12 2009 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Fri Sep 11 20:32:15 2009 +0200 @@ -90,7 +90,7 @@ } Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class); - assertEquals("BlackWins", GameResult.BLACK_WON, end.getId().getResult()); + assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus()); } @Test public void testResignAGame() throws Exception { @@ -100,7 +100,7 @@ webResource.path("games/" + s.getId()).queryParam("player", "Jarda").queryParam("move", "RESIGN").put(GameId.class); Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class); - assertEquals("BlackWins", GameResult.BLACK_WON, end.getId().getResult()); + assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus()); } }