diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 76cc107..a5b7128 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -1,7 +1,10 @@ package solitaer; +import java.awt.Graphics; +import java.awt.Image; import java.util.Objects; +import javax.swing.ImageIcon; import javax.swing.JPanel; enum Symbol { @@ -9,20 +12,31 @@ enum Symbol { } public class Card extends JPanel { - + /** * */ private static final long serialVersionUID = 1L; private int nr; private Symbol symbol; - + private boolean faceUp; + private Image Up; + private Image back; + public Card(int nr, Symbol symbol, boolean faceUp) { + this.setSize(72,96); this.nr = nr; this.symbol = symbol; this.faceUp = faceUp; + + String cardName = "" + getFileNr() + getFileSymbole(); + ImageIcon iiup = new ImageIcon(getClass().getResource("images/" + cardName + ".png")); + Up = iiup.getImage(); + + ImageIcon iiback = new ImageIcon(getClass().getResource("images/back.png")); + back = iiback.getImage(); } public boolean isFaceUp() { @@ -37,10 +51,41 @@ public class Card extends JPanel { return nr; } + private String getFileNr() { + if (this.nr < 10) { + return "0" + this.nr; + } else { + return "" + this.nr; + } + } + public Symbol getSymbol() { return symbol; } + private String getFileSymbole() { + switch (this.symbol) { + case Herz: + return "Herz"; + case Karo: + return "Karo"; + case Pik: + return "Pik"; + case Kreuz: + return "Kreuz"; + default: + return null; + } + } + + public Image getImage() { + if (faceUp) { + return Up; + } else { + return back; + } + } + @Override public String toString() { return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; @@ -63,6 +108,11 @@ public class Card extends JPanel { return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; } - + @Override + protected void paintComponent(Graphics g) { + // TODO Auto-generated method stub + super.paintComponent(g); + g.drawImage(getImage(), 0, 0, this.getWidth(), this.getHeight(), this); + } } diff --git a/src/main/java/solitaer/SolitaerGamePanel.java b/src/main/java/solitaer/SolitaerGamePanel.java index 520ae04..73fc4d0 100644 --- a/src/main/java/solitaer/SolitaerGamePanel.java +++ b/src/main/java/solitaer/SolitaerGamePanel.java @@ -16,6 +16,8 @@ public class SolitaerGamePanel extends JPanel { public SolitaerGamePanel() { setLayout(null); StartStack a = new StartStack(25,25); + a.addCard(new Card(13, Symbol.Karo, true)); + a.addCard(new Card(1, Symbol.Karo, true)); this.add(a); } diff --git a/src/main/java/solitaer/StartStack.java b/src/main/java/solitaer/StartStack.java index 79b3242..2ab0504 100644 --- a/src/main/java/solitaer/StartStack.java +++ b/src/main/java/solitaer/StartStack.java @@ -11,24 +11,39 @@ public class StartStack extends JPanel { private static final long serialVersionUID = 1L; private Image im; - private ArrayList Stack = new ArrayList(); - - + private ArrayList stack = new ArrayList(); public StartStack(int _x, int _y) { super.setLocation(_x, _y); - super.setSize(72,450); + super.setSize(72, 450); super.setOpaque(false); super.setLayout(null); } + public void addCard(Card _card) { + stack.add(_card); + System.out.println("dfsfdsf"); + addtoPanel(); + } + + void addtoPanel() { + + this.removeAll(); + for(int i = stack.size()-1; i>=0; i-- ) { + System.out.println("for"); + this.add(stack.get(i)); + } + } + @Override protected void paintComponent(Graphics g) { // TODO Auto-generated method stub super.paintComponent(g); - ImageIcon ii = new ImageIcon(getClass().getResource("images/back.png")); - im = ii.getImage(); - g.drawImage(im, 0, 0, this.getWidth(), 96, this); + if (stack.size() == 0) { + ImageIcon ii = new ImageIcon(getClass().getResource("images/back.png")); + im = ii.getImage(); + g.drawImage(im, 0, 0, this.getWidth(), 96, this); + } } } diff --git a/src/main/java/solitaer/images/01Herz.png b/src/main/java/solitaer/images/01Herz.png new file mode 100644 index 0000000..62d0956 Binary files /dev/null and b/src/main/java/solitaer/images/01Herz.png differ diff --git a/src/main/java/solitaer/images/01Karo.png b/src/main/java/solitaer/images/01Karo.png new file mode 100644 index 0000000..73b0128 Binary files /dev/null and b/src/main/java/solitaer/images/01Karo.png differ diff --git a/src/main/java/solitaer/images/01Kreuz.png b/src/main/java/solitaer/images/01Kreuz.png new file mode 100644 index 0000000..a202c88 Binary files /dev/null and b/src/main/java/solitaer/images/01Kreuz.png differ diff --git a/src/main/java/solitaer/images/01Pik.png b/src/main/java/solitaer/images/01Pik.png new file mode 100644 index 0000000..faa496e Binary files /dev/null and b/src/main/java/solitaer/images/01Pik.png differ diff --git a/src/main/java/solitaer/images/02Herz.png b/src/main/java/solitaer/images/02Herz.png new file mode 100644 index 0000000..559fbbe Binary files /dev/null and b/src/main/java/solitaer/images/02Herz.png differ diff --git a/src/main/java/solitaer/images/02Karo.png b/src/main/java/solitaer/images/02Karo.png new file mode 100644 index 0000000..028c276 Binary files /dev/null and b/src/main/java/solitaer/images/02Karo.png differ diff --git a/src/main/java/solitaer/images/02Kreuz.png b/src/main/java/solitaer/images/02Kreuz.png new file mode 100644 index 0000000..8a0fd46 Binary files /dev/null and b/src/main/java/solitaer/images/02Kreuz.png differ diff --git a/src/main/java/solitaer/images/02Pik.png b/src/main/java/solitaer/images/02Pik.png new file mode 100644 index 0000000..0a1e274 Binary files /dev/null and b/src/main/java/solitaer/images/02Pik.png differ diff --git a/src/main/java/solitaer/images/03Herz.png b/src/main/java/solitaer/images/03Herz.png new file mode 100644 index 0000000..05c7794 Binary files /dev/null and b/src/main/java/solitaer/images/03Herz.png differ diff --git a/src/main/java/solitaer/images/03Karo.png b/src/main/java/solitaer/images/03Karo.png new file mode 100644 index 0000000..da7c45d Binary files /dev/null and b/src/main/java/solitaer/images/03Karo.png differ diff --git a/src/main/java/solitaer/images/03Kreuz.png b/src/main/java/solitaer/images/03Kreuz.png new file mode 100644 index 0000000..aac5c92 Binary files /dev/null and b/src/main/java/solitaer/images/03Kreuz.png differ diff --git a/src/main/java/solitaer/images/03Pik.png b/src/main/java/solitaer/images/03Pik.png new file mode 100644 index 0000000..16ebe5b Binary files /dev/null and b/src/main/java/solitaer/images/03Pik.png differ diff --git a/src/main/java/solitaer/images/04Herz.png b/src/main/java/solitaer/images/04Herz.png new file mode 100644 index 0000000..abf7b19 Binary files /dev/null and b/src/main/java/solitaer/images/04Herz.png differ diff --git a/src/main/java/solitaer/images/04Karo.png b/src/main/java/solitaer/images/04Karo.png new file mode 100644 index 0000000..4c37a84 Binary files /dev/null and b/src/main/java/solitaer/images/04Karo.png differ diff --git a/src/main/java/solitaer/images/04Kreuz.png b/src/main/java/solitaer/images/04Kreuz.png new file mode 100644 index 0000000..acbfba9 Binary files /dev/null and b/src/main/java/solitaer/images/04Kreuz.png differ diff --git a/src/main/java/solitaer/images/04Pik.png b/src/main/java/solitaer/images/04Pik.png new file mode 100644 index 0000000..d33a448 Binary files /dev/null and b/src/main/java/solitaer/images/04Pik.png differ diff --git a/src/main/java/solitaer/images/05Herz.png b/src/main/java/solitaer/images/05Herz.png new file mode 100644 index 0000000..4eaf218 Binary files /dev/null and b/src/main/java/solitaer/images/05Herz.png differ diff --git a/src/main/java/solitaer/images/05Karo.png b/src/main/java/solitaer/images/05Karo.png new file mode 100644 index 0000000..45d75ca Binary files /dev/null and b/src/main/java/solitaer/images/05Karo.png differ diff --git a/src/main/java/solitaer/images/05Kreuz.png b/src/main/java/solitaer/images/05Kreuz.png new file mode 100644 index 0000000..7ab055a Binary files /dev/null and b/src/main/java/solitaer/images/05Kreuz.png differ diff --git a/src/main/java/solitaer/images/05Pik.png b/src/main/java/solitaer/images/05Pik.png new file mode 100644 index 0000000..6bbfab9 Binary files /dev/null and b/src/main/java/solitaer/images/05Pik.png differ diff --git a/src/main/java/solitaer/images/06Herz.png b/src/main/java/solitaer/images/06Herz.png new file mode 100644 index 0000000..04e7477 Binary files /dev/null and b/src/main/java/solitaer/images/06Herz.png differ diff --git a/src/main/java/solitaer/images/06Karo.png b/src/main/java/solitaer/images/06Karo.png new file mode 100644 index 0000000..be2d58a Binary files /dev/null and b/src/main/java/solitaer/images/06Karo.png differ diff --git a/src/main/java/solitaer/images/06Kreuz.png b/src/main/java/solitaer/images/06Kreuz.png new file mode 100644 index 0000000..c79e672 Binary files /dev/null and b/src/main/java/solitaer/images/06Kreuz.png differ diff --git a/src/main/java/solitaer/images/06Pik.png b/src/main/java/solitaer/images/06Pik.png new file mode 100644 index 0000000..35e3403 Binary files /dev/null and b/src/main/java/solitaer/images/06Pik.png differ diff --git a/src/main/java/solitaer/images/07Herz.png b/src/main/java/solitaer/images/07Herz.png new file mode 100644 index 0000000..b16d663 Binary files /dev/null and b/src/main/java/solitaer/images/07Herz.png differ diff --git a/src/main/java/solitaer/images/07Karo.png b/src/main/java/solitaer/images/07Karo.png new file mode 100644 index 0000000..854f4f0 Binary files /dev/null and b/src/main/java/solitaer/images/07Karo.png differ diff --git a/src/main/java/solitaer/images/07Kreuz.png b/src/main/java/solitaer/images/07Kreuz.png new file mode 100644 index 0000000..0cc142d Binary files /dev/null and b/src/main/java/solitaer/images/07Kreuz.png differ diff --git a/src/main/java/solitaer/images/07Pik.png b/src/main/java/solitaer/images/07Pik.png new file mode 100644 index 0000000..9391d2a Binary files /dev/null and b/src/main/java/solitaer/images/07Pik.png differ diff --git a/src/main/java/solitaer/images/08Herz.png b/src/main/java/solitaer/images/08Herz.png new file mode 100644 index 0000000..f95f90c Binary files /dev/null and b/src/main/java/solitaer/images/08Herz.png differ diff --git a/src/main/java/solitaer/images/08Karo.png b/src/main/java/solitaer/images/08Karo.png new file mode 100644 index 0000000..064e234 Binary files /dev/null and b/src/main/java/solitaer/images/08Karo.png differ diff --git a/src/main/java/solitaer/images/08Kreuz.png b/src/main/java/solitaer/images/08Kreuz.png new file mode 100644 index 0000000..3ed11e7 Binary files /dev/null and b/src/main/java/solitaer/images/08Kreuz.png differ diff --git a/src/main/java/solitaer/images/08Pik.png b/src/main/java/solitaer/images/08Pik.png new file mode 100644 index 0000000..6519112 Binary files /dev/null and b/src/main/java/solitaer/images/08Pik.png differ diff --git a/src/main/java/solitaer/images/09Herz.png b/src/main/java/solitaer/images/09Herz.png new file mode 100644 index 0000000..67532fb Binary files /dev/null and b/src/main/java/solitaer/images/09Herz.png differ diff --git a/src/main/java/solitaer/images/09Karo.png b/src/main/java/solitaer/images/09Karo.png new file mode 100644 index 0000000..719aba4 Binary files /dev/null and b/src/main/java/solitaer/images/09Karo.png differ diff --git a/src/main/java/solitaer/images/09Kreuz.png b/src/main/java/solitaer/images/09Kreuz.png new file mode 100644 index 0000000..1838a50 Binary files /dev/null and b/src/main/java/solitaer/images/09Kreuz.png differ diff --git a/src/main/java/solitaer/images/09Pik.png b/src/main/java/solitaer/images/09Pik.png new file mode 100644 index 0000000..9bd7df3 Binary files /dev/null and b/src/main/java/solitaer/images/09Pik.png differ diff --git a/src/main/java/solitaer/images/10Herz.png b/src/main/java/solitaer/images/10Herz.png new file mode 100644 index 0000000..80d7080 Binary files /dev/null and b/src/main/java/solitaer/images/10Herz.png differ diff --git a/src/main/java/solitaer/images/10Karo.png b/src/main/java/solitaer/images/10Karo.png new file mode 100644 index 0000000..2e44348 Binary files /dev/null and b/src/main/java/solitaer/images/10Karo.png differ diff --git a/src/main/java/solitaer/images/10Kreuz.png b/src/main/java/solitaer/images/10Kreuz.png new file mode 100644 index 0000000..7f5e236 Binary files /dev/null and b/src/main/java/solitaer/images/10Kreuz.png differ diff --git a/src/main/java/solitaer/images/10Pik.png b/src/main/java/solitaer/images/10Pik.png new file mode 100644 index 0000000..fa6024a Binary files /dev/null and b/src/main/java/solitaer/images/10Pik.png differ diff --git a/src/main/java/solitaer/images/11Herz.png b/src/main/java/solitaer/images/11Herz.png new file mode 100644 index 0000000..a6efc0f Binary files /dev/null and b/src/main/java/solitaer/images/11Herz.png differ diff --git a/src/main/java/solitaer/images/11Karo.png b/src/main/java/solitaer/images/11Karo.png new file mode 100644 index 0000000..422760b Binary files /dev/null and b/src/main/java/solitaer/images/11Karo.png differ diff --git a/src/main/java/solitaer/images/11Kreuz.png b/src/main/java/solitaer/images/11Kreuz.png new file mode 100644 index 0000000..2000018 Binary files /dev/null and b/src/main/java/solitaer/images/11Kreuz.png differ diff --git a/src/main/java/solitaer/images/11Pik.png b/src/main/java/solitaer/images/11Pik.png new file mode 100644 index 0000000..cb6ed92 Binary files /dev/null and b/src/main/java/solitaer/images/11Pik.png differ diff --git a/src/main/java/solitaer/images/12Herz.png b/src/main/java/solitaer/images/12Herz.png new file mode 100644 index 0000000..cfda346 Binary files /dev/null and b/src/main/java/solitaer/images/12Herz.png differ diff --git a/src/main/java/solitaer/images/12Karo.png b/src/main/java/solitaer/images/12Karo.png new file mode 100644 index 0000000..d9f8a0b Binary files /dev/null and b/src/main/java/solitaer/images/12Karo.png differ diff --git a/src/main/java/solitaer/images/12Kreuz.png b/src/main/java/solitaer/images/12Kreuz.png new file mode 100644 index 0000000..a6356c8 Binary files /dev/null and b/src/main/java/solitaer/images/12Kreuz.png differ diff --git a/src/main/java/solitaer/images/12Pik.png b/src/main/java/solitaer/images/12Pik.png new file mode 100644 index 0000000..c57f94c Binary files /dev/null and b/src/main/java/solitaer/images/12Pik.png differ diff --git a/src/main/java/solitaer/images/13Herz.png b/src/main/java/solitaer/images/13Herz.png new file mode 100644 index 0000000..5362efa Binary files /dev/null and b/src/main/java/solitaer/images/13Herz.png differ diff --git a/src/main/java/solitaer/images/13Karo.png b/src/main/java/solitaer/images/13Karo.png new file mode 100644 index 0000000..7945855 Binary files /dev/null and b/src/main/java/solitaer/images/13Karo.png differ diff --git a/src/main/java/solitaer/images/13Kreuz.png b/src/main/java/solitaer/images/13Kreuz.png new file mode 100644 index 0000000..2765266 Binary files /dev/null and b/src/main/java/solitaer/images/13Kreuz.png differ diff --git a/src/main/java/solitaer/images/13Pik.png b/src/main/java/solitaer/images/13Pik.png new file mode 100644 index 0000000..605141a Binary files /dev/null and b/src/main/java/solitaer/images/13Pik.png differ