package solitaer; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; public class AblageStack extends BaseStack { private static final long serialVersionUID = 1L; private Symbol sym; public AblageStack(int _x, int _y, Symbol _sym) { super(false); super.setLocation(_x, _y); super.setSize(IMAGE_WIDTH, STACK_HIGHT); super.setOpaque(false); super.setLayout(null); this.sym = _sym; } @Override protected boolean cardCheck(Card _topStack, Card _playerCard) { if(_topStack == null && _playerCard == null) { return false; } if(_playerCard.getSymbol() != this.sym) { return false; } else if(_topStack == null) { //nur ein Ass darf auf einen Leeren Stabel gelegt werden return _playerCard.getNr() == 1; } else { return _topStack.getNr() == _playerCard.getNr() - 1; } } @Override protected void paintComponent(Graphics g) { // TODO Auto-generated method stub super.paintComponent(g); if (stackIsEmpty()) { g.setColor(Color.gray); g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); g.setColor(Color.black); g.drawRect(0, 0, this.getWidth()-1, IMAGE_HIGHT-1); if (this.sym == Symbol.Herz || this.sym == Symbol.Karo) g.setColor(Color.red); else g.setColor(Color.black); int fontSize = 20; Font f = new Font(Font.MONOSPACED, Font.BOLD, fontSize); g.setFont(f); String text = this.sym.toString(); g.drawString(text, 5, this.IMAGE_HIGHT/2); } } }