Displaying who is supposed to move on a given board in the index page
authorJaroslav Tulach <jtulach@netbeans.org>
Fri, 11 Sep 2009 20:32:15 +0200
changeset 77d574ac6e44cc
parent 76 ff37bdeef2b3
child 78 5ea4172dcf8b
Displaying who is supposed to move on a given board in the index page
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties
freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties
webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java
webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java
webidor/src/main/java/cz/xelfi/quoridor/webidor/GameResult.java
webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java
webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java
webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java
webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java
     1.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt	Fri Sep 11 14:53:12 2009 +0200
     1.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt	Fri Sep 11 20:32:15 2009 +0200
     1.3 @@ -24,11 +24,11 @@
     1.4  
     1.5        <#assign play = false>
     1.6  
     1.7 -      <#if doc.game.id.@result = "IN_PROGRESS" >
     1.8 +      <#if doc.game.id.@status = "whiteMove" || doc.game.id.@status = "blackMove" >
     1.9            ${bundle("MOVE_WHO", doc.game.@currentPlayer?string)}
    1.10            <#assign play = user = doc.game.@currentPlayer>
    1.11        <#else>
    1.12 -        <#if doc.game.id.@result = "WHITE_WON">
    1.13 +        <#if doc.game.id.@status = "whiteWon">
    1.14            ${bundle("WON", doc.game.id.@white?string)}
    1.15          <#else>
    1.16            ${bundle("WON", doc.game.id.@black?string)}
     2.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt	Fri Sep 11 14:53:12 2009 +0200
     2.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt	Fri Sep 11 20:32:15 2009 +0200
     2.3 @@ -21,7 +21,23 @@
     2.4  
     2.5        <ol>
     2.6        <#list doc.gameIds.* as g>
     2.7 -        <#if (g.@white = user || g.@black = user) && g.@result = "IN_PROGRESS" >
     2.8 +        <#if (g.@white = user && g.@status = "whiteMove") ||
     2.9 +             (g.@black = user && g.@status = "blackMove")
    2.10 +        >
    2.11 +            <li>
    2.12 +                <@game g/>
    2.13 +            </li>
    2.14 +        </#if>
    2.15 +      </#list>
    2.16 +      </ol>
    2.17 +
    2.18 +      <h5>${bundle.GAME_WAIT}</h5>
    2.19 +
    2.20 +      <ol>
    2.21 +      <#list doc.gameIds.* as g>
    2.22 +        <#if (g.@white = user && g.@status = "blackMove") ||
    2.23 +             (g.@black = user && g.@status = "whiteMove")
    2.24 +        >
    2.25              <li>
    2.26                  <@game g/>
    2.27              </li>
    2.28 @@ -34,8 +50,8 @@
    2.29        <ol>
    2.30        <#list doc.gameIds.* as g>
    2.31          <#if 
    2.32 -            (g.@white = user && g.@result = "WHITE_WON") ||
    2.33 -            (g.@black = user && g.@result = "BLACK_WON")
    2.34 +            (g.@white = user && g.@status = "whiteWon") ||
    2.35 +            (g.@black = user && g.@status = "blackWon")
    2.36          >
    2.37              <li>
    2.38                  <@game g/>
    2.39 @@ -49,8 +65,8 @@
    2.40        <ol>
    2.41        <#list doc.gameIds.* as g>
    2.42          <#if
    2.43 -            (g.@white = user && g.@result = "BLACK_WON") ||
    2.44 -            (g.@black = user && g.@result = "WHITE_WON")
    2.45 +            (g.@white = user && g.@status = "blackWon") ||
    2.46 +            (g.@black = user && g.@status = "whiteWon")
    2.47          >
    2.48              <li>
    2.49                  <@game g/>
     3.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties	Fri Sep 11 14:53:12 2009 +0200
     3.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.properties	Fri Sep 11 20:32:15 2009 +0200
     3.3 @@ -1,7 +1,8 @@
     3.4  TITLE=<a href="http://en.wikipedia.org/wiki/Quoridor">Quoridor</a> Community Server
     3.5  gameWhiteBlack={0} vs. {1}
     3.6  BOARD=QuoBoard
     3.7 -GAME_MOVE=In progress games
     3.8 +GAME_MOVE=Your move
     3.9 +GAME_WAIT=Opponent's move
    3.10  GAME_WON=Won games
    3.11  GAME_LOST=Lost games
    3.12  CREATE=Create!
     4.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties	Fri Sep 11 14:53:12 2009 +0200
     4.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index_cs.properties	Fri Sep 11 20:32:15 2009 +0200
     4.3 @@ -1,7 +1,8 @@
     4.4  TITLE=Komunitn\u00ED server <a href="http://cs.wikipedia.org/wiki/Quoridor">Quoridor</a>
     4.5  gameWhiteBlack={0} proti {1}
     4.6  BOARD=Hrac\u00ED deska
     4.7 -GAME_MOVE=Otev\u0159en\u00E9
     4.8 +GAME_MOVE=Na tahu
     4.9 +GAME_WAIT=\u010Cek\u00E1 se na tah
    4.10  GAME_WON=Vyhran\u00E9
    4.11  GAME_LOST=Prohran\u00E9
    4.12  CREATE=Vytvo\u0159 novou
     5.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java	Fri Sep 11 14:53:12 2009 +0200
     5.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java	Fri Sep 11 20:32:15 2009 +0200
     5.3 @@ -101,10 +101,7 @@
     5.4          }
     5.5  
     5.6          board = getBoard().apply(m);
     5.7 -        if (board.getWinner() != null) {
     5.8 -            GameResult r = board.getWinner() == board.getPlayers().get(0) ? GameResult.WHITE_WON : GameResult.BLACK_WON;
     5.9 -            id = new GameId(id.getId(), id.getWhite(), id.getBlack(), id.getStarted(), r);
    5.10 -        }
    5.11 +        id = new GameId(id.getId(), id.getWhite(), id.getBlack(), id.getStarted(), GameStatus.valueOf(board));
    5.12          getMoves().add(m);
    5.13      }
    5.14  
     6.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java	Fri Sep 11 14:53:12 2009 +0200
     6.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameId.java	Fri Sep 11 20:32:15 2009 +0200
     6.3 @@ -48,7 +48,7 @@
     6.4      @XmlAttribute
     6.5      private Date started;
     6.6      @XmlAttribute
     6.7 -    private GameResult result;
     6.8 +    private GameStatus status;
     6.9      @XmlID @XmlAttribute
    6.10      private String id;
    6.11  
    6.12 @@ -58,16 +58,16 @@
    6.13      public GameId(String first, String second) {
    6.14          this(
    6.15              UUID.randomUUID().toString(),
    6.16 -            first, second, new Date(), GameResult.IN_PROGRESS
    6.17 +            first, second, new Date(), GameStatus.whiteMove
    6.18          );
    6.19      }
    6.20  
    6.21 -    public GameId(String id, String first, String second, Date started, GameResult result) {
    6.22 +    public GameId(String id, String first, String second, Date started, GameStatus result) {
    6.23          this.white = first;
    6.24          this.black = second;
    6.25          this.id = id;
    6.26          this.started = started;
    6.27 -        this.result = result;
    6.28 +        this.status = result;
    6.29      }
    6.30  
    6.31      public String getId() {
    6.32 @@ -86,7 +86,7 @@
    6.33          return started;
    6.34      }
    6.35  
    6.36 -    public GameResult getResult() {
    6.37 -        return result;
    6.38 +    public GameStatus getStatus() {
    6.39 +        return status;
    6.40      }
    6.41  }
     7.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameResult.java	Fri Sep 11 14:53:12 2009 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,35 +0,0 @@
     7.4 -/*
     7.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.6 - *
     7.7 - * The contents of this file are subject to the terms of either the GNU
     7.8 - * General Public License Version 2 only ("GPL") or the Common
     7.9 - * Development and Distribution License("CDDL") (collectively, the
    7.10 - * "License"). You may not use this file except in compliance with the
    7.11 - * License. You can obtain a copy of the License at
    7.12 - * http://www.netbeans.org/cddl-gplv2.html
    7.13 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    7.14 - * specific language governing permissions and limitations under the
    7.15 - * License.  When distributing the software, include this License Header
    7.16 - * Notice in each file and include the License file at
    7.17 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    7.18 - * particular file as subject to the "Classpath" exception as provided
    7.19 - * by Sun in the GPL Version 2 section of the License file that
    7.20 - * accompanied this code. If applicable, add the following below the
    7.21 - * License Header, with the fields enclosed by brackets [] replaced by
    7.22 - * your own identifying information:
    7.23 - * "Portions Copyrighted [year] [name of copyright owner]"
    7.24 - *
    7.25 - * Contributor(s):
    7.26 - *
    7.27 - * Portions Copyrighted 2009 Jaroslav Tulach
    7.28 - */
    7.29 -
    7.30 -package cz.xelfi.quoridor.webidor;
    7.31 -
    7.32 -/** Possible results of the game.
    7.33 - *
    7.34 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    7.35 - */
    7.36 -public enum GameResult {
    7.37 -    IN_PROGRESS, WHITE_WON, BLACK_WON;
    7.38 -}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/GameStatus.java	Fri Sep 11 20:32:15 2009 +0200
     8.3 @@ -0,0 +1,54 @@
     8.4 +/*
     8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 + *
     8.7 + * The contents of this file are subject to the terms of either the GNU
     8.8 + * General Public License Version 2 only ("GPL") or the Common
     8.9 + * Development and Distribution License("CDDL") (collectively, the
    8.10 + * "License"). You may not use this file except in compliance with the
    8.11 + * License. You can obtain a copy of the License at
    8.12 + * http://www.netbeans.org/cddl-gplv2.html
    8.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    8.14 + * specific language governing permissions and limitations under the
    8.15 + * License.  When distributing the software, include this License Header
    8.16 + * Notice in each file and include the License file at
    8.17 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    8.18 + * particular file as subject to the "Classpath" exception as provided
    8.19 + * by Sun in the GPL Version 2 section of the License file that
    8.20 + * accompanied this code. If applicable, add the following below the
    8.21 + * License Header, with the fields enclosed by brackets [] replaced by
    8.22 + * your own identifying information:
    8.23 + * "Portions Copyrighted [year] [name of copyright owner]"
    8.24 + *
    8.25 + * Contributor(s):
    8.26 + *
    8.27 + * Portions Copyrighted 2009 Jaroslav Tulach
    8.28 + */
    8.29 +
    8.30 +package cz.xelfi.quoridor.webidor;
    8.31 +
    8.32 +import cz.xelfi.quoridor.Board;
    8.33 +
    8.34 +/** Possible states of the game.
    8.35 + *
    8.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    8.37 + */
    8.38 +public enum GameStatus {
    8.39 +    whiteMove,
    8.40 +    blackMove,
    8.41 +    whiteWon,
    8.42 +    blackWon;
    8.43 +
    8.44 +    /** Creates appropriate status of the game based on the state
    8.45 +     * on the board.
    8.46 +     *
    8.47 +     * @param board the board
    8.48 +     * @return status describing the situation on the board
    8.49 +     */
    8.50 +    public static GameStatus valueOf(Board board) {
    8.51 +        if (board.getWinner() != null) {
    8.52 +            return board.getWinner() == board.getPlayers().get(0) ? GameStatus.whiteWon : GameStatus.blackWon;
    8.53 +        } else {
    8.54 +            return board.getCurrentPlayer() == board.getPlayers().get(0) ? GameStatus.whiteMove : GameStatus.blackMove;
    8.55 +        }
    8.56 +    }
    8.57 +}
     9.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java	Fri Sep 11 14:53:12 2009 +0200
     9.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java	Fri Sep 11 20:32:15 2009 +0200
     9.3 @@ -57,7 +57,7 @@
     9.4      
     9.5      private final Set<Class> types;
     9.6      
     9.7 -    private final Class[] cTypes = {Game.class, GameId.class, GameResult.class };
     9.8 +    private final Class[] cTypes = {Game.class, GameId.class, GameStatus.class };
     9.9      
    9.10      public JAXBContextResolver() throws Exception {
    9.11          this.types = new HashSet(Arrays.asList(cTypes));
    10.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java	Fri Sep 11 14:53:12 2009 +0200
    10.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java	Fri Sep 11 20:32:15 2009 +0200
    10.3 @@ -188,7 +188,7 @@
    10.4                  throw new IOException("Missing white and black identification in " + f);
    10.5              }
    10.6              if (g == null) {
    10.7 -                GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), GameResult.IN_PROGRESS);
    10.8 +                GameId id = new GameId(f.getName(), white, black, new Date(f.lastModified()), GameStatus.whiteMove);
    10.9                  g = new Game(id);
   10.10              }
   10.11              if (line.equals("finish")) {
   10.12 @@ -222,7 +222,7 @@
   10.13          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(f)));
   10.14          pw.println("# white: " + g.getId().getWhite());
   10.15          pw.println("# black: " + g.getId().getBlack());
   10.16 -        pw.println("# status: " + g.getId().getResult());
   10.17 +        pw.println("# status: " + g.getId().getStatus());
   10.18          int cnt = 0;
   10.19          for (Move m : g.getMoves()) {
   10.20              pw.print(m.toString());
    11.1 --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java	Fri Sep 11 14:53:12 2009 +0200
    11.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java	Fri Sep 11 20:32:15 2009 +0200
    11.3 @@ -90,7 +90,7 @@
    11.4          }
    11.5  
    11.6          Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class);
    11.7 -        assertEquals("BlackWins", GameResult.BLACK_WON, end.getId().getResult());
    11.8 +        assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus());
    11.9      }
   11.10  
   11.11      @Test public void testResignAGame() throws Exception {
   11.12 @@ -100,7 +100,7 @@
   11.13  
   11.14          webResource.path("games/" + s.getId()).queryParam("player", "Jarda").queryParam("move", "RESIGN").put(GameId.class);
   11.15          Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class);
   11.16 -        assertEquals("BlackWins", GameResult.BLACK_WON, end.getId().getResult());
   11.17 +        assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus());
   11.18      }
   11.19  
   11.20  }