- Added win with quartet implementation
- Wrote a test to check if quartet worked - Wrote a test to check if a non-valid quartet didn't work - Updated TODO.md
This commit is contained in:
@@ -12,11 +12,9 @@ public class Game {
|
||||
private Card currentCard;
|
||||
private final Deck deck = new Deck();
|
||||
private Dealer dealer;
|
||||
private CardHandler cardHandler = new CardHandler();
|
||||
private final CardHandler cardHandler = new CardHandler();
|
||||
private TurnTable turnTable;
|
||||
private final List<Player> players = new ArrayList<>();
|
||||
private int playerTurn = 0;
|
||||
private Boolean reverse = false;
|
||||
|
||||
public Game() {
|
||||
setupGame();
|
||||
@@ -59,7 +57,7 @@ public class Game {
|
||||
}
|
||||
System.out.println(deck.getDeck().size() + " cards left in deck");
|
||||
} else {
|
||||
if(Referee.isValidEndCard(playedCard)) {
|
||||
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(playedCard)) {
|
||||
playCard(playedCard);
|
||||
System.out.println(player.getName() + " won!");
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package mau.mau;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Referee {
|
||||
|
||||
public static ArrayList<TYPENUM> allowedTypes = new ArrayList<>();
|
||||
|
||||
public static boolean isAmazedByAmazingQuartet = false;
|
||||
|
||||
public static boolean isValidMove(Card currentCard, Card playedCard) {
|
||||
|
||||
TYPENUM currentCardType = currentCard.getType();
|
||||
@@ -35,6 +38,25 @@ public class Referee {
|
||||
return !isMauCard(card);
|
||||
}
|
||||
|
||||
public static boolean isValidQuartet(List<Card> hand){
|
||||
boolean result = false;
|
||||
|
||||
for (Card card : hand) {
|
||||
int count = 0;
|
||||
for (Card card1 : hand) {
|
||||
if (card.getValue() == card1.getValue()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 4) {
|
||||
result = true;
|
||||
Referee.isAmazedByAmazingQuartet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setAllowedCards(TYPENUM type) {
|
||||
allowedTypes.add(type);
|
||||
allowedTypes.add(TYPENUM.JOKER);
|
||||
|
||||
@@ -14,7 +14,6 @@ public class Human extends Player {
|
||||
@Override
|
||||
public Card getPlay(Card currentCard) {
|
||||
printHand();
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
List<Card> hand = getHand();
|
||||
@@ -30,6 +29,16 @@ public class Human extends Player {
|
||||
hand.add(card);
|
||||
return null;
|
||||
}
|
||||
if (input.equals("quartet")) {
|
||||
if (Referee.isValidQuartet(hand)) {
|
||||
System.out.println("You played a quartet!");
|
||||
|
||||
hand.clear();
|
||||
return null;
|
||||
}
|
||||
System.out.println("You don't have a quartet!");
|
||||
continue;
|
||||
}
|
||||
if (Utils.isNumeric(input)) {
|
||||
int cardIndex = Integer.parseInt(input);
|
||||
if (cardIndex < 0 || cardIndex > hand.size()) {
|
||||
@@ -96,5 +105,6 @@ public class Human extends Player {
|
||||
System.out.printf("| (%s) %s ", i, card);
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# TODO
|
||||
1. Refactoring
|
||||
2. Huisregels toevoegen
|
||||
* Kwartet = win
|
||||
* ~~Kwartet = win~~
|
||||
* 69 mag tegelijk opgelegd worden
|
||||
* ~~Als er 2 spelers zijn, mag je 2x na een Ace~~
|
||||
3. Spelers kunnen een naam kiezen
|
||||
|
||||
@@ -2,6 +2,8 @@ package mau.mau;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -119,4 +121,36 @@ public class RefereeTest {
|
||||
//Assert
|
||||
assertTrue(results);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAFourOfEveryTypeAValidQuartetTest(){
|
||||
//Arrange
|
||||
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.FOUR);
|
||||
Card testCardTwo = new Card(TYPENUM.DIAMONDS, VALUENUM.FOUR);
|
||||
Card testCardThree = new Card(TYPENUM.SPADES, VALUENUM.FOUR);
|
||||
Card testCardFour = new Card(TYPENUM.CLUBS, VALUENUM.FOUR);
|
||||
List<Card> hand = List.of(testCardOne, testCardTwo, testCardThree, testCardFour);
|
||||
|
||||
//Act
|
||||
boolean results = Referee.isValidQuartet(hand);
|
||||
|
||||
//Assert
|
||||
assertTrue(results);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isTwoFoursAndTwoThreesAValidQuartetTest(){
|
||||
//Arrange
|
||||
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.FOUR);
|
||||
Card testCardTwo = new Card(TYPENUM.DIAMONDS, VALUENUM.FOUR);
|
||||
Card testCardThree = new Card(TYPENUM.SPADES, VALUENUM.THREE);
|
||||
Card testCardFour = new Card(TYPENUM.CLUBS, VALUENUM.THREE);
|
||||
List<Card> hand = List.of(testCardOne, testCardTwo, testCardThree, testCardFour);
|
||||
|
||||
//Act
|
||||
boolean results = Referee.isValidQuartet(hand);
|
||||
|
||||
//Assert
|
||||
assertFalse(results);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user