Browse Source

implement render for cards and ADD image files for cards

feature_solitaer_StartStack
Alexander Hartung 3 years ago
parent
commit
cd0645ba09
  1. 52
      src/main/java/solitaer/Card.java
  2. 2
      src/main/java/solitaer/SolitaerGamePanel.java
  3. 29
      src/main/java/solitaer/StartStack.java
  4. BIN
      src/main/java/solitaer/images/01Herz.png
  5. BIN
      src/main/java/solitaer/images/01Karo.png
  6. BIN
      src/main/java/solitaer/images/01Kreuz.png
  7. BIN
      src/main/java/solitaer/images/01Pik.png
  8. BIN
      src/main/java/solitaer/images/02Herz.png
  9. BIN
      src/main/java/solitaer/images/02Karo.png
  10. BIN
      src/main/java/solitaer/images/02Kreuz.png
  11. BIN
      src/main/java/solitaer/images/02Pik.png
  12. BIN
      src/main/java/solitaer/images/03Herz.png
  13. BIN
      src/main/java/solitaer/images/03Karo.png
  14. BIN
      src/main/java/solitaer/images/03Kreuz.png
  15. BIN
      src/main/java/solitaer/images/03Pik.png
  16. BIN
      src/main/java/solitaer/images/04Herz.png
  17. BIN
      src/main/java/solitaer/images/04Karo.png
  18. BIN
      src/main/java/solitaer/images/04Kreuz.png
  19. BIN
      src/main/java/solitaer/images/04Pik.png
  20. BIN
      src/main/java/solitaer/images/05Herz.png
  21. BIN
      src/main/java/solitaer/images/05Karo.png
  22. BIN
      src/main/java/solitaer/images/05Kreuz.png
  23. BIN
      src/main/java/solitaer/images/05Pik.png
  24. BIN
      src/main/java/solitaer/images/06Herz.png
  25. BIN
      src/main/java/solitaer/images/06Karo.png
  26. BIN
      src/main/java/solitaer/images/06Kreuz.png
  27. BIN
      src/main/java/solitaer/images/06Pik.png
  28. BIN
      src/main/java/solitaer/images/07Herz.png
  29. BIN
      src/main/java/solitaer/images/07Karo.png
  30. BIN
      src/main/java/solitaer/images/07Kreuz.png
  31. BIN
      src/main/java/solitaer/images/07Pik.png
  32. BIN
      src/main/java/solitaer/images/08Herz.png
  33. BIN
      src/main/java/solitaer/images/08Karo.png
  34. BIN
      src/main/java/solitaer/images/08Kreuz.png
  35. BIN
      src/main/java/solitaer/images/08Pik.png
  36. BIN
      src/main/java/solitaer/images/09Herz.png
  37. BIN
      src/main/java/solitaer/images/09Karo.png
  38. BIN
      src/main/java/solitaer/images/09Kreuz.png
  39. BIN
      src/main/java/solitaer/images/09Pik.png
  40. BIN
      src/main/java/solitaer/images/10Herz.png
  41. BIN
      src/main/java/solitaer/images/10Karo.png
  42. BIN
      src/main/java/solitaer/images/10Kreuz.png
  43. BIN
      src/main/java/solitaer/images/10Pik.png
  44. BIN
      src/main/java/solitaer/images/11Herz.png
  45. BIN
      src/main/java/solitaer/images/11Karo.png
  46. BIN
      src/main/java/solitaer/images/11Kreuz.png
  47. BIN
      src/main/java/solitaer/images/11Pik.png
  48. BIN
      src/main/java/solitaer/images/12Herz.png
  49. BIN
      src/main/java/solitaer/images/12Karo.png
  50. BIN
      src/main/java/solitaer/images/12Kreuz.png
  51. BIN
      src/main/java/solitaer/images/12Pik.png
  52. BIN
      src/main/java/solitaer/images/13Herz.png
  53. BIN
      src/main/java/solitaer/images/13Karo.png
  54. BIN
      src/main/java/solitaer/images/13Kreuz.png
  55. BIN
      src/main/java/solitaer/images/13Pik.png

52
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 {
@ -19,10 +22,21 @@ public class Card extends JPanel {
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);
}
}

2
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);
}

29
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<Card> Stack = new ArrayList<Card>();
private ArrayList<Card> stack = new ArrayList<Card>();
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);
}
}
}

BIN
src/main/java/solitaer/images/01Herz.png

After

Width: 73  |  Height: 97  |  Size: 523 B

BIN
src/main/java/solitaer/images/01Karo.png

After

Width: 73  |  Height: 97  |  Size: 539 B

BIN
src/main/java/solitaer/images/01Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 564 B

BIN
src/main/java/solitaer/images/01Pik.png

After

Width: 73  |  Height: 97  |  Size: 506 B

BIN
src/main/java/solitaer/images/02Herz.png

After

Width: 73  |  Height: 97  |  Size: 530 B

BIN
src/main/java/solitaer/images/02Karo.png

After

Width: 73  |  Height: 97  |  Size: 546 B

BIN
src/main/java/solitaer/images/02Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 574 B

BIN
src/main/java/solitaer/images/02Pik.png

After

Width: 73  |  Height: 97  |  Size: 517 B

BIN
src/main/java/solitaer/images/03Herz.png

After

Width: 73  |  Height: 97  |  Size: 532 B

BIN
src/main/java/solitaer/images/03Karo.png

After

Width: 73  |  Height: 97  |  Size: 547 B

BIN
src/main/java/solitaer/images/03Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 576 B

BIN
src/main/java/solitaer/images/03Pik.png

After

Width: 73  |  Height: 97  |  Size: 518 B

BIN
src/main/java/solitaer/images/04Herz.png

After

Width: 73  |  Height: 97  |  Size: 530 B

BIN
src/main/java/solitaer/images/04Karo.png

After

Width: 73  |  Height: 97  |  Size: 547 B

BIN
src/main/java/solitaer/images/04Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 574 B

BIN
src/main/java/solitaer/images/04Pik.png

After

Width: 73  |  Height: 97  |  Size: 516 B

BIN
src/main/java/solitaer/images/05Herz.png

After

Width: 73  |  Height: 97  |  Size: 531 B

BIN
src/main/java/solitaer/images/05Karo.png

After

Width: 73  |  Height: 97  |  Size: 548 B

BIN
src/main/java/solitaer/images/05Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 575 B

BIN
src/main/java/solitaer/images/05Pik.png

After

Width: 73  |  Height: 97  |  Size: 519 B

BIN
src/main/java/solitaer/images/06Herz.png

After

Width: 73  |  Height: 97  |  Size: 540 B

BIN
src/main/java/solitaer/images/06Karo.png

After

Width: 73  |  Height: 97  |  Size: 555 B

BIN
src/main/java/solitaer/images/06Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 584 B

BIN
src/main/java/solitaer/images/06Pik.png

After

Width: 73  |  Height: 97  |  Size: 527 B

BIN
src/main/java/solitaer/images/07Herz.png

After

Width: 73  |  Height: 97  |  Size: 525 B

BIN
src/main/java/solitaer/images/07Karo.png

After

Width: 73  |  Height: 97  |  Size: 542 B

BIN
src/main/java/solitaer/images/07Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 567 B

BIN
src/main/java/solitaer/images/07Pik.png

After

Width: 73  |  Height: 97  |  Size: 510 B

BIN
src/main/java/solitaer/images/08Herz.png

After

Width: 73  |  Height: 97  |  Size: 543 B

BIN
src/main/java/solitaer/images/08Karo.png

After

Width: 73  |  Height: 97  |  Size: 557 B

BIN
src/main/java/solitaer/images/08Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 588 B

BIN
src/main/java/solitaer/images/08Pik.png

After

Width: 73  |  Height: 97  |  Size: 530 B

BIN
src/main/java/solitaer/images/09Herz.png

After

Width: 73  |  Height: 97  |  Size: 540 B

BIN
src/main/java/solitaer/images/09Karo.png

After

Width: 73  |  Height: 97  |  Size: 555 B

BIN
src/main/java/solitaer/images/09Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 584 B

BIN
src/main/java/solitaer/images/09Pik.png

After

Width: 73  |  Height: 97  |  Size: 527 B

BIN
src/main/java/solitaer/images/10Herz.png

After

Width: 73  |  Height: 97  |  Size: 523 B

BIN
src/main/java/solitaer/images/10Karo.png

After

Width: 73  |  Height: 97  |  Size: 539 B

BIN
src/main/java/solitaer/images/10Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 563 B

BIN
src/main/java/solitaer/images/10Pik.png

After

Width: 73  |  Height: 97  |  Size: 507 B

BIN
src/main/java/solitaer/images/11Herz.png

After

Width: 73  |  Height: 97  |  Size: 499 B

BIN
src/main/java/solitaer/images/11Karo.png

After

Width: 73  |  Height: 97  |  Size: 518 B

BIN
src/main/java/solitaer/images/11Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 540 B

BIN
src/main/java/solitaer/images/11Pik.png

After

Width: 73  |  Height: 97  |  Size: 483 B

BIN
src/main/java/solitaer/images/12Herz.png

After

Width: 73  |  Height: 97  |  Size: 509 B

BIN
src/main/java/solitaer/images/12Karo.png

After

Width: 73  |  Height: 97  |  Size: 525 B

BIN
src/main/java/solitaer/images/12Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 552 B

BIN
src/main/java/solitaer/images/12Pik.png

After

Width: 73  |  Height: 97  |  Size: 494 B

BIN
src/main/java/solitaer/images/13Herz.png

After

Width: 73  |  Height: 97  |  Size: 511 B

BIN
src/main/java/solitaer/images/13Karo.png

After

Width: 73  |  Height: 97  |  Size: 527 B

BIN
src/main/java/solitaer/images/13Kreuz.png

After

Width: 73  |  Height: 97  |  Size: 554 B

BIN
src/main/java/solitaer/images/13Pik.png

After

Width: 73  |  Height: 97  |  Size: 495 B

Loading…
Cancel
Save