Changes by DTieman
This commit is contained in:
@@ -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));
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ public class Human extends Player {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (input.equals("quartet")) {
|
if (input.equals("quartet")) {
|
||||||
if (Referee.isValidQuartet(hand)) {
|
if (Referee.isValidQuartet(hand)) {
|
||||||
System.out.println("You played a quartet!");
|
System.out.println("You played a quartet!");
|
||||||
|
|
||||||
hand.clear();
|
hand.clear();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
System.out.println("You don't have a quartet!");
|
System.out.println("You don't have a quartet!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -47,15 +47,9 @@ 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user