@@ -44,8 +44,9 @@ public class CardHandler {
|
||||
}
|
||||
|
||||
private void handleJack(TurnTable turnTable) {
|
||||
Referee.setAllowedCards(turnTable.getCurrentPlayer().getTypeChoice());
|
||||
System.out.printf("%s chose %s\n", turnTable.getCurrentPlayer().getName(), turnTable.getCurrentPlayer().getTypeChoice());
|
||||
TYPENUM typeChoice = turnTable.getCurrentPlayer().getTypeChoice();
|
||||
Referee.setAllowedType(typeChoice);
|
||||
System.out.printf("%s chose %s\n", turnTable.getCurrentPlayer().getName(), typeChoice);
|
||||
turnTable.nextPlayer();
|
||||
}
|
||||
|
||||
@@ -60,11 +61,13 @@ public class CardHandler {
|
||||
}
|
||||
|
||||
private void handleJoker(TurnTable turnTable) {
|
||||
int punishment = 5;
|
||||
Player nextPlayer = turnTable.getNextPlayer();
|
||||
drawCards(nextPlayer, 5);
|
||||
drawCards(nextPlayer, punishment);
|
||||
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());
|
||||
TYPENUM typeChoice = nextPlayer.getTypeChoice();
|
||||
Referee.setAllowedType(typeChoice);
|
||||
System.out.printf("%s chose %s\n", nextPlayer.getName(), typeChoice);
|
||||
turnTable.skipNextPlayer();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ public class Deck {
|
||||
public Deck() {
|
||||
for (TYPENUM type : TYPENUM.values()) {
|
||||
if(type == TYPENUM.JOKER) {
|
||||
deck.add(new Card(type, VALUENUM.TWO));
|
||||
deck.add(new Card(type, VALUENUM.THREE));
|
||||
deck.add(new Card(type, VALUENUM.JACK));
|
||||
deck.add(new Card(type, VALUENUM.JACK));
|
||||
} else {
|
||||
for (VALUENUM value : VALUENUM.values()) {
|
||||
deck.add(new Card(type, value));
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Game {
|
||||
while (players.size() > 1) {
|
||||
Player player = turnTable.getCurrentPlayer();
|
||||
|
||||
System.out.println("Current card: " + currentCard);
|
||||
System.out.printf("Current card: %s%n", currentCard);
|
||||
Card playedCard = player.getPlay(currentCard);
|
||||
if (player instanceof Bot) {
|
||||
new Scanner(System.in).nextLine();
|
||||
@@ -46,7 +46,7 @@ public class Game {
|
||||
if(playedCard != null){
|
||||
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 {
|
||||
if( Referee.isAmazedByAmazingQuartet || Referee.isValidEndCard(currentCard, playedCard)) {
|
||||
playCard(playedCard);
|
||||
@@ -54,9 +54,9 @@ public class Game {
|
||||
} else {
|
||||
System.out.println("You can't end the game with that card!");
|
||||
System.out.println("Take five cards as punishment!");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
player.addCardToHand(dealer.drawCard());
|
||||
}
|
||||
int punishment = 5;
|
||||
player.drawCards(punishment);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@ public class Messages {
|
||||
public static final String KEY_NUMBER_OF_CARDS = "{{numberOfCards}}";
|
||||
|
||||
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 knoweth as Koet";
|
||||
public static final String ASK_FOR_PLAYER_NAME = "Hwæt shall be thy namian?";
|
||||
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_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";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package mau.mau;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Referee {
|
||||
|
||||
public static ArrayList<TYPENUM> allowedTypes = new ArrayList<>();
|
||||
public static TYPENUM allowedType;
|
||||
|
||||
public static boolean isAmazedByAmazingQuartet = false;
|
||||
|
||||
@@ -16,6 +15,13 @@ public class Referee {
|
||||
TYPENUM playedCardType = playedCard.getType();
|
||||
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
|
||||
|| playedCardType == TYPENUM.JOKER
|
||||
|| playedCardType == currentCardType
|
||||
@@ -57,8 +63,11 @@ public class Referee {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setAllowedCards(TYPENUM type) {
|
||||
allowedTypes.add(type);
|
||||
allowedTypes.add(TYPENUM.JOKER);
|
||||
private static boolean isAllowedCardType(VALUENUM currentCardValue, TYPENUM playedCardType, VALUENUM playedCardValue) {
|
||||
return allowedType == playedCardType || playedCardType == TYPENUM.JOKER || playedCardValue == currentCardValue;
|
||||
}
|
||||
|
||||
public static void setAllowedType(TYPENUM type) {
|
||||
allowedType = type;
|
||||
}
|
||||
}
|
||||
@@ -21,18 +21,12 @@ public class Bot extends Player {
|
||||
|
||||
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)) {
|
||||
if(!Referee.isValidMove(currentCard, card)){
|
||||
continue;
|
||||
}
|
||||
System.out.println(getName() + " played " + card);
|
||||
System.out.printf("%n%s played %s%n", getName(), 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;
|
||||
}
|
||||
} else {
|
||||
@@ -46,7 +40,7 @@ public class Bot extends Player {
|
||||
}
|
||||
}
|
||||
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");
|
||||
return null;
|
||||
}
|
||||
@@ -81,7 +75,6 @@ public class Bot extends Player {
|
||||
try {
|
||||
return JSONderulo.getJSONArrayFromJSONFile(JSON, JSON_KEY).getString(nameIndex++);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error reading bot-names from JSON file");
|
||||
return "Koet " + nameIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ public class Human extends Player {
|
||||
return null;
|
||||
}
|
||||
if (input.equals("quartet")) {
|
||||
if (Referee.isValidQuartet(hand)) {
|
||||
System.out.println("You played a quartet!");
|
||||
if (Referee.isValidQuartet(hand)) {
|
||||
System.out.println("You played a quartet!");
|
||||
|
||||
hand.clear();
|
||||
return null;
|
||||
}
|
||||
hand.clear();
|
||||
return null;
|
||||
}
|
||||
System.out.println("You don't have a quartet!");
|
||||
continue;
|
||||
}
|
||||
@@ -47,15 +47,9 @@ public class Human extends Player {
|
||||
continue;
|
||||
}
|
||||
Card card = hand.get(cardIndex);
|
||||
if (Referee.allowedTypes.isEmpty()) {
|
||||
if (!Referee.isValidMove(card, currentCard)) {
|
||||
System.out.println("Invalid move");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (Referee.allowedTypes.contains(card.getType())) {
|
||||
Referee.allowedTypes.clear();
|
||||
}
|
||||
if (!Referee.isValidMove(currentCard, card)) {
|
||||
System.out.println("Invalid move");
|
||||
continue;
|
||||
}
|
||||
hand.remove(cardIndex);
|
||||
return card;
|
||||
@@ -102,7 +96,9 @@ public class Human extends Player {
|
||||
String input = scanner.nextLine();
|
||||
if (input.equals("")) {
|
||||
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();
|
||||
return input;
|
||||
|
||||
@@ -29,10 +29,6 @@ public abstract class Player {
|
||||
return hand.isEmpty();
|
||||
}
|
||||
|
||||
public void addCardToHand(Card card) {
|
||||
hand.add(card);
|
||||
}
|
||||
|
||||
public Card drawCard() {
|
||||
return dealer.drawCard();
|
||||
}
|
||||
|
||||
@@ -11,12 +11,15 @@
|
||||
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~~
|
||||
7. Messages voor alles maken
|
||||
|
||||
## 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
|
||||
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
|
||||
1. UI
|
||||
|
||||
Reference in New Issue
Block a user