Browse Source
Merge commit 'a10127d1b227a91831a48e2bbb2c2ef603b71c87' into HEAD
feature_solitaer_MouseInput
Merge commit 'a10127d1b227a91831a48e2bbb2c2ef603b71c87' into HEAD
feature_solitaer_MouseInput
Jenkins
3 years ago
7 changed files with 272 additions and 0 deletions
-
22.gitignore
-
27src/main/java/hauptmenue/GameWindow.java
-
10src/main/java/hauptmenue/main.java
-
68src/main/java/solitaer/Card.java
-
36src/main/java/solitaer/CardDeck.java
-
28src/main/java/solitaer/SolitaerGamePanel.java
-
81src/test/java/solitaer/CardDeckTest.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); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,10 @@ |
|||
package hauptmenue; |
|||
|
|||
public class main { |
|||
|
|||
public static void main(String[] args) { |
|||
// TODO Auto-generated method stub |
|||
new GameWindow(); |
|||
} |
|||
|
|||
} |
@ -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; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -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; |
|||
} |
|||
|
|||
} |
@ -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()); |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
|
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue