Browse Source

Merge commit 'a10127d1b227a91831a48e2bbb2c2ef603b71c87' into HEAD

feature_solitaer_MouseInput
Jenkins 3 years ago
parent
commit
9aa621c531
  1. 22
      .gitignore
  2. 27
      src/main/java/hauptmenue/GameWindow.java
  3. 10
      src/main/java/hauptmenue/main.java
  4. 68
      src/main/java/solitaer/Card.java
  5. 36
      src/main/java/solitaer/CardDeck.java
  6. 28
      src/main/java/solitaer/SolitaerGamePanel.java
  7. 81
      src/test/java/solitaer/CardDeckTest.java

22
.gitignore

@ -23,3 +23,25 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* 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

27
src/main/java/hauptmenue/GameWindow.java

@ -0,0 +1,27 @@
package hauptmenue;
import java.awt.Dimension;
import javax.swing.JFrame;
import solitaer.SolitaerGamePanel;
public class GameWindow extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private final SolitaerGamePanel gamePanel = new SolitaerGamePanel();
public GameWindow() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gamePanel.setPreferredSize(new Dimension(1180, 780));
add(gamePanel);
pack();
setVisible(true);
}
}

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();
}
}

68
src/main/java/solitaer/Card.java

@ -0,0 +1,68 @@
package solitaer;
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;
public Card(int nr, Symbol symbol, boolean faceUp) {
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 Symbol getSymbol() {
return symbol;
}
@Override
public String toString() {
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + 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;
}
}

36
src/main/java/solitaer/CardDeck.java

@ -0,0 +1,36 @@
package solitaer;
import java.util.ArrayList;
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;
}
}

28
src/main/java/solitaer/SolitaerGamePanel.java

@ -0,0 +1,28 @@
package solitaer;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class SolitaerGamePanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
public SolitaerGamePanel() {
setLayout(null);
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.setColor(Color.green);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}

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;
}
}
Loading…
Cancel
Save