// Copyright Sven-Olof Nystrom Uppsala University 2025

import java.util.*;
import java.awt.geom.Point2D;
import java.awt.*;

public abstract class Pile {
    private int x;
    private int y;

    private ArrayList<Card> cards = new ArrayList<Card>();
        
    public Pile (int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX(){
        return x;
    }

    public int getY(){
        return y;
    }
    
    public Card top() {
        if(cards.size()==0) {
            return null;
        }
        else {
            return cards.get(cards.size()-1);
        }
    }

    public Card pop() {
        int i = cards.size()-1;
        Card r = cards.get(i);
        cards.remove(i);
        return r;
    }

    public boolean isEmpty() {
        return cards.size() == 0;
    }

    public int size () {
        return cards.size();
    }

    
    public int crownX() {
        if (isEmpty()) {
            return x;
        }
        else {
            return top().getX();
        }
    }
        
    public int crownY() {
        if (isEmpty()) {
            return y;
        }
        else {
            return top().getY();
        }
    }

    
    public boolean canAccept(Card c) {
        return false;
    }
            
    public boolean contains (int x1, int y1) {
	if (crownX() <= x1 && x1 <= crownX() + Card.WIDTH
            && crownY() <= y1 && y1 <= crownY() + Card.HEIGHT) {
            return true;
        }
        return false;
    }

    public boolean canRelease() {
        return false;
    }
    
    public boolean isCompleted() {
        return false;
    }
    
    public void add(Card c) {
	c.move(x,y);
        cards.add(c);
    }

    public void click() {} 

    public void draw(Graphics g) {
	g.setColor(Color.YELLOW);
        g.fillRect(x, y, Card.WIDTH, Card.HEIGHT);
        for (Card c : cards) {
	    c.draw(g);
	}

    }

}

