Changes by DTieman

This commit is contained in:
Jordan Geurtsen
2022-09-21 23:28:56 +02:00
parent de86579295
commit 86f6000e0e
4 changed files with 25 additions and 29 deletions

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

@@ -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,13 +21,7 @@ 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;
}
} else if (!Referee.isValidMove(card, currentCard)) {
continue; continue;
} }
System.out.printf("%n%s played %s%n", getName(), card); System.out.printf("%n%s played %s%n", getName(), card);
@@ -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;
} }