Add the transformations stack code.
[TP_POO.git] / TP2 / Piletransformations.java
CommitLineData
14d4fd0d
JB
1
2class Piletransformations {
3 private Point[] transformations;
4 private int currentTransformation;
5
6 Piletransformations(int size) {
7 transformations = new Point[size];
8 for (int i = 0; i < transformations.length; i++) {
9 transformations[i] = new Point(0, 0);
10 }
11 currentTransformation = 0;
12 }
13
14 public Point getCurrentTransformation() {
15 if (isEmpty()) {
16 return transformations[currentTransformation];
17 } else {
18 return transformations[currentTransformation - 1];
19 }
20 }
21
22 private boolean isEmpty() {
23 return (currentTransformation == 0);
24 }
25
26 private boolean isFull() {
27 return (currentTransformation >= transformations.length);
28 }
29
30 public boolean empiler(Point p) {
31 boolean rtVal = false;
32 if (isEmpty()) {
33 transformations[currentTransformation] = p;
34 currentTransformation++;
35 rtVal = true;
36 } else if (!isFull()) {
37 transformations[currentTransformation] = transformations[currentTransformation - 1].additionner(p);
38 currentTransformation++;
39 rtVal = true;
40 }
41 return rtVal;
42 }
43
44 public Point depiler() {
45 if(!isEmpty()) {
46 currentTransformation--;
47 return transformations[currentTransformation];
48 } else {
49 return transformations[currentTransformation];
50 }
51 }
52
53 public void display() {
54 System.out.println("----");
55 for (int i = 0; i < transformations.length; i++) {
56 System.out.println(transformations[i].toString());
57 }
58 }
59
60}