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>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -38,11 +39,13 @@ public class CardHandler {
|
||||
}
|
||||
|
||||
private void handleEight(TurnTable turnTable) {
|
||||
System.out.println("Eighty waity");
|
||||
turnTable.skipNextPlayer();
|
||||
}
|
||||
|
||||
private void handleJack(TurnTable turnTable) {
|
||||
Referee.setAllowedCards(turnTable.getCurrentPlayer().getTypeChoice());
|
||||
System.out.printf("%s chose %s\n", turnTable.getCurrentPlayer().getName(), turnTable.getCurrentPlayer().getTypeChoice());
|
||||
turnTable.nextPlayer();
|
||||
}
|
||||
|
||||
@@ -51,6 +54,7 @@ public class CardHandler {
|
||||
}
|
||||
|
||||
private void handleAce(TurnTable turnTable) {
|
||||
System.out.printf("%s spins everybody right round baby right round\n", turnTable.getCurrentPlayer().getName());
|
||||
turnTable.reverseDirection();
|
||||
turnTable.nextPlayer();
|
||||
}
|
||||
@@ -58,7 +62,9 @@ public class CardHandler {
|
||||
private void handleJoker(TurnTable turnTable) {
|
||||
Player nextPlayer = turnTable.getNextPlayer();
|
||||
drawCards(nextPlayer, 5);
|
||||
System.out.printf("%s was forced to draw 5 cards\n", nextPlayer.getName());
|
||||
Referee.setAllowedCards(nextPlayer.getTypeChoice());
|
||||
System.out.printf("%s chose %s\n", nextPlayer.getName(), nextPlayer.getTypeChoice());
|
||||
turnTable.skipNextPlayer();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,19 +24,10 @@ public class Game {
|
||||
private void setupGame() {
|
||||
System.out.println(ConsoleColors.RED_BOLD + Messages.WELCOME + ConsoleColors.RESET);
|
||||
dealer = new Dealer(deck);
|
||||
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);
|
||||
}
|
||||
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));
|
||||
players.add(new Human(dealer));
|
||||
players.add(new Bot(dealer));
|
||||
players.add(new Bot(dealer));
|
||||
players.add(new Bot(dealer));
|
||||
turnTable = new TurnTable(players);
|
||||
dealer.dealCards(players);
|
||||
currentCard = dealer.getInitialCard();
|
||||
@@ -57,7 +48,7 @@ public class Game {
|
||||
}
|
||||
System.out.println(deck.getDeck().size() + " cards left in deck");
|
||||
} else {
|
||||
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(playedCard)) {
|
||||
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(currentCard, playedCard)) {
|
||||
playCard(playedCard);
|
||||
System.out.println(player.getName() + " won!");
|
||||
} 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 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_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";
|
||||
|
||||
@@ -34,8 +34,8 @@ public class Referee {
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean isValidEndCard(Card card) {
|
||||
return !isMauCard(card);
|
||||
public static boolean isValidEndCard(Card currentCard, Card playedCard) {
|
||||
return !isMauCard(playedCard) && isValidMove(currentCard, playedCard);
|
||||
}
|
||||
|
||||
public static boolean isValidQuartet(List<Card> hand){
|
||||
|
||||
@@ -8,43 +8,42 @@ import java.util.Scanner;
|
||||
|
||||
public class Bot extends Player {
|
||||
|
||||
public Bot(String name, Dealer dealer) {
|
||||
super(name, dealer);
|
||||
private static int nameIndex = 0;
|
||||
private static String JSON = "src/main/resources/languages/en.json";
|
||||
private static String JSON_KEY = "botnames";
|
||||
|
||||
public Bot(Dealer dealer) {
|
||||
super(dealer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Card getPlay(Card currentCard) {
|
||||
List<Card> hand = getHand();
|
||||
|
||||
if (hand.size() == 1 && Referee.isValidEndCard(hand.get(0)) && Referee.isValidMove(hand.get(0), currentCard)) {
|
||||
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) {
|
||||
if (Referee.allowedTypes.isEmpty()) {
|
||||
if (Referee.isValidMove(card, currentCard)) {
|
||||
System.out.println(getName() + " played " + card);
|
||||
hand.remove(card);
|
||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
||||
return card;
|
||||
}
|
||||
} else {
|
||||
if (Referee.allowedTypes.contains(card.getType())) {
|
||||
Referee.allowedTypes.clear();
|
||||
System.out.println(getName() + " played " + card);
|
||||
hand.remove(card);
|
||||
System.out.println(getName() + " now has " + hand.size() + " cards");
|
||||
return card;
|
||||
if (getHandSize() > 1){
|
||||
for (Card card : hand) {
|
||||
if (!Referee.allowedTypes.isEmpty()) {
|
||||
if (Referee.allowedTypes.contains(card.getType())) {
|
||||
Referee.allowedTypes.clear();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else if (!Referee.isValidMove(card, currentCard)) {
|
||||
continue;
|
||||
}
|
||||
System.out.println(getName() + " played " + card);
|
||||
hand.remove(card);
|
||||
System.out.println(getName() + " now has " + getHandSize() + " cards");
|
||||
return card;
|
||||
}
|
||||
} else {
|
||||
Card lastCard = hand.get(0);
|
||||
if(Referee.isValidEndCard(currentCard, lastCard)){
|
||||
Card card = hand.get(0);
|
||||
System.out.println(getName() + " played " + card);
|
||||
hand.remove(0);
|
||||
System.out.println(getName() + " now has " + getHandSize() + " cards");
|
||||
return card;
|
||||
}
|
||||
}
|
||||
hand.add(drawCard());
|
||||
@@ -75,7 +74,16 @@ public class Bot extends Player {
|
||||
if (typeChoice == null || typeChoice == TYPENUM.JOKER) {
|
||||
typeChoice = TYPENUM.values()[(int) (Math.random() * 4)];
|
||||
}
|
||||
System.out.println(getName() + " chose " + 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 Human(String name, Dealer dealer) {
|
||||
super(name, dealer);
|
||||
public Human(Dealer dealer) {
|
||||
super(dealer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Card getPlay(Card currentCard) {
|
||||
System.out.println();
|
||||
printHand();
|
||||
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() {
|
||||
List<Card> hand = getHand();
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
|
||||
@@ -12,9 +12,9 @@ public abstract class Player {
|
||||
private List<Card> hand;
|
||||
private Dealer dealer;
|
||||
|
||||
public Player(String name, Dealer dealer) {
|
||||
this.name = name;
|
||||
public Player(Dealer dealer) {
|
||||
this.dealer = dealer;
|
||||
name = askForName();
|
||||
}
|
||||
|
||||
public List<Card> getHand() {
|
||||
@@ -54,4 +54,6 @@ public abstract class Player {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract String askForName();
|
||||
}
|
||||
|
||||
@@ -4,16 +4,19 @@
|
||||
* ~~Kwartet = win~~
|
||||
* 69 mag tegelijk opgelegd worden
|
||||
* ~~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~~
|
||||
5. 100% test coverage
|
||||
* ~~69% test coverage~~
|
||||
6. Redesign terminal interface
|
||||
* ~~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
|
||||
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
|
||||
|
||||
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();
|
||||
players = new ArrayList<>();
|
||||
turnTable = new TurnTable(players);
|
||||
bot1 = new Bot("Bot1", dealer);
|
||||
bot2 = new Bot("Bot2", dealer);
|
||||
bot3 = new Bot("Bot3", dealer);
|
||||
bot1 = new Bot(dealer);
|
||||
bot2 = new Bot(dealer);
|
||||
bot3 = new Bot(dealer);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -102,9 +102,10 @@ public class RefereeTest {
|
||||
public void isAceOfSpadesValidEndcardTest(){
|
||||
//Arrange
|
||||
Card testCardOne = new Card(TYPENUM.SPADES, VALUENUM.ACE);
|
||||
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
||||
|
||||
//Act
|
||||
boolean results = Referee.isValidEndCard(testCardOne);
|
||||
boolean results = Referee.isValidEndCard(testCurrentCard, testCardOne);
|
||||
|
||||
//Assert
|
||||
assertFalse(results);
|
||||
@@ -114,9 +115,10 @@ public class RefereeTest {
|
||||
public void isThreeOfHeartsValidEndcardTest(){
|
||||
//Arrange
|
||||
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.THREE);
|
||||
Card testCurrentCard = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
|
||||
|
||||
//Act
|
||||
boolean results = Referee.isValidEndCard(testCardOne);
|
||||
boolean results = Referee.isValidEndCard(testCurrentCard, testCardOne);
|
||||
|
||||
//Assert
|
||||
assertTrue(results);
|
||||
|
||||
@@ -18,9 +18,9 @@ public class TurnTableTest {
|
||||
public void setUp() {
|
||||
Dealer dealer = new Dealer(new Deck());
|
||||
players = new ArrayList<>();
|
||||
bot1 = new Bot("Bot1", dealer);
|
||||
bot2 = new Bot("Bot2", dealer);
|
||||
bot3 = new Bot("Bot3", dealer);
|
||||
bot1 = new Bot(dealer);
|
||||
bot2 = new Bot(dealer);
|
||||
bot3 = new Bot(dealer);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,7 +20,7 @@ public class BotTest {
|
||||
public void setUp() {
|
||||
deck = new Deck();
|
||||
dealer = new Dealer(deck);
|
||||
sut = new Bot("Koet", dealer);
|
||||
sut = new Bot(dealer);
|
||||
hand = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user