X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exo4%2FPiletransformations.java;fp=exo4%2FPiletransformations.java;h=5e53ddd7e3500a9fe421ab290b388a4478658075;hb=c05c228927b2d9141cbc27e467e252e5e83263cf;hp=0000000000000000000000000000000000000000;hpb=01bad5b37bf95f027f583e1b1da607e074050651;p=Project_POO.git diff --git a/exo4/Piletransformations.java b/exo4/Piletransformations.java new file mode 100644 index 0000000..5e53ddd --- /dev/null +++ b/exo4/Piletransformations.java @@ -0,0 +1,60 @@ + +class Piletransformations { + private Point[] transformations; + private int currentTransformation; + + Piletransformations(int size) { + transformations = new Point[size]; + for (int i = 0; i < transformations.length; i++) { + transformations[i] = new Point(0, 0); + } + currentTransformation = 0; + } + + public Point getCurrentTransformation() { + if (isEmpty()) { + return transformations[currentTransformation]; + } else { + return transformations[currentTransformation - 1]; + } + } + + private boolean isEmpty() { + return (currentTransformation == 0); + } + + private boolean isFull() { + return (currentTransformation >= transformations.length); + } + + public boolean empiler(Point p) { + boolean rtVal = false; + if (isEmpty()) { + transformations[currentTransformation] = p; + currentTransformation++; + rtVal = true; + } else if (!isFull()) { + transformations[currentTransformation] = transformations[currentTransformation - 1].additionner(p); + currentTransformation++; + rtVal = true; + } + return rtVal; + } + + public Point depiler() { + if(!isEmpty()) { + currentTransformation--; + return transformations[currentTransformation]; + } else { + return transformations[currentTransformation]; + } + } + + public void display() { + System.out.println("----"); + for (int i = 0; i < currentTransformation; i++) { + System.out.println(transformations[i].toString()); + } + } + +}