Merge pull request #2 from DTieman/jordans_playground

I Pull U
This commit is contained in:
DTieman
2022-09-22 09:06:25 +02:00
committed by GitHub
9 changed files with 52 additions and 50 deletions

View File

@@ -44,8 +44,9 @@ public class CardHandler {
} }
private void handleJack(TurnTable turnTable) { private void handleJack(TurnTable turnTable) {
Referee.setAllowedCards(turnTable.getCurrentPlayer().getTypeChoice()); TYPENUM typeChoice = turnTable.getCurrentPlayer().getTypeChoice();
System.out.printf("%s chose %s\n", turnTable.getCurrentPlayer().getName(), turnTable.getCurrentPlayer().getTypeChoice()); Referee.setAllowedType(typeChoice);
System.out.printf("%s chose %s\n", turnTable.getCurrentPlayer().getName(), typeChoice);
turnTable.nextPlayer(); turnTable.nextPlayer();
} }
@@ -60,11 +61,13 @@ public class CardHandler {
} }
private void handleJoker(TurnTable turnTable) { private void handleJoker(TurnTable turnTable) {
int punishment = 5;
Player nextPlayer = turnTable.getNextPlayer(); Player nextPlayer = turnTable.getNextPlayer();
drawCards(nextPlayer, 5); drawCards(nextPlayer, punishment);
System.out.printf("%s was forced to draw 5 cards\n", nextPlayer.getName()); System.out.printf("%s was forced to draw 5 cards\n", nextPlayer.getName());
Referee.setAllowedCards(nextPlayer.getTypeChoice()); TYPENUM typeChoice = nextPlayer.getTypeChoice();
System.out.printf("%s chose %s\n", nextPlayer.getName(), nextPlayer.getTypeChoice()); Referee.setAllowedType(typeChoice);
System.out.printf("%s chose %s\n", nextPlayer.getName(), typeChoice);
turnTable.skipNextPlayer(); turnTable.skipNextPlayer();
} }

View File

@@ -11,8 +11,8 @@ public class Deck {
public Deck() { public Deck() {
for (TYPENUM type : TYPENUM.values()) { for (TYPENUM type : TYPENUM.values()) {
if(type == TYPENUM.JOKER) { if(type == TYPENUM.JOKER) {
deck.add(new Card(type, VALUENUM.TWO)); deck.add(new Card(type, VALUENUM.JACK));
deck.add(new Card(type, VALUENUM.THREE)); deck.add(new Card(type, VALUENUM.JACK));
} else { } else {
for (VALUENUM value : VALUENUM.values()) { for (VALUENUM value : VALUENUM.values()) {
deck.add(new Card(type, value)); deck.add(new Card(type, value));

View File

@@ -37,7 +37,7 @@ public class Game {
while (players.size() > 1) { while (players.size() > 1) {
Player player = turnTable.getCurrentPlayer(); Player player = turnTable.getCurrentPlayer();
System.out.println("Current card: " + currentCard); System.out.printf("Current card: %s%n", currentCard);
Card playedCard = player.getPlay(currentCard); Card playedCard = player.getPlay(currentCard);
if (player instanceof Bot) { if (player instanceof Bot) {
new Scanner(System.in).nextLine(); new Scanner(System.in).nextLine();
@@ -46,7 +46,7 @@ public class Game {
if(playedCard != null){ if(playedCard != null){
playCard(playedCard); playCard(playedCard);
} }
System.out.println(deck.getDeck().size() + " cards left in deck"); System.out.printf("%s cards left in deck%n", deck.getDeck().size());
} else { } else {
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(currentCard, playedCard)) { if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(currentCard, playedCard)) {
playCard(playedCard); playCard(playedCard);
@@ -54,9 +54,9 @@ public class Game {
} else { } else {
System.out.println("You can't end the game with that card!"); System.out.println("You can't end the game with that card!");
System.out.println("Take five cards as punishment!"); System.out.println("Take five cards as punishment!");
for (int i = 0; i < 5; i++) { int punishment = 5;
player.addCardToHand(dealer.drawCard()); player.drawCards(punishment);
} continue;
} }
break; break;
} }

View File

@@ -6,9 +6,11 @@ public class Messages {
public static final String KEY_NUMBER_OF_CARDS = "{{numberOfCards}}"; public static final String KEY_NUMBER_OF_CARDS = "{{numberOfCards}}";
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 = "Hwæt shall be thy namian?";
public static final String BAD_PLAYER_NAME = "What a pathetic response, thy shall be knoweth as Koet"; public static final String BAD_PLAYER_NAME = "Hwæt a preposterous reciprocation, thy shall be knoweth as %s%n";
public static final String PLAYER_NAME = "Thy shall be knoweth as %s%n";
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";
} }

View File

@@ -1,11 +1,10 @@
package mau.mau; package mau.mau;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Referee { public class Referee {
public static ArrayList<TYPENUM> allowedTypes = new ArrayList<>(); public static TYPENUM allowedType;
public static boolean isAmazedByAmazingQuartet = false; public static boolean isAmazedByAmazingQuartet = false;
@@ -16,6 +15,13 @@ public class Referee {
TYPENUM playedCardType = playedCard.getType(); TYPENUM playedCardType = playedCard.getType();
VALUENUM playedCardValue = playedCard.getValue(); VALUENUM playedCardValue = playedCard.getValue();
if (allowedType != null && isAllowedCardType(currentCardValue, playedCardType, playedCardValue)){
allowedType = null;
return true;
} else if (allowedType != null && !isAllowedCardType(currentCardValue, playedCardType, playedCardValue)){
return false;
}
return currentCardType == TYPENUM.JOKER return currentCardType == TYPENUM.JOKER
|| playedCardType == TYPENUM.JOKER || playedCardType == TYPENUM.JOKER
|| playedCardType == currentCardType || playedCardType == currentCardType
@@ -57,8 +63,11 @@ public class Referee {
return result; return result;
} }
public static void setAllowedCards(TYPENUM type) { private static boolean isAllowedCardType(VALUENUM currentCardValue, TYPENUM playedCardType, VALUENUM playedCardValue) {
allowedTypes.add(type); return allowedType == playedCardType || playedCardType == TYPENUM.JOKER || playedCardValue == currentCardValue;
allowedTypes.add(TYPENUM.JOKER); }
public static void setAllowedType(TYPENUM type) {
allowedType = type;
} }
} }

View File

@@ -21,18 +21,12 @@ public class Bot extends Player {
if (getHandSize() > 1){ if (getHandSize() > 1){
for (Card card : hand) { for (Card card : hand) {
if (!Referee.allowedTypes.isEmpty()) { if(!Referee.isValidMove(currentCard, card)){
if (Referee.allowedTypes.contains(card.getType())) {
Referee.allowedTypes.clear();
} else {
continue; continue;
} }
} else if (!Referee.isValidMove(card, currentCard)) { System.out.printf("%n%s played %s%n", getName(), card);
continue;
}
System.out.println(getName() + " played " + card);
hand.remove(card); hand.remove(card);
System.out.println(getName() + " now has " + getHandSize() + " cards"); System.out.printf("%s now has %s cards%n", getName(), getHandSize());
return card; return card;
} }
} else { } else {
@@ -46,7 +40,7 @@ public class Bot extends Player {
} }
} }
hand.add(drawCard()); hand.add(drawCard());
System.out.println(getName() + " drew a card"); System.out.printf("%n%s drew a card%n", getName());
System.out.println(getName() + " now has " + hand.size() + " cards"); System.out.println(getName() + " now has " + hand.size() + " cards");
return null; return null;
} }
@@ -81,7 +75,6 @@ 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 bot-names from JSON file");
return "Koet " + nameIndex++; return "Koet " + nameIndex++;
} }
} }

View File

@@ -47,16 +47,10 @@ public class Human extends Player {
continue; continue;
} }
Card card = hand.get(cardIndex); Card card = hand.get(cardIndex);
if (Referee.allowedTypes.isEmpty()) { if (!Referee.isValidMove(currentCard, card)) {
if (!Referee.isValidMove(card, currentCard)) {
System.out.println("Invalid move"); System.out.println("Invalid move");
continue; continue;
} }
} else {
if (Referee.allowedTypes.contains(card.getType())) {
Referee.allowedTypes.clear();
}
}
hand.remove(cardIndex); hand.remove(cardIndex);
return card; return card;
} }
@@ -102,7 +96,9 @@ public class Human extends Player {
String input = scanner.nextLine(); String input = scanner.nextLine();
if (input.equals("")) { if (input.equals("")) {
input = "Koet"; input = "Koet";
System.out.println(Messages.BAD_PLAYER_NAME); System.out.printf(Messages.BAD_PLAYER_NAME, input);
} else {
System.out.printf(Messages.PLAYER_NAME, input);
} }
scanner.nextLine(); scanner.nextLine();
return input; return input;

View File

@@ -29,10 +29,6 @@ public abstract class Player {
return hand.isEmpty(); return hand.isEmpty();
} }
public void addCardToHand(Card card) {
hand.add(card);
}
public Card drawCard() { public Card drawCard() {
return dealer.drawCard(); return dealer.drawCard();
} }

View File

@@ -11,12 +11,15 @@
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~~ * ~~Zorgen dat de hand van de speler horizontaal wordt geprint ipv verticaal~~
7. Messages voor alles maken
## 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 4. ~~Wanneer je een nieuwe type mag kiezen met een boer of joker, moet je 2 keer kiezen~~
5. ~~Naam moet je 2 keer bevestigen~~
6. ~~Bij een joker kan je altijd opleggen, ook als het niet voldoet aan de zojuist gekozen type~~
### In een land hier ver, ver vandaan ### In een land hier ver, ver vandaan
1. UI 1. UI