My stupid ass forgot to pull so here is the master pull with an updated todo and some minor tweaks
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -35,4 +35,5 @@
|
|||||||
<maven.compiler.target>16</maven.compiler.target>
|
<maven.compiler.target>16</maven.compiler.target>
|
||||||
<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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,11 +39,13 @@ public class CardHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleEight(TurnTable turnTable) {
|
private void handleEight(TurnTable turnTable) {
|
||||||
|
System.out.println("Eighty waity");
|
||||||
turnTable.skipNextPlayer();
|
turnTable.skipNextPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleJack(TurnTable turnTable) {
|
private void handleJack(TurnTable turnTable) {
|
||||||
Referee.setAllowedCards(turnTable.getCurrentPlayer().getTypeChoice());
|
Referee.setAllowedCards(turnTable.getCurrentPlayer().getTypeChoice());
|
||||||
|
System.out.printf("%s chose %s\n", turnTable.getCurrentPlayer().getName(), turnTable.getCurrentPlayer().getTypeChoice());
|
||||||
turnTable.nextPlayer();
|
turnTable.nextPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +54,7 @@ public class CardHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleAce(TurnTable turnTable) {
|
private void handleAce(TurnTable turnTable) {
|
||||||
|
System.out.printf("%s spins everybody right round baby right round\n", turnTable.getCurrentPlayer().getName());
|
||||||
turnTable.reverseDirection();
|
turnTable.reverseDirection();
|
||||||
turnTable.nextPlayer();
|
turnTable.nextPlayer();
|
||||||
}
|
}
|
||||||
@@ -58,7 +62,9 @@ public class CardHandler {
|
|||||||
private void handleJoker(TurnTable turnTable) {
|
private void handleJoker(TurnTable turnTable) {
|
||||||
Player nextPlayer = turnTable.getNextPlayer();
|
Player nextPlayer = turnTable.getNextPlayer();
|
||||||
drawCards(nextPlayer, 5);
|
drawCards(nextPlayer, 5);
|
||||||
|
System.out.printf("%s was forced to draw 5 cards\n", nextPlayer.getName());
|
||||||
Referee.setAllowedCards(nextPlayer.getTypeChoice());
|
Referee.setAllowedCards(nextPlayer.getTypeChoice());
|
||||||
|
System.out.printf("%s chose %s\n", nextPlayer.getName(), nextPlayer.getTypeChoice());
|
||||||
turnTable.skipNextPlayer();
|
turnTable.skipNextPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,19 +24,10 @@ public class Game {
|
|||||||
private void setupGame() {
|
private void setupGame() {
|
||||||
System.out.println(ConsoleColors.RED_BOLD + Messages.WELCOME + ConsoleColors.RESET);
|
System.out.println(ConsoleColors.RED_BOLD + Messages.WELCOME + ConsoleColors.RESET);
|
||||||
dealer = new Dealer(deck);
|
dealer = new Dealer(deck);
|
||||||
Scanner scanner = new Scanner(System.in);
|
players.add(new Human(dealer));
|
||||||
System.out.println(Messages.ASK_FOR_PLAYER_NAME);
|
players.add(new Bot(dealer));
|
||||||
String input = scanner.nextLine();
|
players.add(new Bot(dealer));
|
||||||
if (input.equals("")) {
|
players.add(new Bot(dealer));
|
||||||
input = "Koet";
|
|
||||||
System.out.println(Messages.BAD_PLAYER_NAME);
|
|
||||||
}
|
|
||||||
new Scanner(System.in).nextLine();
|
|
||||||
Human human = new Human(input, dealer);
|
|
||||||
players.add(human);
|
|
||||||
players.add(new Bot("Jordan", dealer));
|
|
||||||
players.add(new Bot("MaarKoet", dealer));
|
|
||||||
players.add(new Bot("El Tigre", dealer));
|
|
||||||
turnTable = new TurnTable(players);
|
turnTable = new TurnTable(players);
|
||||||
dealer.dealCards(players);
|
dealer.dealCards(players);
|
||||||
currentCard = dealer.getInitialCard();
|
currentCard = dealer.getInitialCard();
|
||||||
@@ -57,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.isAmazedByAmazingQuartet || Referee.isValidEndCard(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 {
|
||||||
|
|||||||
21
src/main/java/mau/mau/JSONderulo.java
Normal file
21
src/main/java/mau/mau/JSONderulo.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package mau.mau;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class JSONderulo {
|
||||||
|
|
||||||
|
public static JSONObject parseJSONFile(String filename) throws JSONException, IOException {
|
||||||
|
String content = new String(Files.readAllBytes(Paths.get(filename)));
|
||||||
|
return new JSONObject(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONArray getJSONArrayFromJSONFile(String filename, String key) throws JSONException, IOException {
|
||||||
|
return parseJSONFile(filename).getJSONArray(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ public class Messages {
|
|||||||
|
|
||||||
public static final String WELCOME = "Welcome to Dutch Mau Mau!";
|
public static final String WELCOME = "Welcome to Dutch Mau Mau!";
|
||||||
public static final String ASK_FOR_PLAYER_NAME = "What shall be thy name?";
|
public static final String ASK_FOR_PLAYER_NAME = "What shall be thy name?";
|
||||||
public static final String BAD_PLAYER_NAME = "What a pathetic response, thy shall be known as Koet";
|
public static final String BAD_PLAYER_NAME = "What a pathetic response, thy shall be knoweth as Koet";
|
||||||
public static final String PLAYER_PLAYED_CARD = KEY_PLAYER_NAME + " played " + KEY_CARD;
|
public static final String PLAYER_PLAYED_CARD = KEY_PLAYER_NAME + " played " + KEY_CARD;
|
||||||
public static final String PLAYER_DRAW_CARDS = KEY_PLAYER_NAME + " drew " + KEY_NUMBER_OF_CARDS + " cards";
|
public static final String PLAYER_DRAW_CARDS = KEY_PLAYER_NAME + " drew " + KEY_NUMBER_OF_CARDS + " cards";
|
||||||
public static final String PLAYER_HAS_X_CARDS = KEY_PLAYER_NAME + " now has " + KEY_NUMBER_OF_CARDS + " cards";
|
public static final String PLAYER_HAS_X_CARDS = KEY_PLAYER_NAME + " now has " + KEY_NUMBER_OF_CARDS + " cards";
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public class Referee {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidEndCard(Card card) {
|
public static boolean isValidEndCard(Card currentCard, Card playedCard) {
|
||||||
return !isMauCard(card);
|
return !isMauCard(playedCard) && isValidMove(currentCard, playedCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidQuartet(List<Card> hand){
|
public static boolean isValidQuartet(List<Card> hand){
|
||||||
|
|||||||
@@ -8,45 +8,44 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class Bot extends Player {
|
public class Bot extends Player {
|
||||||
|
|
||||||
public Bot(String name, Dealer dealer) {
|
private static int nameIndex = 0;
|
||||||
super(name, dealer);
|
private static String JSON = "src/main/resources/languages/en.json";
|
||||||
|
private static String JSON_KEY = "botnames";
|
||||||
|
|
||||||
|
public Bot(Dealer dealer) {
|
||||||
|
super(dealer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Card getPlay(Card currentCard) {
|
public Card getPlay(Card currentCard) {
|
||||||
List<Card> hand = getHand();
|
List<Card> hand = getHand();
|
||||||
|
|
||||||
if (hand.size() == 1 && Referee.isValidEndCard(hand.get(0)) && Referee.isValidMove(hand.get(0), currentCard)) {
|
if (getHandSize() > 1){
|
||||||
Card card = hand.get(0);
|
|
||||||
System.out.println(getName() + " played " + card);
|
|
||||||
hand.remove(0);
|
|
||||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
|
||||||
return card;
|
|
||||||
} else if (hand.size() == 1) {
|
|
||||||
hand.add(drawCard());
|
|
||||||
System.out.println(getName() + " drew a card");
|
|
||||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Card card : hand) {
|
for (Card card : hand) {
|
||||||
if (Referee.allowedTypes.isEmpty()) {
|
if (!Referee.allowedTypes.isEmpty()) {
|
||||||
if (Referee.isValidMove(card, currentCard)) {
|
if (Referee.allowedTypes.contains(card.getType())) {
|
||||||
|
Referee.allowedTypes.clear();
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (!Referee.isValidMove(card, currentCard)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
System.out.println(getName() + " played " + card);
|
System.out.println(getName() + " played " + card);
|
||||||
hand.remove(card);
|
hand.remove(card);
|
||||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
System.out.println(getName() + " now has " + getHandSize() + " cards");
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Referee.allowedTypes.contains(card.getType())) {
|
Card lastCard = hand.get(0);
|
||||||
Referee.allowedTypes.clear();
|
if(Referee.isValidEndCard(currentCard, lastCard)){
|
||||||
|
Card card = hand.get(0);
|
||||||
System.out.println(getName() + " played " + card);
|
System.out.println(getName() + " played " + card);
|
||||||
hand.remove(card);
|
hand.remove(0);
|
||||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
System.out.println(getName() + " now has " + getHandSize() + " cards");
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
hand.add(drawCard());
|
hand.add(drawCard());
|
||||||
System.out.println(getName() + " drew a card");
|
System.out.println(getName() + " drew a card");
|
||||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
System.out.println(getName() + " now has " + hand.size() + " cards");
|
||||||
@@ -75,7 +74,16 @@ public class Bot extends Player {
|
|||||||
if (typeChoice == null || typeChoice == TYPENUM.JOKER) {
|
if (typeChoice == null || typeChoice == TYPENUM.JOKER) {
|
||||||
typeChoice = TYPENUM.values()[(int) (Math.random() * 4)];
|
typeChoice = TYPENUM.values()[(int) (Math.random() * 4)];
|
||||||
}
|
}
|
||||||
System.out.println(getName() + " chose " + typeChoice);
|
|
||||||
return typeChoice;
|
return typeChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String askForName() {
|
||||||
|
try {
|
||||||
|
return JSONderulo.getJSONArrayFromJSONFile(JSON, JSON_KEY).getString(nameIndex++);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Error reading botnames from JSON file");
|
||||||
|
return "Koet " + nameIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,13 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class Human extends Player {
|
public class Human extends Player {
|
||||||
|
|
||||||
public Human(String name, Dealer dealer) {
|
public Human(Dealer dealer) {
|
||||||
super(name, dealer);
|
super(dealer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Card getPlay(Card currentCard) {
|
public Card getPlay(Card currentCard) {
|
||||||
|
System.out.println();
|
||||||
printHand();
|
printHand();
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
@@ -94,6 +95,19 @@ public class Human extends Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String askForName() {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
System.out.println(Messages.ASK_FOR_PLAYER_NAME);
|
||||||
|
String input = scanner.nextLine();
|
||||||
|
if (input.equals("")) {
|
||||||
|
input = "Koet";
|
||||||
|
System.out.println(Messages.BAD_PLAYER_NAME);
|
||||||
|
}
|
||||||
|
scanner.nextLine();
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
private void printHand() {
|
private void printHand() {
|
||||||
List<Card> hand = getHand();
|
List<Card> hand = getHand();
|
||||||
for (int i = 0; i < hand.size(); i++) {
|
for (int i = 0; i < hand.size(); i++) {
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ public abstract class Player {
|
|||||||
private List<Card> hand;
|
private List<Card> hand;
|
||||||
private Dealer dealer;
|
private Dealer dealer;
|
||||||
|
|
||||||
public Player(String name, Dealer dealer) {
|
public Player(Dealer dealer) {
|
||||||
this.name = name;
|
|
||||||
this.dealer = dealer;
|
this.dealer = dealer;
|
||||||
|
name = askForName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Card> getHand() {
|
public List<Card> getHand() {
|
||||||
@@ -54,4 +54,6 @@ public abstract class Player {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract String askForName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,19 @@
|
|||||||
* ~~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~~
|
||||||
4. ~~Als je laatste kaart een pestkaart is moet je 5 kaarten pakken als je hem probeert op te leggen~~
|
4. ~~Als je laatste kaart een pestkaart is moet je 5 kaarten pakken als je hem probeert op te leggen~~
|
||||||
5. 100% test coverage
|
5. 100% test coverage
|
||||||
|
* ~~69% test coverage~~
|
||||||
6. Redesign terminal interface
|
6. Redesign terminal interface
|
||||||
* ~~Kaarten laten zien als er een joker op je gedropt is~~
|
* ~~Kaarten laten zien als er een joker op je gedropt is~~
|
||||||
|
* ~~Zorgen dat de hand van de speler horizontaal wordt geprint ipv verticaal~~
|
||||||
|
|
||||||
## Known Bugs
|
## Known Bugs
|
||||||
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
|
||||||
|
|||||||
7
src/main/resources/languages/en.json
Normal file
7
src/main/resources/languages/en.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"botnames": [
|
||||||
|
"Jordan",
|
||||||
|
"MaarKoet",
|
||||||
|
"El Tigre"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -25,9 +25,9 @@ public class CardHandlerTest {
|
|||||||
sut = new CardHandler();
|
sut = new CardHandler();
|
||||||
players = new ArrayList<>();
|
players = new ArrayList<>();
|
||||||
turnTable = new TurnTable(players);
|
turnTable = new TurnTable(players);
|
||||||
bot1 = new Bot("Bot1", dealer);
|
bot1 = new Bot(dealer);
|
||||||
bot2 = new Bot("Bot2", dealer);
|
bot2 = new Bot(dealer);
|
||||||
bot3 = new Bot("Bot3", dealer);
|
bot3 = new Bot(dealer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -102,9 +102,10 @@ public class RefereeTest {
|
|||||||
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);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
boolean results = Referee.isValidEndCard(testCardOne);
|
boolean results = Referee.isValidEndCard(testCurrentCard, testCardOne);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
assertFalse(results);
|
assertFalse(results);
|
||||||
@@ -114,9 +115,10 @@ public class RefereeTest {
|
|||||||
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);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
boolean results = Referee.isValidEndCard(testCardOne);
|
boolean results = Referee.isValidEndCard(testCurrentCard, testCardOne);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
assertTrue(results);
|
assertTrue(results);
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ public class TurnTableTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
Dealer dealer = new Dealer(new Deck());
|
Dealer dealer = new Dealer(new Deck());
|
||||||
players = new ArrayList<>();
|
players = new ArrayList<>();
|
||||||
bot1 = new Bot("Bot1", dealer);
|
bot1 = new Bot(dealer);
|
||||||
bot2 = new Bot("Bot2", dealer);
|
bot2 = new Bot(dealer);
|
||||||
bot3 = new Bot("Bot3", dealer);
|
bot3 = new Bot(dealer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class BotTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
deck = new Deck();
|
deck = new Deck();
|
||||||
dealer = new Dealer(deck);
|
dealer = new Dealer(deck);
|
||||||
sut = new Bot("Koet", dealer);
|
sut = new Bot(dealer);
|
||||||
hand = new ArrayList<>();
|
hand = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user