+++ /dev/null
-
-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());
- }
- }
-
-}