Nur die besten Spiele ;3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
3.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package solitaer;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. public class SolitaerGamePanel extends JPanel {
  8. private static final long serialVersionUID = 1L;
  9. private final int OFFSET_STACKS_X = 5;
  10. private final int OFFSET_STACKS_Y = 15;
  11. public final int IMAGE_WIDTH = 72;
  12. public final int IMAGE_HIGHT = 96;
  13. public final int STARTSTACK_SIZE = 7;
  14. public final int ABLAGESTACK_SIZE = 4;
  15. private CardDeck deck;
  16. private MyMouseListener mouseL;
  17. private SaveStack save;
  18. private StartStack[] start = new StartStack[7];
  19. private AblageStack[] ablage = new AblageStack[4];
  20. private WasteStack waste;
  21. private GeberStack geber;
  22. public SolitaerGamePanel() {
  23. setLayout(null);
  24. int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1);
  25. int Offset_y_Save = setLayouty(1);
  26. JLabel label = new JLabel();
  27. label.setText("selected Cards");
  28. label.setBounds(Offset_x_Save, Offset_y_Save - 25, 200, 25);
  29. this.add(label);
  30. save = new SaveStack(Offset_x_Save, Offset_y_Save);
  31. mouseL = new MyMouseListener(save);
  32. this.addMouseListener(mouseL);
  33. // deck = new CardDeck();
  34. // deck.shuffelDeck();
  35. for (int i = 0; i < STARTSTACK_SIZE; i++) {
  36. int y = setLayouty(1);
  37. start[i] = new StartStack(setLayoutX(i), y);
  38. // int tmp = i;
  39. // while (tmp != 0) {
  40. // start[i].addCard(deck.getDeck().remove(0));
  41. // tmp -= 1;
  42. // }
  43. // Card card = deck.getDeck().remove(0);
  44. // card.setFaceUp(true);
  45. // start[i].addCard(card);
  46. // this.add(start[i]);
  47. }
  48. for (int i = 0; i < ABLAGESTACK_SIZE; i++) {
  49. int x = setLayoutX(((STARTSTACK_SIZE - ABLAGESTACK_SIZE) + i));
  50. int y = setLayouty(0);
  51. switch (i) {
  52. case 0:
  53. ablage[i] = new AblageStack(x, y, Symbol.Herz);
  54. break;
  55. case 1:
  56. ablage[i] = new AblageStack(x, y, Symbol.Kreuz);
  57. break;
  58. case 2:
  59. ablage[i] = new AblageStack(x, y, Symbol.Karo);
  60. break;
  61. case 3:
  62. ablage[i] = new AblageStack(x, y, Symbol.Pik);
  63. break;
  64. default:
  65. break;
  66. }
  67. // this.add(ablage[i]);
  68. }
  69. waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y);
  70. geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste);
  71. // while (deck.getDeck().size() != 1) {
  72. // geber.addCard(deck.getDeck().remove(0));
  73. // }
  74. //
  75. // Card card = deck.getDeck().remove(0);
  76. // card.setFaceUp(true);
  77. // waste.addCard(card);
  78. //
  79. // this.add(waste);
  80. // this.add(geber);
  81. restartGame();
  82. }
  83. private int setLayoutX(int _spalte) {
  84. return (((IMAGE_WIDTH + OFFSET_STACKS_X) * _spalte) + OFFSET_STACKS_X);
  85. }
  86. private int setLayouty(int _row) {
  87. if (_row == 1)
  88. return IMAGE_HIGHT + (OFFSET_STACKS_Y * 3);
  89. else
  90. return OFFSET_STACKS_Y;
  91. }
  92. public void restartGame() {
  93. deck = new CardDeck();
  94. deck.shuffelDeck();
  95. for (int i = 0; i < STARTSTACK_SIZE; i++) {
  96. start[i].clearStack();
  97. int tmp = i;
  98. while (tmp != 0) {
  99. start[i].addCard(deck.getDeck().remove(0));
  100. tmp -= 1;
  101. }
  102. Card card = deck.getDeck().remove(0);
  103. card.setFaceUp(true);
  104. start[i].addCard(card);
  105. this.add(start[i]);
  106. }
  107. for (int i = 0; i < ABLAGESTACK_SIZE; i++) {
  108. ablage[i].clearStack();
  109. this.add(ablage[i]);
  110. }
  111. geber.clearStack();
  112. waste.clearStack();
  113. while (deck.getDeck().size() != 1) {
  114. geber.addCard(deck.getDeck().remove(0));
  115. }
  116. Card card = deck.getDeck().remove(0);
  117. card.setFaceUp(true);
  118. waste.addCard(card);
  119. this.add(waste);
  120. this.add(geber);
  121. save.clearStack();
  122. this.add(save);
  123. }
  124. @Override
  125. protected void paintComponent(Graphics g) {
  126. // TODO Auto-generated method stub
  127. super.paintComponent(g);
  128. g.setColor(new Color(0, 135, 62));
  129. g.fillRect(0, 0, this.getWidth(), this.getHeight());
  130. }
  131. }