Merge pull request #1 from DTieman/jordans_playground
Console hand print change, win with quartet implementation added, fixed a lot of IDE warnings
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -11,7 +11,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<version>5.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -30,6 +30,7 @@ public class CardHandler {
|
||||
|
||||
private void handleTwo(TurnTable turnTable) {
|
||||
drawCards(turnTable.getNextPlayer(), 2);
|
||||
System.out.printf("%s was forced to draw 2 cards\n", turnTable.getNextPlayer().getName());
|
||||
turnTable.skipNextPlayer();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Dealer {
|
||||
private Deck deck;
|
||||
private final Deck deck;
|
||||
|
||||
public Dealer(Deck deck) {
|
||||
this.deck = deck;
|
||||
|
||||
@@ -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();
|
||||
@@ -50,7 +48,7 @@ public class Game {
|
||||
}
|
||||
System.out.println(deck.getDeck().size() + " cards left in deck");
|
||||
} else {
|
||||
if(Referee.isValidEndCard(currentCard, playedCard)) {
|
||||
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(currentCard, 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(playedCard) && isValidMove(currentCard, playedCard);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package mau.mau;
|
||||
|
||||
public enum TYPENUM {
|
||||
SPADES, HEARTS, DIAMONDS, CLUBS, JOKER;
|
||||
SPADES, HEARTS, DIAMONDS, CLUBS, JOKER
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import mau.mau.players.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class TurnTable {
|
||||
private List<Player> players;
|
||||
private final List<Player> players;
|
||||
private int currentPlayerIndex;
|
||||
private int direction;
|
||||
|
||||
|
||||
@@ -4,13 +4,12 @@ import mau.mau.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Bot extends Player {
|
||||
|
||||
private static int nameIndex = 0;
|
||||
private static String JSON = "src/main/resources/languages/en.json";
|
||||
private static String JSON_KEY = "botnames";
|
||||
private static final String JSON = "src/main/resources/languages/en.json";
|
||||
private static final String JSON_KEY = "bot-names";
|
||||
|
||||
public Bot(Dealer dealer) {
|
||||
super(dealer);
|
||||
@@ -82,7 +81,7 @@ public class Bot extends Player {
|
||||
try {
|
||||
return JSONderulo.getJSONArrayFromJSONFile(JSON, JSON_KEY).getString(nameIndex++);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error reading botnames from JSON file");
|
||||
System.out.println("Error reading bot-names from JSON file");
|
||||
return "Koet " + nameIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ public class Human extends Player {
|
||||
public Card getPlay(Card currentCard) {
|
||||
System.out.println();
|
||||
printHand();
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
List<Card> hand = getHand();
|
||||
@@ -31,6 +30,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()) {
|
||||
@@ -103,7 +112,13 @@ public class Human extends Player {
|
||||
List<Card> hand = getHand();
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
Card card = hand.get(i);
|
||||
System.out.println("(" + i + ") " + card);
|
||||
if (i == 0) {
|
||||
System.out.println("Your hand: ");
|
||||
System.out.printf("(%s) %s ", i, card);
|
||||
} else {
|
||||
System.out.printf("| (%s) %s ", i, card);
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import java.util.List;
|
||||
|
||||
public abstract class Player {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
private List<Card> hand;
|
||||
private Dealer dealer;
|
||||
private final Dealer dealer;
|
||||
|
||||
public Player(Dealer dealer) {
|
||||
this.dealer = dealer;
|
||||
@@ -21,8 +21,8 @@ public abstract class Player {
|
||||
return hand;
|
||||
}
|
||||
|
||||
public List<Card> setHand(List<Card> hand) {
|
||||
return this.hand = hand;
|
||||
public void setHand(List<Card> hand) {
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public Boolean handIsEmpty() {
|
||||
|
||||
@@ -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~~
|
||||
@@ -16,6 +16,7 @@
|
||||
1. ~~Teveel kaarten in deck na het opnieuw schudden~~
|
||||
2. Dezelfde type kaart als de boer mag alsnog opgelegd worden
|
||||
3. Je kan als laatste kaart een pestkaart opleggen
|
||||
4. Wanneer je een nieuwe type mag kiezen met een boer of joker, moet je 2 keer kiezen
|
||||
|
||||
### In een land hier ver, ver vandaan
|
||||
1. UI
|
||||
|
||||
@@ -20,7 +20,7 @@ loop until someone wins
|
||||
else draw
|
||||
User -> Player: draw()
|
||||
end
|
||||
else bot's turn
|
||||
else bots turn
|
||||
alt play
|
||||
Bot -> Player: play(card)
|
||||
Game <-- Player: playedCard
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"botnames": [
|
||||
"bot-names": [
|
||||
"Jordan",
|
||||
"MaarKoet",
|
||||
"El Tigre"
|
||||
|
||||
@@ -15,13 +15,12 @@ public class CardHandlerTest {
|
||||
private CardHandler sut;
|
||||
private TurnTable turnTable;
|
||||
private List<Player> players;
|
||||
private Dealer dealer;
|
||||
private Bot bot1, bot2, bot3;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
//Arrange
|
||||
dealer = new Dealer(new Deck());
|
||||
Dealer dealer = new Dealer(new Deck());
|
||||
sut = new CardHandler();
|
||||
players = new ArrayList<>();
|
||||
turnTable = new TurnTable(players);
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
package mau.mau;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DealerTest {
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -97,7 +99,7 @@ public class RefereeTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void isAceOfSpadesValidEndcardTest(){
|
||||
public void isAceOfSpadesValidEndCardTest(){
|
||||
//Arrange
|
||||
Card testCardOne = new Card(TYPENUM.SPADES, VALUENUM.ACE);
|
||||
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
||||
@@ -110,7 +112,7 @@ public class RefereeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isThreeOfHeartsValidEndcardTest(){
|
||||
public void isThreeOfHeartsValidEndCardTest(){
|
||||
//Arrange
|
||||
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.THREE);
|
||||
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
||||
@@ -121,4 +123,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
public class BotTest {
|
||||
|
||||
private Bot sut;
|
||||
private Dealer dealer;
|
||||
private Deck deck;
|
||||
private List<Card> hand;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
deck = new Deck();
|
||||
dealer = new Dealer(deck);
|
||||
Deck deck = new Deck();
|
||||
Dealer dealer = new Dealer(deck);
|
||||
sut = new Bot(dealer);
|
||||
hand = new ArrayList<>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user