Changes by DTieman
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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,13 +21,7 @@ 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.printf("%n%s played %s%n", getName(), card);
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user