/
Registry.java
52 lines (39 loc) · 1.1 KB
/
Registry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package usantatecla.tictactoe.models;
import java.util.ArrayList;
public class Registry {
private ArrayList<GameMemento> mementoList;
private Game game;
private int firstPrevious;
Registry(Game game) {
this.game = game;
this.mementoList = new ArrayList<GameMemento>();
// this.mementoList.add(firstPrevious, this.game.createMemento());
this.firstPrevious = 0;
}
void registry() {
for (int i = 0; i < this.firstPrevious; i++) {
this.mementoList.remove(0);
}
this.firstPrevious = 0;
this.mementoList.add(this.firstPrevious, this.game.createMemento());
}
void undo(Game game) {
this.firstPrevious++;
game.set(this.mementoList.get(this.firstPrevious));
}
void redo(Game game) {
this.firstPrevious--;
game.set(this.mementoList.get(this.firstPrevious));
}
boolean undoable() {
return this.firstPrevious < this.mementoList.size() - 1;
}
boolean redoable() {
return this.firstPrevious >= 1;
}
void reset() {
this.mementoList = new ArrayList<GameMemento>();
// this.mementoList.add(firstPrevious, this.game.createMemento());
this.firstPrevious = 0;
}
}