1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Aug 11 14:51:47 2009 +0200
1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Aug 11 15:17:23 2009 +0200
1.3 @@ -42,6 +42,7 @@
1.4 import java.util.Iterator;
1.5 import java.util.List;
1.6 import java.util.Map;
1.7 +import javax.ws.rs.DefaultValue;
1.8 import javax.ws.rs.GET;
1.9 import javax.ws.rs.Path;
1.10 import javax.ws.rs.PathParam;
1.11 @@ -81,13 +82,34 @@
1.12 }
1.13
1.14 @GET
1.15 - @Path("games/{id}")
1.16 + @Path("games/{id}/")
1.17 public Viewable board(@PathParam("id") String id) throws JSONException {
1.18 Object obj = convert(base.path("games").path(id).accept(MediaType.TEXT_PLAIN_TYPE).get(String.class));
1.19 return new Viewable("game.fmt", obj);
1.20 }
1.21
1.22 @GET
1.23 + @Path("games/{id}/move")
1.24 + public Viewable move(
1.25 + @PathParam("id") String id,
1.26 + @QueryParam("type") String type,
1.27 + @QueryParam("direction") String direction,
1.28 + @QueryParam("direction-next") @DefaultValue("") String directionNext,
1.29 + @QueryParam("column") @DefaultValue("") String column,
1.30 + @QueryParam("row") @DefaultValue("") String row
1.31 + ) throws JSONException {
1.32 + if (type.equals("fence")) {
1.33 + base.path("games").path(id).queryParam("move", direction.charAt(0) + column + row).post();
1.34 + return board(id);
1.35 + }
1.36 + if (type.equals("move")) {
1.37 + base.path("games").path(id).queryParam("move", direction + directionNext);
1.38 + return board(id);
1.39 + }
1.40 + return board(id);
1.41 + }
1.42 +
1.43 + @GET
1.44 @Path("games/create")
1.45 public Viewable create(
1.46 @QueryParam("white") String white,
2.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt Tue Aug 11 14:51:47 2009 +0200
2.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/game.fmt Tue Aug 11 15:17:23 2009 +0200
2.3 @@ -6,6 +6,51 @@
2.4 </head>
2.5 <body>
2.6 <h1>Game</h1>
2.7 + <form action="move">
2.8 + <input type="hidden" name="type" value="fence" readonly="readonly"/>
2.9 + <select name="column">
2.10 + <option>A</option>
2.11 + <option>B</option>
2.12 + <option>C</option>
2.13 + <option>D</option>
2.14 + <option>E</option>
2.15 + <option>F</option>
2.16 + <option>G</option>
2.17 + <option>H</option>
2.18 + </select>
2.19 + <select name="row">
2.20 + <option>1</option>
2.21 + <option>2</option>
2.22 + <option>3</option>
2.23 + <option>4</option>
2.24 + <option>5</option>
2.25 + <option>6</option>
2.26 + <option>7</option>
2.27 + <option>8</option>
2.28 + </select>
2.29 + <select name="direction">
2.30 + <option>horizontal</option>
2.31 + <option>vertical</option>
2.32 + </select>
2.33 + <input type="submit" value="Place!" />
2.34 + </form>
2.35 + <form action="move">
2.36 + <input type="hidden" name="type" value="move" readonly="readonly"/>
2.37 + <select name="direction">
2.38 + <option>E</option>
2.39 + <option>W</option>
2.40 + <option>N</option>
2.41 + <option>S</option>
2.42 + </select>
2.43 + <select name="direction-next">
2.44 + <option></option>
2.45 + <option>E</option>
2.46 + <option>W</option>
2.47 + <option>N</option>
2.48 + <option>S</option>
2.49 + </select>
2.50 + <input type="submit" value="Move!" />
2.51 + </form>
2.52 <pre>${model}</pre>
2.53 </body>
2.54 </html>
2.55 \ No newline at end of file
3.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Tue Aug 11 14:51:47 2009 +0200
3.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Tue Aug 11 15:17:23 2009 +0200
3.3 @@ -9,7 +9,7 @@
3.4
3.5 <ol>
3.6 <#list model as item>
3.7 - <li>${item.white} vs. ${item.black} <a href="games/${item.id}">board</a></li>
3.8 + <li>${item.white} vs. ${item.black} <a href="games/${item.id}/">board</a></li>
3.9 </#list>
3.10 </ol>
3.11 <form action="games/create">