diff --git a/PokerKata/src/session3/PokerGame.java b/PokerKata/src/session3/PokerGame.java index 0fd5f3f..28decad 100644 --- a/PokerKata/src/session3/PokerGame.java +++ b/PokerKata/src/session3/PokerGame.java @@ -1,4 +1,4 @@ -/* +/** * PokerGame.java * * Course in Software Craftsmenship @ Högskolan Väst @@ -11,6 +11,12 @@ package session3; import java.util.Arrays; +/** + * Gives you a score with a hand of poker + * + * @author crille + * + */ public class PokerGame { public int getScore(String hand) { int score = 0; @@ -30,6 +36,13 @@ public class PokerGame { return score; } + /** + * Finds a pair by looking if two cards next to each other has the same + * value + * + * @param hand + * @return true if there is a pair, otherwise false + */ private boolean findPair(String hand) { char[] values = getValues(hand); @@ -41,6 +54,13 @@ public class PokerGame { return false; } + /** + * Finds a pair by looking if three cards next to each other has the same + * value + * + * @param hand + * @return true if there is a Three of a kind, otherwise false + */ private boolean findThreeOfAKind(String hand) { char[] values = getValues(hand); @@ -52,6 +72,13 @@ public class PokerGame { return false; } + /** + * Finds two pairs by looking for a pair, and them look if the remaining + * cards is a pair + * + * @param hand + * @return true if there is two pairs, otherwise false + */ private boolean findTwoPairs(String hand) { char[] values = getValues(hand); @@ -72,6 +99,13 @@ public class PokerGame { return false; } + /** + * Finds Four of a kind by first finding Three of a kind and then looks if + * one of the remaining cards matches + * + * @param hand + * @return true if there is a Four of a kind, otherwise false + */ private boolean findFourOfAKind(String hand) { char[] values = getValues(hand); @@ -84,17 +118,29 @@ public class PokerGame { return false; } + /** + * Finds a prison (kåk = prison). We have a prison if the first and last two + * cards are a pair, and the middle card has same value as either of them + * (is three of a kind) + * + * @param hand + * @return true if there is a prison, otherwise false + */ private boolean findPrison(String hand) { char[] values = getValues(hand); - // We have a prison if the first and last two cards are a pair, and the - // middle card has same value as either of them (is three of a kind) if (values[0] == values[1] && values[3] == values[4] && (values[0] == values[2] || values[2] == values[3])) return true; return false; } + /** + * Extracts all the values from the given String (hand) + * + * @param hand + * @return The values of all the cards + */ private char[] getValues(String hand) { char[] values = "".toCharArray(); String temp = ""; diff --git a/PokerKata/test/session3/PokerGameTest.java b/PokerKata/test/session3/PokerGameTest.java index 7a252e8..6e0f988 100644 --- a/PokerKata/test/session3/PokerGameTest.java +++ b/PokerKata/test/session3/PokerGameTest.java @@ -1,4 +1,4 @@ -/* +/** * PokerGame.java * * Course in Software Craftsmenship @ Högskolan Väst