Browse Source

Merge commit '6722a62792900ca9e5a7f5650aab2c3c1a8f1c5f' into HEAD

solitaer_Game
Jenkins 3 years ago
parent
commit
b2c43f842d
  1. 7
      src/main/java/hauptmenue/GameWindow.java
  2. 10
      src/main/java/solitaer/BaseStack.java
  3. 68
      src/main/java/solitaer/SolitaerGamePanel.java
  4. 53
      src/main/java/solitaer/SolitaerMenue.java

7
src/main/java/hauptmenue/GameWindow.java

@ -5,18 +5,19 @@ import java.awt.Dimension;
import javax.swing.JFrame;
import solitaer.SolitaerGamePanel;
import solitaer.SolitaerMenue;
public class GameWindow extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private final SolitaerGamePanel gamePanel = new SolitaerGamePanel();
private SolitaerMenue smenue = new SolitaerMenue(gamePanel);
public GameWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gamePanel.setPreferredSize(new Dimension(1180, 780));
this.setJMenuBar(smenue.getMenue());
add(gamePanel);
pack();

10
src/main/java/solitaer/BaseStack.java

@ -12,8 +12,8 @@ public abstract class BaseStack extends JPanel {
private static final long serialVersionUID = 1L;
private ArrayList<Card> stack = new ArrayList<Card>();
private final int OFFSET_VALUE = 20;
int offset;
int addOffset;
private int offset;
private int addOffset;
public BaseStack(boolean _offset) {
// TODO Auto-generated constructor stub
@ -25,6 +25,12 @@ public abstract class BaseStack extends JPanel {
offset = 0;
}
public void clearStack() {
stack.clear();
offset = 0;
RenderStackNew();
}
public boolean stackIsEmpty() {
return stack.isEmpty();
}

68
src/main/java/solitaer/SolitaerGamePanel.java

@ -1,7 +1,6 @@
package solitaer;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JLabel;
@ -20,6 +19,8 @@ public class SolitaerGamePanel extends JPanel {
public final int STARTSTACK_SIZE = 7;
public final int ABLAGESTACK_SIZE = 4;
private Color backgroundColor = new Color(0, 135, 62);
private CardDeck deck;
private MyMouseListener mouseL;
@ -42,26 +43,13 @@ public class SolitaerGamePanel extends JPanel {
this.add(label);
save = new SaveStack(Offset_x_Save, Offset_y_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++) {
@ -84,22 +72,12 @@ public class SolitaerGamePanel extends JPanel {
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();
}
@ -114,11 +92,49 @@ public class SolitaerGamePanel extends JPanel {
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.setColor(backgroundColor);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}

53
src/main/java/solitaer/SolitaerMenue.java

@ -0,0 +1,53 @@
package solitaer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class SolitaerMenue implements ActionListener{
SolitaerGamePanel solitaerpanel;
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("options");
JMenuItem restart = new JMenuItem("restart");
JMenuItem quit = new JMenuItem("quit");
public SolitaerMenue(SolitaerGamePanel _panel) {
solitaerpanel = _panel;
this.restart.addActionListener(this);
this.menu.add(restart);
this.menu.addSeparator();
this.quit.addActionListener(this);
this.menu.add(quit);
this.menuBar.add(menu);
}
public JMenuBar getMenue() {
return menuBar;
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == this.quit) {
System.out.println("quit");
System.exit(0);
}
if(e.getSource() == this.restart) {
solitaerpanel.restartGame();
}
}
}
Loading…
Cancel
Save