Browse Source

Merge commit '6c2aaeb146d57f157f6b27933c27ca66c487ebfe' into HEAD

solitaer_Game
Jenkins 3 years ago
parent
commit
73edcd59d1
  1. 6
      src/main/java/solitaer/CardDeck.java
  2. 15
      src/main/java/solitaer/MyMouseListener.java
  3. 172
      src/main/java/solitaer/SolitaerGamePanel.java

6
src/main/java/solitaer/CardDeck.java

@ -1,6 +1,7 @@
package solitaer; package solitaer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
public class CardDeck { public class CardDeck {
@ -33,4 +34,9 @@ public class CardDeck {
return deck; return deck;
} }
public void shuffelDeck() {
Collections.shuffle(deck);
}
} }

15
src/main/java/solitaer/MyMouseListener.java

@ -29,14 +29,7 @@ public class MyMouseListener implements MouseInputListener {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.println("DOWN"); System.out.println("DOWN");
Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
// // Leeres StartFeld
// if (com instanceof StartStack) {
// System.out.println("Leer Start");
//
// }
// // Karte, die in einem StartStack liegt
// else
if ((com instanceof Card && com.getParent() instanceof StartStack) if ((com instanceof Card && com.getParent() instanceof StartStack)
|| (com instanceof StartStack && ((StartStack) com).stackIsEmpty())) { || (com instanceof StartStack && ((StartStack) com).stackIsEmpty())) {
@ -152,6 +145,12 @@ public class MyMouseListener implements MouseInputListener {
} else { } else {
clearSaveStack(selectedStack); clearSaveStack(selectedStack);
} }
//Clear SaveStack click on SolitaerGamePanel
}else if(com instanceof SolitaerGamePanel ||
com.getParent() instanceof SolitaerGamePanel && com instanceof StartStack ){
if(saveStack.stackIsEmpty() == false) {
clearSaveStack(selectedStack);
}
} }
} }

172
src/main/java/solitaer/SolitaerGamePanel.java

@ -1,110 +1,124 @@
package solitaer; package solitaer;
import java.awt.Color; import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
public class SolitaerGamePanel extends JPanel { public class SolitaerGamePanel extends JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final int OFFSET_STACKS_X = 5;
private final int OFFSET_STACKS_Y = 15;
public final int IMAGE_WIDTH = 72;
public final int IMAGE_HIGHT = 96;
public final int STARTSTACK_SIZE = 7;
public final int ABLAGESTACK_SIZE = 4;
private CardDeck deck; private CardDeck deck;
private MyMouseListener mouseL; private MyMouseListener mouseL;
private SaveStack save =new SaveStack(500,250);
private SaveStack save;
private StartStack[] start = new StartStack[7];
private AblageStack[] ablage = new AblageStack[4];
private WasteStack waste;
private GeberStack geber;
public SolitaerGamePanel() { public SolitaerGamePanel() {
setLayout(null); setLayout(null);
mouseL = new MyMouseListener(save);
this.addMouseListener(mouseL);
int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1);
int Offset_y_Save = setLayouty(1);
deck = new CardDeck();
JLabel label = new JLabel();
label.setText("selected Cards");
label.setBounds(Offset_x_Save, Offset_y_Save - 25, 200, 25);
this.add(label);
StartStack a = new StartStack(25,125);
deck.getDeck().get(5).setFaceUp(true);
a.addCard((deck.getDeck().get(5)));
deck.getDeck().get(4).setFaceUp(true);
a.addCard((deck.getDeck().get(4)));
deck.getDeck().get(3).setFaceUp(true);
a.addCard((deck.getDeck().get(3)));
deck.getDeck().get(2).setFaceUp(true);
a.addCard((deck.getDeck().get(2)));
deck.getDeck().get(1).setFaceUp(true);
a.addCard((deck.getDeck().get(1)));
deck.getDeck().get(0).setFaceUp(true);
a.addCard(deck.getDeck().get(0));
this.add(a);
StartStack b = new StartStack(200,125);
deck.getDeck().get(32).setFaceUp(true);
b.addCard((deck.getDeck().get(32)));
this.add(b);
StartStack c = new StartStack(375,125);
//deck.getDeck().get(20).setFaceUp(true);
c.addCard((deck.getDeck().get(20)));
this.add(c);
StartStack d = new StartStack(475,125);
this.add(d);
//save = new SaveStack(500,250);
save = new SaveStack(Offset_x_Save, Offset_y_Save);
this.add(save); this.add(save);
mouseL = new MyMouseListener(save);
this.addMouseListener(mouseL);
deck = new CardDeck();
deck.shuffelDeck();
for (int i = 0; i < STARTSTACK_SIZE; i++) {
int y = setLayouty(1);
start[i] = new StartStack(setLayoutX(i), y);
int tmp = i;
while(tmp != 0) {
start[i].addCard(deck.getDeck().remove(0));
tmp -= 1;
}
Card card = deck.getDeck().remove(0);
card.setFaceUp(true);
start[i].addCard(card);
this.add(start[i]);
}
for (int i = 0; i < ABLAGESTACK_SIZE; i++) {
int x = setLayoutX(((STARTSTACK_SIZE - ABLAGESTACK_SIZE) + i));
int y = setLayouty(0);
switch (i) {
case 0:
ablage[i] = new AblageStack(x, y, Symbol.Herz);
break;
case 1:
ablage[i] = new AblageStack(x, y, Symbol.Kreuz);
break;
case 2:
ablage[i] = new AblageStack(x, y, Symbol.Karo);
break;
case 3:
ablage[i] = new AblageStack(x, y, Symbol.Pik);
break;
default:
break;
}
this.add(ablage[i]);
}
waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y);
geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste);
AblageStack a1 = new AblageStack(200, 10, Symbol.Herz);
this.add(a1);
AblageStack a2 = new AblageStack(275, 10, Symbol.Kreuz);
this.add(a2);
AblageStack a3 = new AblageStack(350, 10, Symbol.Karo);
this.add(a3);
AblageStack a4 = new AblageStack(425, 10, Symbol.Pik);
this.add(a4);
WasteStack w = new WasteStack(85, 10);
GeberStack g = new GeberStack(10, 10, w);
deck.getDeck().get(34).setFaceUp(true);
w.addCard(deck.getDeck().get(34));
deck.getDeck().get(35).setFaceUp(true);
w.addCard(deck.getDeck().get(35));
deck.getDeck().get(36).setFaceUp(true);
w.addCard(deck.getDeck().get(36));
deck.getDeck().get(37).setFaceUp(true);
w.addCard(deck.getDeck().get(37));
g.addCard(deck.getDeck().get(38));
this.add(w);
this.add(g);
while(deck.getDeck().size() != 1) {
geber.addCard(deck.getDeck().remove(0));
}
Card card = deck.getDeck().remove(0);
card.setFaceUp(true);
waste.addCard(card);
this.add(waste);
this.add(geber);
} }
private int setLayoutX(int _spalte) {
return (((IMAGE_WIDTH + OFFSET_STACKS_X) * _spalte) + OFFSET_STACKS_X);
}
private int setLayouty(int _row) {
if(_row == 1)
return IMAGE_HIGHT + (OFFSET_STACKS_Y * 3);
else
return OFFSET_STACKS_Y;
}
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
super.paintComponent(g); super.paintComponent(g);
g.setColor(Color.green);
g.setColor(new Color(0, 135, 62));
g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.fillRect(0, 0, this.getWidth(), this.getHeight());
} }
} }
Loading…
Cancel
Save