webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java
changeset 100 8b899ed24f9f
parent 79 89bca098e14e
child 115 6a80463a74c0
     1.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java	Sat Sep 12 05:00:28 2009 +0200
     1.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java	Sat Sep 19 14:38:29 2009 +0200
     1.3 @@ -56,6 +56,7 @@
     1.4      @XmlElement
     1.5      @XmlJavaTypeAdapter(MoveAdapter.class)
     1.6      private List<Move> moves;
     1.7 +    private Integer move;
     1.8  
     1.9      Game() {
    1.10      }
    1.11 @@ -115,6 +116,35 @@
    1.12          return moves;
    1.13      }
    1.14  
    1.15 +    @XmlAttribute
    1.16 +    public int getCurrentMove() {
    1.17 +        return move == null ? getMoves().size() : move;
    1.18 +    }
    1.19 +
    1.20 +    public Game snapshot(int move) throws IllegalPositionException {
    1.21 +        Board b = Board.empty();
    1.22 +        int cnt = 0;
    1.23 +        for (Move m : getMoves()) {
    1.24 +            if (move-- <= 0) {
    1.25 +                break;
    1.26 +            }
    1.27 +            b = b.apply(m);
    1.28 +            cnt++;
    1.29 +        }
    1.30 +
    1.31 +        Game g = new Game(
    1.32 +            new GameId(
    1.33 +                id.getId(), id.getWhite(), id.getBlack(),
    1.34 +                new Date(id.getStarted()), new Date(id.getModified()),
    1.35 +                GameStatus.history
    1.36 +            )
    1.37 +        );
    1.38 +        g.board = b;
    1.39 +        g.move = cnt;
    1.40 +        g.moves = new ArrayList<Move>(getMoves());
    1.41 +        return g;
    1.42 +    }
    1.43 +
    1.44      @XmlAccessorType(XmlAccessType.FIELD)
    1.45      private static final class MoveTmp {
    1.46          @XmlAttribute