Skip to content
Snippets Groups Projects
Commit d33e9433 authored by your_username's avatar your_username
Browse files

made som java doc

parent 1bc0ce40
Branches
No related tags found
No related merge requests found
...@@ -41,6 +41,10 @@ public class Controller { ...@@ -41,6 +41,10 @@ public class Controller {
deck.refillDeck(); deck.refillDeck();
} }
/**
* Checks the hand for different values.
* @param event the click on the button.
*/
public void checkCards(ActionEvent event){ public void checkCards(ActionEvent event){
try { try {
......
...@@ -7,6 +7,9 @@ import java.util.Random; ...@@ -7,6 +7,9 @@ import java.util.Random;
public class DeckOfCards { public class DeckOfCards {
/**
* the constructor of the deck. makes 52 different cards.
*/
private final char[] suit = {'S','H','D','C'}; private final char[] suit = {'S','H','D','C'};
private ArrayList<PlayingCard> cards; private ArrayList<PlayingCard> cards;
private Random random; private Random random;
...@@ -21,10 +24,19 @@ public class DeckOfCards { ...@@ -21,10 +24,19 @@ public class DeckOfCards {
} }
} }
/**
* removes a card from the deck.
* @param card PlayingCard
*/
public void removeCardFromDeck(PlayingCard card){ public void removeCardFromDeck(PlayingCard card){
cards.remove(card); cards.remove(card);
} }
/**
* deals the hand in the game
* @param n the amount of cards in the game
* @return a hand of cards
*/
public List<PlayingCard> dealHand(int n){ public List<PlayingCard> dealHand(int n){
List<PlayingCard> hand = new ArrayList<>(); List<PlayingCard> hand = new ArrayList<>();
PlayingCard cardDealt = null; PlayingCard cardDealt = null;
...@@ -36,6 +48,10 @@ public class DeckOfCards { ...@@ -36,6 +48,10 @@ public class DeckOfCards {
return hand; return hand;
} }
/**
* refills the deck after use
* @return a refilled dek of cards
*/
public List<PlayingCard> refillDeck(){ public List<PlayingCard> refillDeck(){
cards.removeAll(cards); cards.removeAll(cards);
for (char c : suit) { for (char c : suit) {
......
...@@ -11,13 +11,20 @@ public class PokerCardHand { ...@@ -11,13 +11,20 @@ public class PokerCardHand {
this.hand = hand; this.hand = hand;
} }
/**
* test if the hand has a flush. 5 card og the same suit.
* @return a boolean. true if it has a flush
*/
public boolean isFlush(){ public boolean isFlush(){
if(hand.stream().filter(c -> c.getSuit() == hand.get(0).getSuit()).collect(Collectors.toList()).size() >= 5){ return hand.stream().collect(Collectors.groupingBy(PlayingCard::getSuit, Collectors.counting()))
return true; .values().stream().anyMatch(x -> x >= 5);
}
return false;
} }
/**
* test if the hand has a straight. 5 cards increasing.
* @return a boolean. true if it has a straight
*/
public boolean isStraight(){ public boolean isStraight(){
hand.sort(Comparator.comparingInt(PlayingCard::getFace)); hand.sort(Comparator.comparingInt(PlayingCard::getFace));
for (int i = 0; i<hand.size()-1;i++){ for (int i = 0; i<hand.size()-1;i++){
...@@ -28,11 +35,19 @@ public class PokerCardHand { ...@@ -28,11 +35,19 @@ public class PokerCardHand {
return true; return true;
} }
/**
* finds the total value og the hand
* @return an int, the total value
*/
public int totalValue(){ public int totalValue(){
int sum = hand.stream().mapToInt(PlayingCard::getFace).sum(); int sum = hand.stream().mapToInt(PlayingCard::getFace).sum();
return sum; return sum;
} }
/**
* finds all the harts og the hand
* @return string if all the harts
*/
public String getAllHarts(){ public String getAllHarts(){
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
...@@ -42,6 +57,10 @@ public class PokerCardHand { ...@@ -42,6 +57,10 @@ public class PokerCardHand {
return stringBuilder.toString(); return stringBuilder.toString();
} }
/**
* makes a string of the hand
* @return a string of the hand
*/
public String getStringRepresentationHand(){ public String getStringRepresentationHand(){
return this.hand.stream() return this.hand.stream()
...@@ -49,10 +68,17 @@ public class PokerCardHand { ...@@ -49,10 +68,17 @@ public class PokerCardHand {
.collect(Collectors.joining(" ")); .collect(Collectors.joining(" "));
} }
/**
* finds out if the hand has a queen
* @return a boolean, true if it has a queen
*/
public boolean containsQueenOfSpades(){ public boolean containsQueenOfSpades(){
return hand.stream().anyMatch(playingCard -> playingCard.getFace() == 12 && playingCard.getSuit()=='S'); return hand.stream().anyMatch(playingCard -> playingCard.getFace() == 12 && playingCard.getSuit()=='S');
} }
/**
* @return the hand
*/
public List<PlayingCard> getHand() { public List<PlayingCard> getHand() {
return hand; return hand;
} }
......
...@@ -21,7 +21,7 @@ public class CardHandsTest { ...@@ -21,7 +21,7 @@ public class CardHandsTest {
} }
private PokerCardHand testDataFlushWithEightCards(){ private PokerCardHand testDataFlushWithEightCards(){
ArrayList<PlayingCard> sameSuit = new ArrayList<>(); ArrayList<PlayingCard> sameSuit = new ArrayList<>();
sameSuit.add( new PlayingCard('H',1)); sameSuit.add( new PlayingCard('S',1));
sameSuit.add( new PlayingCard('H',2)); sameSuit.add( new PlayingCard('H',2));
sameSuit.add( new PlayingCard('H',3)); sameSuit.add( new PlayingCard('H',3));
sameSuit.add( new PlayingCard('H',4)); sameSuit.add( new PlayingCard('H',4));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment