130 Commits

Author SHA1 Message Date
Jenkins 5f78b92d6c Merge commit '1c8ba1e1c1f4ae0b45742d49762f54bf86a2b12d' into HEAD 3 years ago
Jenkins 1c8ba1e1c1 Merge commit '8bbad65768b6c487421bcc043329efd6eb29c844' into HEAD 3 years ago
kfkama 8bbad65768 Add Main Menu 3 years ago
Jenkins 92e0e32ef9 Merge commit 'b1e7a31280623d87f9c6012c5ddf5cad6fdf0fa1' into HEAD 3 years ago
kfkama b1e7a31280 fix .gitignore, again...again 3 years ago
kfkama 7738993b29 fix .gitignore, again 3 years ago
Jenkins cc5b606d34 Merge commit '91c5969d9cd2ed4c0ba2e8fddb0f70a46d59aa0b' into HEAD 3 years ago
Jenkins 4d0c23ece7 Merge commit 'e3215fc44c8b339838de193d401104350e00453d' into HEAD 3 years ago
Jenkins 0262d65cea Merge commit '520c5dc3a0a5320891b6b01374ee9101ca02c4bd' into HEAD 3 years ago
kfkama 520c5dc3a0 Bugfix timer reset 3 years ago
kfkama d6f1baffe9 Timer stops while game end dialog is open 3 years ago
kfkama 1a7908fa2a Reset timer on game end 3 years ago
kfkama 8128061c09 Add reset to TimerLable 3 years ago
kfkama 1a8df9a1a9 Display TimerLable 3 years ago
kfkama f902c3550b Add TimerLable class with basic logic 3 years ago
Jenkins 42af096d06 Merge commit '896413211c40fcb697d435dca1435d5e0709e27f' into HEAD 3 years ago
kfkama 896413211c Bugfix worng colors on unflag 3 years ago
kfkama 9c2de1f2f7 Bugfix numbers not showen 3 years ago
Jenkins c851d634f8 Merge commit '3160bf1ed58da47da6d6d1011f72843e068acb8e' into HEAD 3 years ago
kfkama 3160bf1ed5 Merge branch 'Minesweeper_Game' into feature_Minesweeper_Playfield 3 years ago
kfkama 5c365de0d2 .gitignore fix 3 years ago
kfkama 968c93804d Refactore Minesweeper, Playfield 3 years ago
kfkama 02c2b01d95 Reveal all bombs on game end 3 years ago
kfkama 7c6706bc20 Changed Colors 3 years ago
kfkama 430ff09228 Add reveal cell function 3 years ago
kfkama c6c2328e4a Changed victory end to reset 3 years ago
kfkama 5d1aba4408 Flagged number cells count as flooded 3 years ago
kfkama 7de023fa3e Flagged cells will not be flooded 3 years ago
Jenkins e3215fc44c Merge commit '462b2e0a5f912868170a9b19781aba1d9247cb3c' into HEAD 3 years ago
kfkama d6178355de Bugfix early victory 3 years ago
kfkama 3c6f092049 Add flagging logic to cell 3 years ago
kfkama d0594cba7e Flagging on right click 3 years ago
kfkama b635c64d4f Game End: Victory 3 years ago
kfkama 4cbfc45a3d Game End: Clicked on Mine 3 years ago
kfkama d718f86c52 Made playfield resetable 3 years ago
kfkama 30903220e9 Refactore Playfield 3 years ago
kfkama b51cfb6732 Change update for celltype bomb 3 years ago
kfkama 4d97b75dba Add floodfill on click 3 years ago
kfkama cc10c4fdde Show proximity values on cells 3 years ago
kfkama 0e2ea58e57 Add bomb proximity with test 3 years ago
kfkama 380e848e38 Refactore Playfield 3 years ago
kfkama aa04d679bd Moved playfield logic to new class 3 years ago
kfkama 1dc0576f7b Add bomb placement 3 years ago
kfkama 665d7c1232 Add Cell to Minesweeper, replacing JButtons / Move playfield to center 3 years ago
kfkama 44a39db750 Add class Cell 3 years ago
kfkama 00b6ab308c Refactore MinesweeperGame 3 years ago
kfkama 88de22364d Add class MinesweeperGame with basic playfield gen. 3 years ago
Jenkins 91c5969d9c Merge commit '848a5ba499d335d70de776f8626c65a10942e230' into HEAD 3 years ago
kfkama 848a5ba499 Bugfix draw order 3 years ago
kfkama 899ba9bbc4 Requested change to darker colors 3 years ago
kfkama 3ca691f2a2 Bugfix turn 8 draw 3 years ago
kfkama 3efe0a8d3e Bugfix unclickable cell 3 years ago
kfkama 003119fc27 Changed Colors to cross and circle 3 years ago
Jenkins c16481ba50 Merge commit '41b70d270045d59b2ac072081ad35bd9d4b7463c' into HEAD 3 years ago
kfkama 41b70d2700 Add Games played to Scoreboard 3 years ago
kfkama e7468f1498 Refactor cell, TicTacToe 3 years ago
kfkama ca9ca4446a Show Scoreboard in TicTacToe game 3 years ago
kfkama 30f5312440 Add Scoreboard class with basic functions 3 years ago
Jenkins eeafe8c2ae Merge commit 'e5690a005d319fc71ce5b192ffa44440c4f0be1f' into HEAD 3 years ago
Alexander Hartung 462b2e0a5f Refactor 3 years ago
kfkama e5690a005d Reset game on game end 3 years ago
kfkama 072610ab1b Game end: Draw, with Test 3 years ago
kfkama aad8ef8cf9 Refactore: TicTacToe, cell 3 years ago
kfkama 1b5b077704 Game end: Player wins, with Test 3 years ago
kfkama e684a87d66 Expanded cell click logic 3 years ago
Alexander Hartung fee8ede799 remove unused pictures 3 years ago
kfkama 597dffcc60 Made cell change color on click/Player turns 3 years ago
kfkama bb5e31ff9f Add cell class 3 years ago
Alexander Hartung 788cf4762f Fix MouseInput GeberStack 3 years ago
Jenkins b2c43f842d Merge commit '6722a62792900ca9e5a7f5650aab2c3c1a8f1c5f' into HEAD 3 years ago
Alexander Hartung 6722a62792 Refactor 3 years ago
Alexander Hartung 8a594b8918 Fix render when restart 3 years ago
Alexander Hartung d478ae0cc6 Add MouseInput MenueRestart-Button 3 years ago
Alexander Hartung c57f31ac02 Add clearStack methode to BaseStack 3 years ago
Alexander Hartung 2f4e989b9b Add methode restart 3 years ago
Alexander Hartung e902f029ce Add MouseInput MenueQuit-Button 3 years ago
Alexander Hartung b8ad7aca06 Add SolitaerMenue 3 years ago
Jenkins 73edcd59d1 Merge commit '6c2aaeb146d57f157f6b27933c27ca66c487ebfe' into HEAD 3 years ago
Alexander Hartung 6c2aaeb146 Fix MouseListener 3 years ago
Alexander Hartung f6a2f009da Add Shuffel for CardDeck 3 years ago
Alexander Hartung 337594435a ADD last card to WasteStack 3 years ago
Alexander Hartung abecb9f8be ADD all remaining Cards to GeberStack 3 years ago
Alexander Hartung 3576bf0370 ADD Cards to StartStacks 3 years ago
Alexander Hartung d477a4f2e3 Refactor SolitaerGamePanel 3 years ago
Alexander Hartung c5a31c3991 Set Layout SaveStack 3 years ago
Alexander Hartung 8be8a7096b Set Layout Geber- WasteStack 3 years ago
Alexander Hartung d79fd583f5 Set Layout AblageStacks 3 years ago
Alexander Hartung a0409b6b94 Set Layout StartStacks 3 years ago
Jenkins e5a61e092d Merge commit '02ad893dea6a4e153b8040d5fd1c8e402ff5949f' into HEAD 3 years ago
kfkama 02ad893dea Init Base UI 3 years ago
Jenkins cd2e0ac545 Merge commit '3ad5083c354c4999ba1c9b2ae4595f7c2a45d9f3' into HEAD 3 years ago
Alexander Hartung 3ad5083c35 Refactor Card and StartStack 3 years ago
Alexander Hartung d89b2a0c02 Update check and test from StartStack 3 years ago
Jenkins f53b5d0685 Merge commit '8b93f0414429295fcd4fc0e20a3eb6e1f0cab381' into HEAD 3 years ago
Alexander Hartung 5f6b3bbfff Fix MouseInput StartStack 3 years ago
Alexander Hartung 8b93f04144 Add MouseInput WasteStack 3 years ago
Alexander Hartung b2be476c38 Refactor GeberStack 3 years ago
Alexander Hartung ae20cbcbae Add MousInput GeberStack 3 years ago
Alexander Hartung f83db6a3f9 Add swapGeberWaste Funktion and Add Test 3 years ago
Alexander Hartung 698569ba07 Add render for WasteStack 3 years ago
Alexander Hartung f95187e009 Add render for GeberStack 3 years ago
Alexander Hartung e5832eac49 Add WasteStack 3 years ago
Alexander Hartung 29b2c1db67 Add GeberStack 3 years ago
Jenkins fed92c15c3 Merge commit '24f874a09d420b4b441b2c610319a6420a35b6bc' into HEAD 3 years ago
Alexander Hartung 24f874a09d Refactor MouseInput 3 years ago
Alexander Hartung 63cdf0a8a7 remove offset for AblageStack 3 years ago
Alexander Hartung 2cb74cadc9 add MouseInput for AblageStack 3 years ago
Alexander Hartung b16c5e74ad Add render for AblageStack 3 years ago
Alexander Hartung e5fa1c3657 Add Ruleset for AblageStack and Tests 3 years ago
Alexander Hartung 65a829fbff init AblageStack 3 years ago
Jenkins c5fee840c8 Merge commit '5aab0411798e7bbd41c70e75d0a2bfc51972ce0e' into HEAD 3 years ago
Alexander Hartung 5aab041179 Refactor Start- Save- BaseStack and MyMousListener 3 years ago
Alexander Hartung cc51b3fa68 Move Cards between StartStack with Mouse 3 years ago
Alexander Hartung b11a6244b7 Turn Card with Mouse 3 years ago
Alexander Hartung 421cd8903f Add BaseStack Refactor StartStack 3 years ago
Alexander Hartung 7caebafde9 Add MouseListener 3 years ago
Jenkins fe4fac57b0 Merge commit '7d0878431ed5b959c3fa6887396ac1e8773665ad' into HEAD 3 years ago
Alexander Hartung 7d0878431e Fix Card and StartStack DRAW 3 years ago
Alexander Hartung 67d9ada932 Refactor Card and StartStack 3 years ago
Alexander Hartung 8ccbb52a9a Add Ruleset for startStack and Tests 3 years ago
Alexander Hartung 0fccd2aba9 add Image for empty stack 3 years ago
Alexander Hartung 51d1e8c7ab Add Offset for startStack 3 years ago
Alexander Hartung cd0645ba09 implement render for cards and ADD image files for cards 3 years ago
Alexander Hartung d629613db4 init startStack 3 years ago
Jenkins 9aa621c531 Merge commit 'a10127d1b227a91831a48e2bbb2c2ef603b71c87' into HEAD 3 years ago
Alexander Hartung a10127d1b2 Refactor CardDeck and CardDeckTest 3 years ago
Alexander Hartung 2de3d41bfd CardDeck with 13 Cards of each Symbol 3 years ago
Alexander Hartung 84fab3b084 CardDeck with different Symbole 3 years ago
Alexander Hartung 9346c42223 implement CardDeck with 52 Cards 3 years ago
Alexander Hartung 25f30237d2 init GameWindow 3 years ago
  1. 22
      .gitignore
  2. 143
      src/main/java/Minesweeper/Cell.java
  3. 33
      src/main/java/Minesweeper/MinesweeperGame.java
  4. 151
      src/main/java/Minesweeper/Playfield.java
  5. 60
      src/main/java/Minesweeper/TimerLable.java
  6. 60
      src/main/java/TicTacToe/Cell.java
  7. 45
      src/main/java/TicTacToe/Scoreboard.java
  8. 134
      src/main/java/TicTacToe/TicTacToeGame.java
  9. 100
      src/main/java/hauptmenue/GameWindow.java
  10. 10
      src/main/java/hauptmenue/main.java
  11. 63
      src/main/java/solitaer/AblageStack.java
  12. 81
      src/main/java/solitaer/BaseStack.java
  13. 136
      src/main/java/solitaer/Card.java
  14. 42
      src/main/java/solitaer/CardDeck.java
  15. 66
      src/main/java/solitaer/GeberStack.java
  16. 199
      src/main/java/solitaer/MyMouseListener.java
  17. 38
      src/main/java/solitaer/SaveStack.java
  18. 140
      src/main/java/solitaer/SolitaerGamePanel.java
  19. 53
      src/main/java/solitaer/SolitaerMenue.java
  20. 50
      src/main/java/solitaer/StartStack.java
  21. 38
      src/main/java/solitaer/WasteStack.java
  22. 53
      src/test/java/Minesweeper/MinesweeperGameTest.java
  23. 77
      src/test/java/TicTacToe/TicTacToeGameTest.java
  24. 46
      src/test/java/solitaer/AblageStackTest.java
  25. 81
      src/test/java/solitaer/CardDeckTest.java
  26. 25
      src/test/java/solitaer/GeberStackTest.java
  27. 38
      src/test/java/solitaer/StartStackTest.java

22
.gitignore

@ -23,3 +23,25 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
# End of https://www.toptal.com/developers/gitignore/api/maven

143
src/main/java/Minesweeper/Cell.java

@ -0,0 +1,143 @@
package Minesweeper;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JOptionPane;
enum CellType {
Number, Bomb
}
public class Cell extends JButton {
private static final Color FLAGCOLOR = Color.RED;
private static final Color FLOODEDCOLOR = Color.LIGHT_GRAY;
private static final Color HIDDENCOLOR = Color.WHITE;
private static final Color MINECOLOR = Color.BLACK;
private static final long serialVersionUID = 1L;
private Playfield playfield;
public CellType type;
public Point cord;
public boolean flagged = false;
public int value = 0;
public Cell(CellType _type, Playfield _playfield, Point _cord) {
type = _type;
cord = _cord;
playfield = _playfield;
setBackground(HIDDENCOLOR);
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
OnMouseClick();
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
super.mousePressed(e);
if (e.getButton() == 3) {
OnMouseRightClick();
}
}
});
}
protected void OnMouseClick() {
if (!flagged) {
reveal();
if (type != CellType.Bomb) {
flood();
} else {
playfield.revealAllBombs();
JOptionPane.showMessageDialog(getParent(),"KABOOM! Try again!");
playfield.reset();
}
}
}
protected void OnMouseRightClick() {
if (isEnabled()) {
if (flagged) {
flagged = false;
setBackground(HIDDENCOLOR);
if (type == CellType.Number) {
playfield.cellDried();
}
} else {
flagged = true;
setBackground(FLAGCOLOR);
if (type == CellType.Number) {
playfield.cellFlooded();
}
}
}
}
public void reveal() {
if (type == CellType.Number) {
if(value > 0) {
setText(String.valueOf(value));
}
} else {
setBackground(MINECOLOR);
}
}
public void flood() {
if (type == CellType.Bomb || flagged) {
return;
}
setBackground(FLOODEDCOLOR);
setEnabled(false);
reveal();
playfield.cellFlooded();
if (value == 0) {
if (cord.y > 0) {
if (playfield.cells[cord.y - 1][cord.x].type == CellType.Number
&& playfield.cells[cord.y - 1][cord.x].isEnabled()) {
playfield.cells[cord.y - 1][cord.x].flood();
}
}
if (cord.x < playfield.Size - 1) {
if (playfield.cells[cord.y][cord.x + 1].type == CellType.Number
&& playfield.cells[cord.y][cord.x + 1].isEnabled()) {
playfield.cells[cord.y][cord.x + 1].flood();
}
}
if (cord.y < playfield.Size - 1) {
if (playfield.cells[cord.y + 1][cord.x].type == CellType.Number
&& playfield.cells[cord.y + 1][cord.x].isEnabled()) {
playfield.cells[cord.y + 1][cord.x].flood();
}
}
if (cord.x > 0) {
if (playfield.cells[cord.y][cord.x - 1].type == CellType.Number
&& playfield.cells[cord.y][cord.x - 1].isEnabled()) {
playfield.cells[cord.y][cord.x - 1].flood();
}
}
}
}
}

33
src/main/java/Minesweeper/MinesweeperGame.java

@ -0,0 +1,33 @@
package Minesweeper;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MinesweeperGame extends JPanel {
private static final long serialVersionUID = 1L;
public static final int WIDTH = 600, HEIGTH = 600;
public Playfield playfield;
public TimerLable tl;
public MinesweeperGame(int _playfieldSize, int _bombAmount) {
this.setSize(WIDTH, HEIGTH);
setLayout(null);
playfield = new Playfield(this, _playfieldSize, _bombAmount);
tl = new TimerLable();
tl.setBounds((WIDTH / 2 - 5), HEIGTH / 2 - 240, 20, 20);
add(tl);
tl.start();
}
public static void main(String[] args) {
JFrame f = new JFrame();
MinesweeperGame MsG = new MinesweeperGame(8, 10);
f.add(MsG);
f.setSize(WIDTH, HEIGTH);
f.setLayout(null);
f.setVisible(true);
}
}

151
src/main/java/Minesweeper/Playfield.java

@ -0,0 +1,151 @@
package Minesweeper;
import java.awt.Point;
import javax.swing.JOptionPane;
public class Playfield {
private static final int CELLSIZE = 50;
public int Size;
private MinesweeperGame MsG;
public Cell[][] cells;
private int bombAmount;
private int cellsFlooded = 0;
public Playfield(MinesweeperGame _MsG, int _Size, int _bombAmount) {
MsG = _MsG;
Size = _Size;
bombAmount = _bombAmount;
generatePlayfield();
}
public void generatePlayfield() {
cells = new Cell[Size][Size];
int[] bPlacement = new int[bombAmount];
for (int i = 0; i < bPlacement.length; i++) {
bPlacement[i] = (int) (Math.random() * Size * Size);
for (int j = 0; j < i; j++) {
if (bPlacement[i] == bPlacement[j]) {
i--;
break;
}
}
}
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
cells[i][j] = new Cell(CellType.Number, this, new Point(j, i));
cells[i][j].setBounds(j * CELLSIZE + (MsG.WIDTH / 2 - Size * CELLSIZE / 2),
i * CELLSIZE + (MsG.HEIGTH / 2 - Size * CELLSIZE / 2), CELLSIZE, CELLSIZE);
MsG.add(cells[i][j]);
for (int k = 0; k < bPlacement.length; k++) {
if (bPlacement[k] == i * Size + j) {
cells[i][j].type = CellType.Bomb;
break;
}
}
}
}
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
if (cells[i][j].type == CellType.Number) {
calculateBombProximity(i, j);
}
}
}
MsG.repaint();
}
public void reset() {
cellsFlooded = 0;
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
MsG.remove(cells[i][j]);
}
}
MsG.tl.reset();
generatePlayfield();
}
public void calculateBombProximity(int row, int column) {
if (row > 0) {
if (column > 0) {
if (cells[row - 1][column - 1].type == CellType.Bomb) {
cells[row][column].value++;
}
}
if (cells[row - 1][column].type == CellType.Bomb) {
cells[row][column].value++;
}
if (column < cells.length - 1) {
if (cells[row - 1][column + 1].type == CellType.Bomb) {
cells[row][column].value++;
}
}
}
if (row < cells.length - 1) {
if (column > 0) {
if (cells[row + 1][column - 1].type == CellType.Bomb) {
cells[row][column].value++;
}
}
if (cells[row + 1][column].type == CellType.Bomb) {
cells[row][column].value++;
}
if (column < cells.length - 1) {
if (cells[row + 1][column + 1].type == CellType.Bomb) {
cells[row][column].value++;
}
}
}
if (column > 0) {
if (cells[row][column - 1].type == CellType.Bomb) {
cells[row][column].value++;
}
}
if (column < cells.length - 1) {
if (cells[row][column + 1].type == CellType.Bomb) {
cells[row][column].value++;
}
}
}
public void cellFlooded() {
cellsFlooded++;
if (cellsFlooded >= Size * Size - bombAmount) {
revealAllBombs();
JOptionPane.showMessageDialog(MsG, "You won, congratulations!");
reset();
}
}
public void revealAllBombs() {
for (int i = 0; i < Size; i++) {
for (int j = 0; j < Size; j++) {
if(cells[i][j].type == CellType.Bomb) {
cells[i][j].reveal();
}
}
}
MsG.tl.stop();
MsG.repaint();
}
public void cellDried() {
cellsFlooded--;
}
}

60
src/main/java/Minesweeper/TimerLable.java

@ -0,0 +1,60 @@
package Minesweeper;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JLabel;
public class TimerLable extends JLabel {
private static final long serialVersionUID = 1L;
protected int counter = 0;
private Helper task;
public void start() {
Timer timer = new Timer();
task = new Helper(this);
timer.schedule(task, 0, 1000);
}
public void update() {
setText(String.valueOf(++counter));
}
public void reset() {
task.reset = true;
counter = 0;
setText(String.valueOf(counter));
repaint();
task.stop = false;
}
public void stop() {
task.stop = true;
}
}
class Helper extends TimerTask
{
public boolean reset;
public boolean stop;
public static int i = 0;
private TimerLable timerLable;
public Helper(TimerLable _timerLable) {
timerLable = _timerLable;
}
public void run()
{
if(stop) {
return;
}
if(reset) {
reset = false;
timerLable.counter = 0;
}
timerLable.update();
}
}

60
src/main/java/TicTacToe/Cell.java

@ -0,0 +1,60 @@
package TicTacToe;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class Cell extends JButton {
public int playerID = 0;
private TicTacToeGame ttt;
public Cell(TicTacToeGame _ttt) {
ttt = _ttt;
setBackground(new Color(0));
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
OnMouseClick();
}
});
}
protected void OnMouseClick() {
if (playerID == 0) {
playerID = ttt.playerID;
setEnabled(false);
ttt.endTurn();
repaint();
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(Color.white);
switch (playerID) {
case 1:
g2.drawLine(5, 5, 90, 90);
g2.drawLine(90, 5, 5, 90);
break;
case 2:
g2.drawOval(5, 5, 90, 90);
break;
}
}
protected void reset() {
playerID = 0;
setEnabled(true);
repaint();
}
}

45
src/main/java/TicTacToe/Scoreboard.java

@ -0,0 +1,45 @@
package TicTacToe;
import java.awt.Color;
import javax.swing.JLabel;
public class Scoreboard extends JLabel{
private static final long serialVersionUID = 1L;
public int[] playerPoints;
public Scoreboard(int _playerCount) {
playerPoints = new int[_playerCount];
setForeground(Color.white);
updateScores();
}
public void addPoint(int playerID) {
playerPoints[playerID]++;
updateScores();
}
public void subPoint(int playerID) {
playerPoints[playerID]--;
updateScores();
}
public void updateScores() {
int gamesPlayed = 0;
for(int i = 0; i < playerPoints.length; i++){
if(i == 0) {
setText("Draws: " + playerPoints[0]);
} else {
setText(getText() + " Player " + i + ": " + playerPoints[i]);
}
gamesPlayed += playerPoints[i];
}
setText(getText() + " Games played: " + gamesPlayed);
}
}

134
src/main/java/TicTacToe/TicTacToeGame.java

@ -0,0 +1,134 @@
package TicTacToe;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class TicTacToeGame extends JPanel {
private static final long serialVersionUID = 1L;
public static final int width = 600, height = 600;
private static final int maxPlayers = 3;
private static final int playFieldSize = 9;
public Cell[] field;
public int playerID = 1;
public int turns = 0;
public Scoreboard scoreboard;
public TicTacToeGame() {
this.setSize(width, height);
setBackground(Color.black);
setLayout(null);
initField();
initScoreboard();
}
public static void main(String[] args) {
JFrame f = new JFrame();
TicTacToeGame ttt = new TicTacToeGame();
f.add(ttt);
f.setSize(width,height);
f.setLayout(null);
f.setVisible(true);
}
public void initField() {
field = new Cell[playFieldSize];
for(int i = 0; i < field.length; i++) {
field[i] = new Cell(this);
add(field[i]);
}
for(int i = 0; i < field.length; i++) {
if(i < 3) {
field[i].setBounds(150 + i*100, 150 , 100, 100);
} else if (i < 6) {
field[i].setBounds(150 + i%3*100, 250 , 100, 100);
} else {
field[i].setBounds(150 + i%3*100, 350 , 100, 100);
}
}
}
private void initScoreboard() {
scoreboard = new Scoreboard(maxPlayers);
scoreboard.setBounds(150, 100, 300, 50);
add(scoreboard);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.white);
Line2D lin = new Line2D.Float(250, 150, 250, 450);
Line2D lin2 = new Line2D.Float(350, 150, 350, 450);
Line2D lin3 = new Line2D.Float(150, 250, 450, 250);
Line2D lin4 = new Line2D.Float(150, 350, 450, 350);
g2.draw(lin);
g2.draw(lin2);
g2.draw(lin3);
g2.draw(lin4);
}
public void endTurn() {
if(checkPlayfield() != 0) {
JOptionPane.showMessageDialog(getParent(),"Player: " + playerID + " Wins!");
scoreboard.addPoint(playerID);
resetGame();
} else {
turns++;
if(turns >= playFieldSize) {
JOptionPane.showMessageDialog(getParent(),"Draw!");
scoreboard.addPoint(0);
resetGame();
}
playerID++;
if(playerID >= maxPlayers) {
playerID = 1;
}
}
}
public int checkPlayfield() {
if ((field[0].playerID == playerID && field[1].playerID == playerID && field[2].playerID == playerID)
|| (field[0].playerID == playerID && field[3].playerID == playerID && field[6].playerID == playerID)
|| (field[8].playerID == playerID && field[5].playerID == playerID && field[2].playerID == playerID)
|| (field[8].playerID == playerID && field[7].playerID == playerID && field[6].playerID == playerID)
|| (field[0].playerID == playerID && field[4].playerID == playerID && field[8].playerID == playerID)
|| (field[0].playerID == playerID && field[4].playerID == playerID && field[8].playerID == playerID)
|| (field[2].playerID == playerID && field[4].playerID == playerID && field[6].playerID == playerID)
|| (field[3].playerID == playerID && field[4].playerID == playerID && field[5].playerID == playerID)
|| (field[1].playerID == playerID && field[4].playerID == playerID && field[7].playerID == playerID)) {
return playerID;
}
return 0;
}
public void resetGame() {
for (Cell c : field) {
c.reset();
}
playerID = 1;
turns = 0;
}
}

100
src/main/java/hauptmenue/GameWindow.java

@ -0,0 +1,100 @@
package hauptmenue;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import Minesweeper.MinesweeperGame;
import TicTacToe.TicTacToeGame;
import solitaer.SolitaerGamePanel;
import solitaer.SolitaerMenue;
public class GameWindow extends JFrame {
private static final long serialVersionUID = 1L;
public GameWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(new Dimension(200, 125));
setLayout(null);
JButton soli = new JButton("Solitaer");
JButton Tic = new JButton("TicTacToe");
JButton Mine = new JButton("Minesweeper");
soli.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
soli.setVisible(false);
Tic.setVisible(false);
Mine.setVisible(false);
initSoli();
}
});
Tic.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
soli.setVisible(false);
Tic.setVisible(false);
Mine.setVisible(false);
initTicTacToe();
}
});
Mine.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
soli.setVisible(false);
Tic.setVisible(false);
Mine.setVisible(false);
initMinesweeper();
}
});
soli.setBounds(0, 0, 200, 30);
Tic.setBounds(0, 30, 200, 30);
Mine.setBounds(0, 60, 200, 30);
add(soli);
add(Tic);
add(Mine);
setVisible(true);
}
private void initSoli() {
SolitaerGamePanel gamePanel = new SolitaerGamePanel();
SolitaerMenue smenue = new SolitaerMenue(gamePanel);
gamePanel.setVisible(true);
gamePanel.setSize(new Dimension(1180, 780));
setSize(new Dimension(1180, 780));
//gamePanel.setPreferredSize(new Dimension(1180, 780));
setJMenuBar(smenue.getMenue());
add(gamePanel);
repaint();
}
public void initTicTacToe() {
TicTacToeGame ttt = new TicTacToeGame();
setSize(ttt.width, ttt.height);
setLayout(null);
add(ttt);
}
public void initMinesweeper() {
MinesweeperGame MsG = new MinesweeperGame(8,10);
setSize(MsG.WIDTH, MsG.HEIGTH);
setLayout(null);
add(MsG);
}
}

10
src/main/java/hauptmenue/main.java

@ -0,0 +1,10 @@
package hauptmenue;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
new GameWindow();
}
}

63
src/main/java/solitaer/AblageStack.java

@ -0,0 +1,63 @@
package solitaer;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class AblageStack extends BaseStack {
private static final long serialVersionUID = 1L;
private Symbol sym;
public AblageStack(int _x, int _y, Symbol _sym) {
super(false);
super.setLocation(_x, _y);
super.setSize(IMAGE_WIDTH, STACK_HIGHT);
super.setOpaque(false);
super.setLayout(null);
this.sym = _sym;
}
@Override
protected boolean cardCheck(Card _topStack, Card _playerCard) {
if(_topStack == null && _playerCard == null) {
return false;
}
if(_playerCard.getSymbol() != this.sym) {
return false;
} else if(_topStack == null) {
//nur ein Ass darf auf einen Leeren Stabel gelegt werden
return _playerCard.getNr() == 1;
} else {
return _topStack.getNr() == _playerCard.getNr() - 1;
}
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
if (stackIsEmpty()) {
g.setColor(Color.gray);
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT);
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth()-1, IMAGE_HIGHT-1);
if (this.sym == Symbol.Herz || this.sym == Symbol.Karo)
g.setColor(Color.red);
else
g.setColor(Color.black);
int fontSize = 20;
Font f = new Font(Font.MONOSPACED, Font.BOLD, fontSize);
g.setFont(f);
String text = this.sym.toString();
g.drawString(text, 5, this.IMAGE_HIGHT/2);
}
}
}

81
src/main/java/solitaer/BaseStack.java

@ -0,0 +1,81 @@
package solitaer;
import java.util.ArrayList;
import javax.swing.JPanel;
public abstract class BaseStack extends JPanel {
public final int IMAGE_WIDTH = 72;
public final int IMAGE_HIGHT = 96;
public final int STACK_HIGHT = 450;
private static final long serialVersionUID = 1L;
private ArrayList<Card> stack = new ArrayList<Card>();
private final int OFFSET_VALUE = 20;
private int offset;
private int addOffset;
public BaseStack(boolean _offset) {
// TODO Auto-generated constructor stub
if(_offset) {
addOffset = OFFSET_VALUE;
}else {
addOffset = 0;
}
offset = 0;
}
public void clearStack() {
stack.clear();
offset = 0;
RenderStackNew();
}
public boolean stackIsEmpty() {
return stack.isEmpty();
}
public Card peekLastCard() {
if(!stackIsEmpty()) {
return stack.get(stack.size()-1);
} else {
return null;
}
}
public int indexOfCard(Card _card) {
return stack.indexOf(_card);
}
public int stackSize() {
return stack.size();
}
public void addCard(Card _card) {
_card.setLocation(0, offset);
stack.add(_card);
RenderStackNew();
offset += addOffset;
}
public Card removeLastCard() {
if (stack.size() != 0) {
Card LastCard = stack.remove(stack.size() - 1);
offset -= addOffset;
RenderStackNew();
return LastCard;
}
return null;
}
private void RenderStackNew() {
this.removeAll();
// Alles neu Zeichnen
for (int i = stack.size() - 1; i >= 0; i--) {
this.add(stack.get(i));
}
this.repaint();
}
protected abstract boolean cardCheck(Card _topStack, Card _playerCard);
}

136
src/main/java/solitaer/Card.java

@ -0,0 +1,136 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Objects;
import javax.swing.JPanel;
enum Symbol {
Herz, Karo, Kreuz, Pik
}
public class Card extends JPanel {
private static final long serialVersionUID = 1L;
private int nr;
private Symbol symbol;
private boolean faceUp;
private final int IMAGE_WIDTH = 72;
private final int IMAGE_HIGHT = 96;
public Card(int _nr, Symbol _symbol, boolean _faceUp) {
this.setSize(IMAGE_WIDTH,IMAGE_HIGHT);
this.nr = _nr;
this.symbol = _symbol;
this.faceUp = _faceUp;
}
public boolean isFaceUp() {
return faceUp;
}
public void setFaceUp(boolean _faceUp) {
this.faceUp = _faceUp;
}
public int getNr() {
return nr;
}
public boolean isred() {
return this.symbol == Symbol.Herz
|| this.symbol == Symbol.Karo;
}
public boolean isblack() {
return this.symbol == Symbol.Kreuz
|| this.symbol == Symbol.Pik;
}
private String getNrText() {
if (this.nr < 10) {
return "0" + this.nr;
} else {
return "" + this.nr;
}
}
public Symbol getSymbol() {
return symbol;
}
private String getSymboleText() {
switch (this.symbol) {
case Herz:
return "Herz";
case Karo:
return "Karo";
case Pik:
return "Pik";
case Kreuz:
return "Kreuz";
default:
return "";
}
}
@Override
public String toString() {
//return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]";
return "Card NR="+nr+" | Symbole="+symbol+" | Face="+faceUp;
}
@Override
public int hashCode() {
return Objects.hash(faceUp, nr, symbol);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Card other = (Card) obj;
return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol;
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
paintCard(g);
}
private void paintCard(Graphics g) {
if (faceUp) {
g.setColor(Color.white);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
if (this.isred())
g.setColor(Color.red);
else
g.setColor(Color.black);
String text = "" + this.getNrText() + " " + this.getSymboleText();
g.drawString(text, 3, 15);
} else {
g.setColor(Color.blue);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
}
}
}

42
src/main/java/solitaer/CardDeck.java

@ -0,0 +1,42 @@
package solitaer;
import java.util.ArrayList;
import java.util.Collections;
public class CardDeck {
private ArrayList<Card> deck = new ArrayList<Card>();
public CardDeck() {
for (int symboleZähler = 0; symboleZähler < 4; symboleZähler++) {
for (int nrZähler = 1; nrZähler <= 13; nrZähler++) {
switch (symboleZähler) {
case 0:
deck.add(new Card(nrZähler, Symbol.Herz, false));
break;
case 1:
deck.add(new Card(nrZähler, Symbol.Karo, false));
break;
case 2:
deck.add(new Card(nrZähler, Symbol.Kreuz, false));
break;
case 3:
deck.add(new Card(nrZähler, Symbol.Pik, false));
break;
}
}
}
}
public ArrayList<Card> getDeck() {
return deck;
}
public void shuffelDeck() {
Collections.shuffle(deck);
}
}

66
src/main/java/solitaer/GeberStack.java

@ -0,0 +1,66 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
public class GeberStack extends BaseStack {
private static final long serialVersionUID = 1L;
private WasteStack wasteStack;
public GeberStack(int _x, int _y, WasteStack _waste) {
super(false);
super.setLocation(_x, _y);
super.setSize(IMAGE_WIDTH, STACK_HIGHT);
super.setOpaque(false);
super.setLayout(null);
this.wasteStack = _waste;
}
public WasteStack getWastStack() {
return wasteStack;
}
public void swapWasteGeber() {
while(wasteStack.stackIsEmpty() == false) {
moveCardTurnFace(wasteStack, this, false);
}
}
public void moveToWaste() {
moveCardTurnFace(this, wasteStack, true);
}
private void moveCardTurnFace(BaseStack _removeStack, BaseStack _addStack, boolean _face) {
Card card = _removeStack.removeLastCard();
card.setFaceUp(_face);
_addStack.addCard(card);
}
@Override
protected boolean cardCheck(Card _topStack, Card _playerCard) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
if (stackIsEmpty()) {
g.setColor(Color.pink);
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT);
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1);
String text = "Start\nAgain";
g.drawString(text, 5, this.IMAGE_HIGHT/2);
}
}
}

199
src/main/java/solitaer/MyMouseListener.java

@ -0,0 +1,199 @@
package solitaer;
import java.awt.Component;
import java.awt.event.MouseEvent;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;
public class MyMouseListener implements MouseInputListener {
private SaveStack saveStack;
private BaseStack tempStack;
private BaseStack selectedStack;
private Card tempCard;
public MyMouseListener(SaveStack _save) {
// TODO Auto-generated constructor stub
this.saveStack = _save;
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("DOWN");
Component com = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
if ((com instanceof Card && com.getParent() instanceof StartStack)
|| (com instanceof StartStack && ((StartStack) com).stackIsEmpty())) {
if (saveStack.stackIsEmpty()) {
if (com instanceof Card && com.getParent() instanceof StartStack) {
tempCard = (Card) com;
tempStack = (StartStack) com.getParent();
// Wenn faceDown, schau ob es die oberste Carde ist und dreh diese um
if (!tempCard.isFaceUp()) {
if (tempStack.peekLastCard().equals(tempCard)) {
tempCard.setFaceUp(true);
tempCard.repaint();
}
}
// Card faceUp
else {
// move all Cards below the selected Card to Save
int index = tempStack.indexOfCard(tempCard);
while (tempStack.stackSize() - 1 >= index) {
saveStack.addCard(tempStack.removeLastCard());
}
selectedStack = tempStack;
}
}
}
// saveStack is NOT empty
else {
if(com instanceof StartStack) {
tempStack = (StartStack) com;
} else {
tempStack = (StartStack) com.getParent();
}
if (selectedStack == null) {
System.out.println("ERROR selectedStack in StartStack");
}
if (tempStack.cardCheck(tempStack.peekLastCard(), saveStack.peekLastCard())) {
clearSaveStack(tempStack);
} else {
clearSaveStack(selectedStack);
}
selectedStack = null;
}
}
// AblageStack
else if (com.getParent() instanceof AblageStack || com instanceof AblageStack) {
System.out.println("AblageStack");
if (com instanceof AblageStack) {
tempStack = (AblageStack) com;
} else {
tempStack = (AblageStack) com.getParent();
}
if (saveStack.stackIsEmpty()) {
// Move Top Card from AblageStack in Save
if (tempStack.stackIsEmpty() == false) {
saveStack.addCard(tempStack.removeLastCard());
selectedStack = tempStack;
}
} else {
// Move Card from Save in AblageStack
if (saveStack.stackSize() == 1) {
if (tempStack.cardCheck(tempStack.peekLastCard(), saveStack.peekLastCard())) {
tempStack.addCard(saveStack.removeLastCard());
}
} else {
// Clear Save
clearSaveStack(selectedStack);
}
}
}
// GeberStack
else if (com.getParent() instanceof GeberStack || com instanceof GeberStack) {
System.out.println("GeberStack");
if (com instanceof GeberStack) {
tempStack = (GeberStack) com;
} else {
tempStack = (GeberStack) com.getParent();
}
if(this.saveStack.stackIsEmpty() == false) {
clearSaveStack(selectedStack);
}
if (tempStack.stackIsEmpty()) {
// Move all from Waste to Geber
((GeberStack) this.tempStack).swapWasteGeber();
} else {
// Move next card to Waste
((GeberStack) this.tempStack).moveToWaste();
}
}
// WasteStack
else if (com.getParent() instanceof WasteStack || com instanceof WasteStack) {
System.out.println("WasteStack");
if (com instanceof WasteStack) {
tempStack = (WasteStack) com;
} else {
tempStack = (WasteStack) com.getParent();
}
if (saveStack.stackIsEmpty()) {
// Move Top Card from AblageStack in Save
if (tempStack.stackIsEmpty() == false) {
saveStack.addCard(tempStack.removeLastCard());
selectedStack = tempStack;
}
} else {
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);
}
}
}
private void clearSaveStack(BaseStack _ziel) {
// Alles wieder auf den Ursprünglichen Stack packen
while (!saveStack.stackIsEmpty()) {
_ziel.addCard(saveStack.removeLastCard());
}
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
}

38
src/main/java/solitaer/SaveStack.java

@ -0,0 +1,38 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
public class SaveStack extends BaseStack {
private static final long serialVersionUID = 1L;
public SaveStack(int _x, int _y) {
// TODO Auto-generated constructor stub
super(true);
super.setLocation(_x, _y);
super.setSize(IMAGE_WIDTH, STACK_HIGHT);
super.setOpaque(false);
super.setLayout(null);
}
@Override
protected boolean cardCheck(Card _topStack, Card _playerCard) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
if (stackIsEmpty()) {
g.setColor(Color.pink);
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT);
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1);
}
}
}

140
src/main/java/solitaer/SolitaerGamePanel.java

@ -0,0 +1,140 @@
package solitaer;
import java.awt.Color;
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 Color backgroundColor = new Color(0, 135, 62);
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);
for (int i = 0; i < STARTSTACK_SIZE; i++) {
int y = setLayouty(1);
start[i] = new StartStack(setLayoutX(i), y);
}
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;
}
}
waste = new WasteStack(setLayoutX(1), OFFSET_STACKS_Y);
geber = new GeberStack(setLayoutX(0), OFFSET_STACKS_Y, waste);
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(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();
}
}
}

50
src/main/java/solitaer/StartStack.java

@ -0,0 +1,50 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
public class StartStack extends BaseStack {
private static final long serialVersionUID = 1L;
public StartStack(int _x, int _y) {
super(true);
super.setLocation(_x, _y);
super.setSize(IMAGE_WIDTH, STACK_HIGHT);
super.setOpaque(false);
super.setLayout(null);
}
public boolean cardCheck(Card _topStack, Card _playerCard) {
if (_topStack == null && _playerCard == null) {
return false;
}
if (_topStack == null) {
// Nur der König kann auf einen leeren Stapel gelegt werden
return _playerCard.getNr() == 13;
} else if (!_topStack.isFaceUp()) {
return false;
} else {
return (// Nummer nur aufsteigend
(_topStack.getNr() == _playerCard.getNr() + 1) &&
// rot auf Schwarz
((_topStack.isred() && _playerCard.isblack()) ||
// schwarz auf rot
(_topStack.isblack() && _playerCard.isred())));
}
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
if (stackIsEmpty()) {
g.setColor(Color.gray);
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT);
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1);
}
}
}

38
src/main/java/solitaer/WasteStack.java

@ -0,0 +1,38 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
public class WasteStack extends BaseStack {
private static final long serialVersionUID = 1L;
public WasteStack(int _x, int _y) {
super(false);
super.setLocation(_x, _y);
super.setSize(IMAGE_WIDTH, STACK_HIGHT);
super.setOpaque(false);
super.setLayout(null);
}
@Override
protected boolean cardCheck(Card _topStack, Card _playerCard) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
if (stackIsEmpty()) {
g.setColor(Color.lightGray);
g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT);
g.setColor(Color.black);
g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1);
}
}
}

53
src/test/java/Minesweeper/MinesweeperGameTest.java

@ -0,0 +1,53 @@
package Minesweeper;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class MinesweeperGameTest {
@ParameterizedTest
@MethodSource("testBombs")
void testBombPlacement(int _playfieldSize, int _bombAmount) {
MinesweeperGame m = new MinesweeperGame(_playfieldSize, _bombAmount);
int bombCounter = 0;
for(Cell[] row : m.playfield.cells){
for (Cell c : row) {
if(c.type == CellType.Bomb) {
bombCounter++;
}
}
}
assertEquals(_bombAmount, bombCounter);
}
@Test
void testProximityPoints() {
MinesweeperGame m = new MinesweeperGame(3, 0);
m.playfield.cells[0][0].type = CellType.Bomb;
m.playfield.calculateBombProximity(1, 1);
assertEquals(1, m.playfield.cells[1][1].value);
}
private static Stream<Arguments> testBombs(){
return Stream.of(
Arguments.of(8, 10),
Arguments.of(8, 0),
Arguments.of(4, 12),
Arguments.of(10, 100),
Arguments.of(5, 1)
);
}
}

77
src/test/java/TicTacToe/TicTacToeGameTest.java

@ -0,0 +1,77 @@
package TicTacToe;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class TicTacToeGameTest {
@ParameterizedTest
@MethodSource("testFieldsWinning")
void testGameEndWin(int[] _field, int _winner) {
TicTacToeGame ttt = new TicTacToeGame();
for(int i = 0; i < ttt.field.length; i++) {
ttt.field[i].playerID = _field[i];
}
ttt.playerID = _winner;
int realWinner = ttt.checkPlayfield();
assertEquals(_winner, realWinner);
}
@ParameterizedTest
@MethodSource("testFieldsDraw")
void testGameEndDraw(int[] _field) {
TicTacToeGame ttt = new TicTacToeGame();
for(int i = 0; i < ttt.field.length; i++) {
ttt.field[i].playerID = _field[i];
}
int noWinner = ttt.checkPlayfield();
assertEquals(0, noWinner);
}
private static Stream<Arguments> testFieldsWinning(){
return Stream.of(
Arguments.of(new int[]{ 1,2,1,
2,2,2,
1,2,1}, 2),
Arguments.of(new int[]{ 2,1,2,
2,2,1,
1,1,1}, 1),
Arguments.of(new int[]{ 1,1,2,
1,2,2,
1,2,1}, 1),
Arguments.of(new int[]{ 2,1,1,
1,2,1,
1,1,2}, 2)
);
}
private static Stream<Arguments> testFieldsDraw(){
return Stream.of(
Arguments.of(new int[]{ 2,1,1,
2,2,2,
1,2,1}),
Arguments.of(new int[]{ 2,1,2,
2,2,1,
1,2,1}),
Arguments.of(new int[]{ 2,1,2,
1,2,2,
1,2,1}),
Arguments.of(new int[]{ 2,1,1,
1,2,2,
2,1,1})
);
}
}

46
src/test/java/solitaer/AblageStackTest.java

@ -0,0 +1,46 @@
package solitaer;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class AblageStackTest {
@ParameterizedTest
@MethodSource("testAblageStackTestDaten")
void testRulesetAblageStack(String _msg, Card _stapel, Card _spieler, boolean _expectedResult) {
AblageStack stack = new AblageStack(0, 0, Symbol.Kreuz);
assertEquals(_expectedResult, stack.cardCheck(_stapel, _spieler), _msg);
}
private static Stream<Arguments> testAblageStackTestDaten(){
return Stream.of(
Arguments.of("Ass-Kreuz auf Leeres Kreuz-Feld",
null,
null, false),
Arguments.of("Ass-Kreuz auf Leeres Kreuz-Feld",
null,
new Card(1, Symbol.Kreuz, true), true),
Arguments.of("02-Kreuz auf Leeres Kreuz-Feld",
null,
new Card(2, Symbol.Kreuz, true), false),
Arguments.of("Ass-Herz auf Leeres Kreuz-Feld",
null,
new Card(1, Symbol.Herz, true), false),
Arguments.of("05-Kreuz auf 04-Kreuz",
new Card(4, Symbol.Kreuz, true),
new Card(5, Symbol.Kreuz, true), true),
Arguments.of("05-Herz auf 04-Kreuz",
new Card(4, Symbol.Kreuz, true),
new Card(5, Symbol.Herz, true), false),
Arguments.of("Ass-Kreuz auf König-Kreuz",
new Card(13, Symbol.Kreuz, true),
new Card(1, Symbol.Kreuz, true), false)
);
}
}

81
src/test/java/solitaer/CardDeckTest.java

@ -0,0 +1,81 @@
package solitaer;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class CardDeckTest {
private CardDeck deck = new CardDeck();
@Test
void testCardDeckSize() {
int result = deck.getDeck().size();
assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ;
}
@ParameterizedTest
@MethodSource("testSymbole")
//Jedes Symbol muss einmal vorhand sein
void testCardDeckSymbole(String _msg, Symbol _sym) {
boolean result = false;
for(int allCardZähler = 0; allCardZähler<deck.getDeck().size(); allCardZähler++) {
if(deck.getDeck().get(allCardZähler).getSymbol() == _sym) {
result = true;
break;
}
}
assertTrue(result, _msg);
}
private static Stream<Arguments> testSymbole(){
return Stream.of(
Arguments.of("Herz", Symbol.Herz),
Arguments.of("Karo", Symbol.Karo),
Arguments.of("Pik", Symbol.Pik),
Arguments.of("Kreuz",Symbol.Kreuz)
);
}
@Test
//Jedes Symbol muss 13 mal vorrhanden sein
void testCardDeckNumber() {
boolean result = true;
result = CheckAllCards(Symbol.Herz) &&
CheckAllCards(Symbol.Karo) &&
CheckAllCards(Symbol.Kreuz) &&
CheckAllCards(Symbol.Pik);
assertTrue(result);
}
private boolean CheckAllCards(Symbol _sym) {
boolean result = true;
for(int nrZähler =1; nrZähler<=13; nrZähler++) {
if(deck.getDeck().contains(new Card(nrZähler, _sym, false))== false) {
result = false;
break;
}
}
return result;
}
}

25
src/test/java/solitaer/GeberStackTest.java

@ -0,0 +1,25 @@
package solitaer;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class GeberStackTest {
@Test
void testswapGeberWaste001() {
WasteStack waste = new WasteStack(0, 0);
GeberStack geber = new GeberStack(0, 0, waste);
for (int i = 1; i < 14; i++) {
waste.addCard(new Card(0, Symbol.Pik, false));
}
int expectedResult = waste.stackSize();
geber.swapWasteGeber();
assertEquals(geber.stackSize(), expectedResult, "same Size");
}
}

38
src/test/java/solitaer/StartStackTest.java

@ -0,0 +1,38 @@
package solitaer;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class StartStackTest {
@ParameterizedTest
@MethodSource("testStartStackTestDaten")
//Jedes Symbol muss einmal vorhand sein
void testRulesetStartStack(String _msg, Card _stapel, Card _spieler, boolean _expectedResult) {
StartStack stack = new StartStack(10, 10);
assertEquals(_expectedResult, stack.cardCheck(_stapel, _spieler), _msg);
}
private static Stream<Arguments> testStartStackTestDaten(){
return Stream.of(
Arguments.of("Ass-Kreuz auf 2-Herz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true),
Arguments.of("Ass-Herz auf 2-Herz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Herz, true), false),
Arguments.of("Ass-Herz auf 2-Herz", new Card(1, Symbol.Herz, true), new Card(2, Symbol.Herz, true), false),
Arguments.of("Ass-Kreuz auf leeres Feld", null, new Card(1, Symbol.Kreuz, true), false),
Arguments.of("König auf leeres Feld", null, new Card(13, Symbol.Kreuz, true), true),
Arguments.of("5-Pik auf 6-Karo", new Card(6, Symbol.Karo, true), new Card(5, Symbol.Pik, true), true),
Arguments.of("König-Karo auf Ass-Kreuz", new Card(1, Symbol.Kreuz, true), new Card(13, Symbol.Karo, true), false),
Arguments.of("5-Karo auf 7-Kreuz", new Card(7, Symbol.Kreuz, true), new Card(5, Symbol.Karo, true), false),
Arguments.of("Ass-Herz auf 2-Kreuz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true),
Arguments.of("null auf null", null, null, false),
Arguments.of("Ass-Herz auf face-Down-2-Kreuz", new Card(2, Symbol.Herz, false), new Card(1, Symbol.Kreuz, true), false)
);
}
}
Loading…
Cancel
Save