diff --git a/src/main/java/solitaer/BaseStack.java b/src/main/java/solitaer/BaseStack.java index 7300cb9..aabbc6f 100644 --- a/src/main/java/solitaer/BaseStack.java +++ b/src/main/java/solitaer/BaseStack.java @@ -18,6 +18,15 @@ public abstract class BaseStack extends JPanel { public boolean stackIsEmpty() { return stack.isEmpty(); } + + public Card peekLastCard() { + if(!stackIsEmpty()) { + return stack.get(stack.size()-1); + } else { + return null; + } + + } public void addCard(Card _card) { _card.setLocation(0, offset); diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 1933d7a..af55cfc 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -69,7 +69,8 @@ public class Card extends JPanel { @Override public String toString() { - return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; + //return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; + return "Card NR="+nr+" | Symbole="+symbol+" | Face="+faceUp; } @Override diff --git a/src/main/java/solitaer/MyMouseListener.java b/src/main/java/solitaer/MyMouseListener.java index 7a29a4b..140c2a9 100644 --- a/src/main/java/solitaer/MyMouseListener.java +++ b/src/main/java/solitaer/MyMouseListener.java @@ -7,6 +7,15 @@ import javax.swing.SwingUtilities; import javax.swing.event.MouseInputListener; public class MyMouseListener implements MouseInputListener { + + private SaveStack save; + private BaseStack tempStack; + private Card tempCard; + + public MyMouseListener(SaveStack _save) { + // TODO Auto-generated constructor stub + this.save = _save; + } @Override public void mouseClicked(MouseEvent e) { @@ -32,9 +41,27 @@ public class MyMouseListener implements MouseInputListener { } //Karte, die in einem StartStack liegt else if(com instanceof Card && com.getParent() instanceof StartStack) { - System.out.println("Karte in StartStack"+com.toString()); + tempCard = (Card) com; + tempStack = (StartStack) com.getParent(); + + //Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um + if(!tempCard.isFaceUp()) { + if(tempStack.peekLastCard().equals(tempCard)) { + tempCard.setFaceUp(true); + tempCard.repaint(); + System.out.println("Turn"+tempCard.toString()); + } + + + } + + + //System.out.println("Karte in StartStack"+com.toString()); + + + - ((BaseStack)com.getParent()).removeLastCard(); + //save.addCard(((BaseStack)com.getParent()).removeLastCard());; } } diff --git a/src/main/java/solitaer/SaveStack.java b/src/main/java/solitaer/SaveStack.java new file mode 100644 index 0000000..d95974f --- /dev/null +++ b/src/main/java/solitaer/SaveStack.java @@ -0,0 +1,38 @@ +package solitaer; + +import java.awt.Color; +import java.awt.Graphics; + +public class SaveStack extends BaseStack { + + private static final long serialVersionUID = 1L; + + public SaveStack(int _x, int _y) { + // TODO Auto-generated constructor stub + super(); + super.setLocation(_x, _y); + super.setSize(72, 450); + super.setOpaque(false); + super.setLayout(null); + } + + @Override + protected boolean cardCheck(Card _topStack, Card _playerCard) { + // TODO Auto-generated method stub + return false; + } + + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + if (stackIsEmpty()) { + g.setColor(Color.pink); + g.fillRect(0, 0, this.getWidth(), 96); + + g.setColor(Color.black); + g.drawRect(0, 0, this.getWidth() - 1, 96 - 1); + } + } + +} diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index bfe5a90..14ab7cf 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -10,12 +10,14 @@ public class SolitaerGamePanel extends JPanel { private static final long serialVersionUID = 1L; private CardDeck deck; private MyMouseListener mouseL; + + private SaveStack save =new SaveStack(500,250); public SolitaerGamePanel() { setLayout(null); - mouseL = new MyMouseListener(); + mouseL = new MyMouseListener(save); this.addMouseListener(mouseL); @@ -25,12 +27,18 @@ public class SolitaerGamePanel extends JPanel { StartStack a = new StartStack(25,25); a.addCard(deck.getDeck().get(0)); - deck.getDeck().get(1).setFaceUp(true); + deck.getDeck().get(1).setFaceUp(false); a.addCard((deck.getDeck().get(1))); this.add(a); StartStack b = new StartStack(200,25); this.add(b); + + //save = new SaveStack(500,250); + this.add(save); + + + }