bugfixes and a few tests
This commit is contained in:
8
pom.xml
8
pom.xml
@@ -7,6 +7,14 @@
|
|||||||
<groupId>com.tman</groupId>
|
<groupId>com.tman</groupId>
|
||||||
<artifactId>MauMau</artifactId>
|
<artifactId>MauMau</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
|||||||
@@ -17,4 +17,11 @@ public class Card {
|
|||||||
public VALUENUM getValue() {
|
public VALUENUM getValue() {
|
||||||
return CARD_VALUE;
|
return CARD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
if (CARD_TYPE == TYPENUM.JOKER){
|
||||||
|
return CARD_TYPE.name();
|
||||||
|
}
|
||||||
|
return CARD_TYPE.name() + " " + CARD_VALUE.name();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class Dealer {
|
|||||||
public List<Card> getHand() {
|
public List<Card> getHand() {
|
||||||
List<Card> deck = this.deck.getDeck();
|
List<Card> deck = this.deck.getDeck();
|
||||||
List<Card> hand = new ArrayList<>();
|
List<Card> hand = new ArrayList<>();
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
hand.add(deck.get(i));
|
hand.add(deck.get(i));
|
||||||
deck.remove(i);
|
deck.remove(i);
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,7 @@ public class Dealer {
|
|||||||
public Card getInitialCard() {
|
public Card getInitialCard() {
|
||||||
List<Card> deck = this.deck.getDeck();
|
List<Card> deck = this.deck.getDeck();
|
||||||
Card card = deck.get(0);
|
Card card = deck.get(0);
|
||||||
|
deck.remove(0);
|
||||||
this.deck.addUsedCard(card);
|
this.deck.addUsedCard(card);
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import mau.mau.players.Human;
|
|||||||
import mau.mau.players.Player;
|
import mau.mau.players.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
@@ -13,7 +14,8 @@ public class Game {
|
|||||||
private Dealer dealer;
|
private Dealer dealer;
|
||||||
private Human human;
|
private Human human;
|
||||||
private Referee referee = new Referee();
|
private Referee referee = new Referee();
|
||||||
private List<Player> players = new ArrayList<>();
|
private List<Player> turnOrder = new ArrayList<>();
|
||||||
|
private Boolean skipNextPlayer = false;
|
||||||
|
|
||||||
public Game() {
|
public Game() {
|
||||||
setupGame();
|
setupGame();
|
||||||
@@ -23,28 +25,41 @@ public class Game {
|
|||||||
private void setupGame() {
|
private void setupGame() {
|
||||||
dealer = new Dealer(deck);
|
dealer = new Dealer(deck);
|
||||||
human = new Human(dealer);
|
human = new Human(dealer);
|
||||||
players.add(human);
|
turnOrder.add(human);
|
||||||
players.add(new Bot(dealer));
|
turnOrder.add(new Bot(dealer));
|
||||||
dealer.dealCards(players);
|
dealer.dealCards(turnOrder);
|
||||||
currentCard = dealer.getInitialCard();
|
currentCard = dealer.getInitialCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playGame() {
|
private void playGame() {
|
||||||
while (!human.handIsEmpty()) {
|
while (turnOrder.size() > 1) {
|
||||||
if (players.size() == 1) {
|
for (Player player : turnOrder) {
|
||||||
System.out.println("Game has ended");
|
if (skipNextPlayer) {
|
||||||
break;
|
skipNextPlayer = false;
|
||||||
}
|
continue;
|
||||||
for (Player player : players) {
|
}
|
||||||
System.out.println("Current card is " + currentCard.getType() + " " + currentCard.getValue());
|
System.out.println("Current card is " + currentCard.getType() + " " + currentCard.getValue());
|
||||||
Card card = player.getPlay(currentCard);
|
Card card = player.getPlay(currentCard);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
playCard(card);
|
playCard(card);
|
||||||
}
|
}
|
||||||
|
if (player.getHandSize() == 0) {
|
||||||
|
if (Referee.isValidEndCard(currentCard)) {
|
||||||
|
System.out.println(player.getClass().getSimpleName() + " won!");
|
||||||
|
turnOrder.remove(player);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.out.println("You can't end with this card!");
|
||||||
|
player.addCardToHand(card);
|
||||||
|
}
|
||||||
|
turnOrder.remove(player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
System.out.println(deck.getDeck().size() + " cards left in deck");
|
System.out.println(deck.getDeck().size() + " cards left in deck");
|
||||||
players.removeIf(Player::handIsEmpty);
|
turnOrder.removeIf(Player::handIsEmpty);
|
||||||
}
|
}
|
||||||
|
System.out.println("Game has ended");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playCard(Card card) {
|
public void playCard(Card card) {
|
||||||
@@ -52,31 +67,39 @@ public class Game {
|
|||||||
deck.addUsedCard(card);
|
deck.addUsedCard(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSpecialCard(Card card) {
|
public void handleTurn(Card card) {
|
||||||
TYPENUM cardType = card.getType();
|
TYPENUM cardType = card.getType();
|
||||||
VALUENUM cardValue = card.getValue();
|
VALUENUM cardValue = card.getValue();
|
||||||
if (cardType == TYPENUM.JOKER) {
|
if (cardType == TYPENUM.JOKER) {
|
||||||
// Draw 5 cards
|
// Draw 5 cards
|
||||||
|
// Choose color
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (cardValue) {
|
switch (cardValue) {
|
||||||
case TWO:
|
case TWO:
|
||||||
// Draw 2 cards
|
handleTwo();
|
||||||
break;
|
return;
|
||||||
case SEVEN:
|
case SEVEN:
|
||||||
case KING:
|
case KING:
|
||||||
// Keep turn
|
// Keep turn
|
||||||
break;
|
return;
|
||||||
case EIGHT:
|
case EIGHT:
|
||||||
// Skip next player
|
// Skip next player
|
||||||
break;
|
return;
|
||||||
case JACK:
|
case JACK:
|
||||||
// Draw 5 cards
|
// Draw 5 cards
|
||||||
// Change card type
|
// Change card type
|
||||||
break;
|
return;
|
||||||
case ACE:
|
case ACE:
|
||||||
// Change direction
|
Collections.reverse(turnOrder);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleTwo(){
|
||||||
|
Player player = turnOrder.get(1);
|
||||||
|
player.addCardToHand(dealer.drawCard());
|
||||||
|
player.addCardToHand(dealer.drawCard());
|
||||||
|
skipNextPlayer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mau.mau;
|
package mau.mau;
|
||||||
|
|
||||||
public class Referee {
|
public class Referee {
|
||||||
|
|
||||||
public static boolean isValidMove(Card currentCard, Card playedCard) {
|
public static boolean isValidMove(Card currentCard, Card playedCard) {
|
||||||
TYPENUM currentCardType = currentCard.getType();
|
TYPENUM currentCardType = currentCard.getType();
|
||||||
VALUENUM currentCardValue = currentCard.getValue();
|
VALUENUM currentCardValue = currentCard.getValue();
|
||||||
@@ -11,4 +12,20 @@ public class Referee {
|
|||||||
|| playedCardType == currentCardType
|
|| playedCardType == currentCardType
|
||||||
|| playedCardValue == currentCardValue;
|
|| playedCardValue == currentCardValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isMauCard(Card card) {
|
||||||
|
TYPENUM cardType = card.getType();
|
||||||
|
VALUENUM cardValue = card.getValue();
|
||||||
|
if (cardType == TYPENUM.JOKER) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return switch (cardValue) {
|
||||||
|
case TWO, SEVEN, EIGHT, JACK, KING, ACE -> true;
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isValidEndCard(Card card) {
|
||||||
|
return !isMauCard(card);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,9 @@ public abstract class Player {
|
|||||||
|
|
||||||
public Player(Dealer dealer) {
|
public Player(Dealer dealer) {
|
||||||
this.dealer = dealer;
|
this.dealer = dealer;
|
||||||
this.hand = dealer.getHand();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Card> getHand() {
|
public List<Card> getHand() {
|
||||||
return hand;
|
return hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,32 @@
|
|||||||
package mau.mau;public class CardTest {
|
package mau.mau;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class CardTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAceOfSpadesPrintedCorrectlyTest() {
|
||||||
|
//Assign
|
||||||
|
Card card = new Card(TYPENUM.SPADES, VALUENUM.ACE);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
String result = card.toString();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
assertEquals("SPADES ACE", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isJokerPrintedCorrectlyTest() {
|
||||||
|
//Assign
|
||||||
|
Card card = new Card(TYPENUM.JOKER, VALUENUM.TWO);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
String result = card.toString();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
assertEquals("JOKER", result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,21 @@
|
|||||||
package mau.mau;public class DealerTest {
|
package mau.mau;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class DealerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isDealerAGoodShufflerTest() {
|
||||||
|
//Assign
|
||||||
|
Deck deck = new Deck();
|
||||||
|
Dealer sut = new Dealer(deck);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
// sut.shuffleDeck();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
package mau.mau;public class DeckTest {
|
package mau.mau;
|
||||||
|
|
||||||
|
public class DeckTest {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
Bot
|
||||||
|
|
||||||
|
Human
|
||||||
|
|
||||||
|
Player
|
||||||
|
|
||||||
|
~~Card~~
|
||||||
|
|
||||||
|
Dealer
|
||||||
|
|
||||||
|
Deck
|
||||||
|
|
||||||
|
Game
|
||||||
|
|
||||||
|
~~Referee~~
|
||||||
|
|
||||||
|
Utils
|
||||||
Reference in New Issue
Block a user