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:
4
pom.xml
4
pom.xml
@@ -11,7 +11,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>RELEASE</version>
|
<version>5.9.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -36,4 +36,4 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -30,6 +30,7 @@ public class CardHandler {
|
|||||||
|
|
||||||
private void handleTwo(TurnTable turnTable) {
|
private void handleTwo(TurnTable turnTable) {
|
||||||
drawCards(turnTable.getNextPlayer(), 2);
|
drawCards(turnTable.getNextPlayer(), 2);
|
||||||
|
System.out.printf("%s was forced to draw 2 cards\n", turnTable.getNextPlayer().getName());
|
||||||
turnTable.skipNextPlayer();
|
turnTable.skipNextPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Dealer {
|
public class Dealer {
|
||||||
private Deck deck;
|
private final Deck deck;
|
||||||
|
|
||||||
public Dealer(Deck deck) {
|
public Dealer(Deck deck) {
|
||||||
this.deck = deck;
|
this.deck = deck;
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ public class Game {
|
|||||||
private Card currentCard;
|
private Card currentCard;
|
||||||
private final Deck deck = new Deck();
|
private final Deck deck = new Deck();
|
||||||
private Dealer dealer;
|
private Dealer dealer;
|
||||||
private CardHandler cardHandler = new CardHandler();
|
private final CardHandler cardHandler = new CardHandler();
|
||||||
private TurnTable turnTable;
|
private TurnTable turnTable;
|
||||||
private final List<Player> players = new ArrayList<>();
|
private final List<Player> players = new ArrayList<>();
|
||||||
private int playerTurn = 0;
|
|
||||||
private Boolean reverse = false;
|
|
||||||
|
|
||||||
public Game() {
|
public Game() {
|
||||||
setupGame();
|
setupGame();
|
||||||
@@ -50,7 +48,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
System.out.println(deck.getDeck().size() + " cards left in deck");
|
System.out.println(deck.getDeck().size() + " cards left in deck");
|
||||||
} else {
|
} else {
|
||||||
if(Referee.isValidEndCard(currentCard, playedCard)) {
|
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(currentCard, playedCard)) {
|
||||||
playCard(playedCard);
|
playCard(playedCard);
|
||||||
System.out.println(player.getName() + " won!");
|
System.out.println(player.getName() + " won!");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package mau.mau;
|
package mau.mau;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Referee {
|
public class Referee {
|
||||||
|
|
||||||
public static ArrayList<TYPENUM> allowedTypes = new ArrayList<>();
|
public static ArrayList<TYPENUM> allowedTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
public static boolean isAmazedByAmazingQuartet = false;
|
||||||
|
|
||||||
public static boolean isValidMove(Card currentCard, Card playedCard) {
|
public static boolean isValidMove(Card currentCard, Card playedCard) {
|
||||||
|
|
||||||
TYPENUM currentCardType = currentCard.getType();
|
TYPENUM currentCardType = currentCard.getType();
|
||||||
@@ -35,6 +38,25 @@ public class Referee {
|
|||||||
return !isMauCard(playedCard) && isValidMove(currentCard, playedCard);
|
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) {
|
public static void setAllowedCards(TYPENUM type) {
|
||||||
allowedTypes.add(type);
|
allowedTypes.add(type);
|
||||||
allowedTypes.add(TYPENUM.JOKER);
|
allowedTypes.add(TYPENUM.JOKER);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package mau.mau;
|
package mau.mau;
|
||||||
|
|
||||||
public enum TYPENUM {
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
public class TurnTable {
|
public class TurnTable {
|
||||||
private List<Player> players;
|
private final List<Player> players;
|
||||||
private int currentPlayerIndex;
|
private int currentPlayerIndex;
|
||||||
private int direction;
|
private int direction;
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import mau.mau.*;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Bot extends Player {
|
public class Bot extends Player {
|
||||||
|
|
||||||
private static int nameIndex = 0;
|
private static int nameIndex = 0;
|
||||||
private static String JSON = "src/main/resources/languages/en.json";
|
private static final String JSON = "src/main/resources/languages/en.json";
|
||||||
private static String JSON_KEY = "botnames";
|
private static final String JSON_KEY = "bot-names";
|
||||||
|
|
||||||
public Bot(Dealer dealer) {
|
public Bot(Dealer dealer) {
|
||||||
super(dealer);
|
super(dealer);
|
||||||
@@ -82,7 +81,7 @@ public class Bot extends Player {
|
|||||||
try {
|
try {
|
||||||
return JSONderulo.getJSONArrayFromJSONFile(JSON, JSON_KEY).getString(nameIndex++);
|
return JSONderulo.getJSONArrayFromJSONFile(JSON, JSON_KEY).getString(nameIndex++);
|
||||||
} catch (Exception e) {
|
} 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++;
|
return "Koet " + nameIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public class Human extends Player {
|
|||||||
public Card getPlay(Card currentCard) {
|
public Card getPlay(Card currentCard) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
printHand();
|
printHand();
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
List<Card> hand = getHand();
|
List<Card> hand = getHand();
|
||||||
@@ -31,6 +30,16 @@ public class Human extends Player {
|
|||||||
hand.add(card);
|
hand.add(card);
|
||||||
return null;
|
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)) {
|
if (Utils.isNumeric(input)) {
|
||||||
int cardIndex = Integer.parseInt(input);
|
int cardIndex = Integer.parseInt(input);
|
||||||
if (cardIndex < 0 || cardIndex > hand.size()) {
|
if (cardIndex < 0 || cardIndex > hand.size()) {
|
||||||
@@ -103,7 +112,13 @@ public class Human extends Player {
|
|||||||
List<Card> hand = getHand();
|
List<Card> hand = getHand();
|
||||||
for (int i = 0; i < hand.size(); i++) {
|
for (int i = 0; i < hand.size(); i++) {
|
||||||
Card card = hand.get(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 {
|
public abstract class Player {
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
private List<Card> hand;
|
private List<Card> hand;
|
||||||
private Dealer dealer;
|
private final Dealer dealer;
|
||||||
|
|
||||||
public Player(Dealer dealer) {
|
public Player(Dealer dealer) {
|
||||||
this.dealer = dealer;
|
this.dealer = dealer;
|
||||||
@@ -21,8 +21,8 @@ public abstract class Player {
|
|||||||
return hand;
|
return hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Card> setHand(List<Card> hand) {
|
public void setHand(List<Card> hand) {
|
||||||
return this.hand = hand;
|
this.hand = hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean handIsEmpty() {
|
public Boolean handIsEmpty() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# TODO
|
# TODO
|
||||||
1. Refactoring
|
1. Refactoring
|
||||||
2. Huisregels toevoegen
|
2. Huisregels toevoegen
|
||||||
* Kwartet = win
|
* ~~Kwartet = win~~
|
||||||
* 69 mag tegelijk opgelegd worden
|
* 69 mag tegelijk opgelegd worden
|
||||||
* ~~Als er 2 spelers zijn, mag je 2x na een Ace~~
|
* ~~Als er 2 spelers zijn, mag je 2x na een Ace~~
|
||||||
3. ~~Spelers kunnen een naam kiezen~~
|
3. ~~Spelers kunnen een naam kiezen~~
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
1. ~~Teveel kaarten in deck na het opnieuw schudden~~
|
1. ~~Teveel kaarten in deck na het opnieuw schudden~~
|
||||||
2. Dezelfde type kaart als de boer mag alsnog opgelegd worden
|
2. Dezelfde type kaart als de boer mag alsnog opgelegd worden
|
||||||
3. Je kan als laatste kaart een pestkaart opleggen
|
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
|
### In een land hier ver, ver vandaan
|
||||||
1. UI
|
1. UI
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ loop until someone wins
|
|||||||
else draw
|
else draw
|
||||||
User -> Player: draw()
|
User -> Player: draw()
|
||||||
end
|
end
|
||||||
else bot's turn
|
else bots turn
|
||||||
alt play
|
alt play
|
||||||
Bot -> Player: play(card)
|
Bot -> Player: play(card)
|
||||||
Game <-- Player: playedCard
|
Game <-- Player: playedCard
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"botnames": [
|
"bot-names": [
|
||||||
"Jordan",
|
"Jordan",
|
||||||
"MaarKoet",
|
"MaarKoet",
|
||||||
"El Tigre"
|
"El Tigre"
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ public class CardHandlerTest {
|
|||||||
private CardHandler sut;
|
private CardHandler sut;
|
||||||
private TurnTable turnTable;
|
private TurnTable turnTable;
|
||||||
private List<Player> players;
|
private List<Player> players;
|
||||||
private Dealer dealer;
|
|
||||||
private Bot bot1, bot2, bot3;
|
private Bot bot1, bot2, bot3;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
//Arrange
|
//Arrange
|
||||||
dealer = new Dealer(new Deck());
|
Dealer dealer = new Dealer(new Deck());
|
||||||
sut = new CardHandler();
|
sut = new CardHandler();
|
||||||
players = new ArrayList<>();
|
players = new ArrayList<>();
|
||||||
turnTable = new TurnTable(players);
|
turnTable = new TurnTable(players);
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
package mau.mau;
|
package mau.mau;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public class DealerTest {
|
public class DealerTest {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package mau.mau;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@@ -97,7 +99,7 @@ public class RefereeTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAceOfSpadesValidEndcardTest(){
|
public void isAceOfSpadesValidEndCardTest(){
|
||||||
//Arrange
|
//Arrange
|
||||||
Card testCardOne = new Card(TYPENUM.SPADES, VALUENUM.ACE);
|
Card testCardOne = new Card(TYPENUM.SPADES, VALUENUM.ACE);
|
||||||
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
||||||
@@ -110,7 +112,7 @@ public class RefereeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isThreeOfHeartsValidEndcardTest(){
|
public void isThreeOfHeartsValidEndCardTest(){
|
||||||
//Arrange
|
//Arrange
|
||||||
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.THREE);
|
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.THREE);
|
||||||
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
||||||
@@ -121,4 +123,36 @@ public class RefereeTest {
|
|||||||
//Assert
|
//Assert
|
||||||
assertTrue(results);
|
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 {
|
public class BotTest {
|
||||||
|
|
||||||
private Bot sut;
|
private Bot sut;
|
||||||
private Dealer dealer;
|
|
||||||
private Deck deck;
|
|
||||||
private List<Card> hand;
|
private List<Card> hand;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
deck = new Deck();
|
Deck deck = new Deck();
|
||||||
dealer = new Dealer(deck);
|
Dealer dealer = new Dealer(deck);
|
||||||
sut = new Bot(dealer);
|
sut = new Bot(dealer);
|
||||||
hand = new ArrayList<>();
|
hand = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user