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
177 lines
3.7 KiB
package solitaer;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Font;
|
|
import java.awt.Graphics;
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
|
|
public class SolitaerGamePanel extends JPanel {
|
|
|
|
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 MyMouseListener mouseL;
|
|
|
|
private SaveStack save;
|
|
private StartStack[] start = new StartStack[7];
|
|
private AblageStack[] ablage = new AblageStack[4];
|
|
|
|
private WasteStack waste;
|
|
private GeberStack geber;
|
|
|
|
public SolitaerGamePanel() {
|
|
setLayout(null);
|
|
|
|
int Offset_x_Save = setLayoutX(STARTSTACK_SIZE + 1);
|
|
int Offset_y_Save = setLayouty(1);
|
|
|
|
JLabel label = new JLabel();
|
|
label.setText("selected Cards");
|
|
label.setBounds(Offset_x_Save, Offset_y_Save - 25, 200, 25);
|
|
this.add(label);
|
|
|
|
save = new SaveStack(Offset_x_Save, Offset_y_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);
|
|
|
|
// 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);
|
|
|
|
restartGame();
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public void restartGame() {
|
|
deck = new CardDeck();
|
|
deck.shuffelDeck();
|
|
|
|
for (int i = 0; i < STARTSTACK_SIZE; i++) {
|
|
start[i].clearStack();
|
|
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++) {
|
|
ablage[i].clearStack();
|
|
this.add(ablage[i]);
|
|
}
|
|
|
|
geber.clearStack();
|
|
waste.clearStack();
|
|
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);
|
|
|
|
|
|
save.clearStack();
|
|
this.add(save);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics g) {
|
|
// TODO Auto-generated method stub
|
|
super.paintComponent(g);
|
|
g.setColor(new Color(0, 135, 62));
|
|
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
}
|
|
}
|