Skip to content
Snippets Groups Projects
Commit 959a678e authored by FrederickPi1969's avatar FrederickPi1969
Browse files

Ready for test

parent 0db73af2
No related branches found
No related tags found
No related merge requests found
Showing
with 8 additions and 167 deletions
File deleted
No preview for this file type
File added
File deleted
File added
No preview for this file type
No preview for this file type
File deleted
No preview for this file type
File deleted
No preview for this file type
File deleted
File deleted
File deleted
......@@ -3,7 +3,8 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Test" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/UNO" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
......
import java.util.*;
public abstract class Card {
protected String color;
public int cardID;
}
abstract class FunctionalCard extends Card {
abstract void changeGameState();
}
class SkipCard extends FunctionalCard {
void changeGameState() {};
}
class ReverseCard extends FunctionalCard {
void changeGameState() {};
}
class WirdCard extends FunctionalCard {
void changeGameState() {};
}
class WildDrawFourCard extends FunctionalCard {
void changeGameState() {};
}
class NormalCard extends Card {
protected int number;
public NormalCard(String color, int number) {
color = color;
number = number;
}
}
\ No newline at end of file
public class Main {
public static void main(String[] args) {
}
}
\ No newline at end of file
import java.util.ArrayList;
public class RuleController {
private static CardParser parser = new CardParser();
private String currentAllowedColor = "all";
private String currentAllowedNumber = "all";
private String currentAllowedSymbol = "all";
/**
* Given a card played by the user, judge whether this play is valid
* that is, all cards must be played following the rule
* @return whether the play is valid
*/
public boolean isValidPlay(Player player, int cardID, boolean updateIfValid) {
String cardDescription = parser.parseCardID(cardID);
String[] result = parser.parseCardDescription(cardDescription);
String color = result[0];
String type = result[1];
String content = result[2];
boolean valid = false;
if (checkAttrMatch(currentAllowedColor, color))
valid = true;
if (checkAttrMatch(currentAllowedNumber, content) || checkAttrMatch(currentAllowedSymbol, content))
valid = true;
if (content.equals("wildDraw4")) {
valid = checkDraw4IsLegal(player);
}
if (valid && updateIfValid) {
currentAllowedColor = color.equals("NA") ? "none" : color; // wildcard played
if (type.equals("sym")) {
currentAllowedSymbol = content;
currentAllowedNumber = "none";
} else if (type.equals("num")) {
currentAllowedNumber = content;
currentAllowedSymbol = "none";
}
}
return false;
}
private boolean checkAttrMatch(String legalString, String stringToCheck) {
return legalString.equals("all") || stringToCheck.equals(legalString);
}
/**
* Check whether a player have currently allowed color when attempting to play wild draw 4
*/
private boolean checkDraw4IsLegal(Player player) {
ArrayList<Integer> cards = player.getCards();
for (int i = 0; i < cards.size(); i++) {
int cardID = cards.get(i);
String cardDescription = parser.parseCardID(cardID);
String color = parser.parseCardDescription(cardDescription)[0];
if (color.equals(currentAllowedNumber)) return false;
}
return true;
}
/**
* Getter and Setter for Allowed number
*/
public String getAllowedNumber() {
return currentAllowedNumber;
}
public void getAllowedNumber(String number) {
currentAllowedColor = number;
}
/**
* Getter and Setter for Allowed Symbol
*/
public String getCurrentAllowedSymbol() {
return currentAllowedSymbol;
}
public void setAllowedSymbol(String symbol) {
currentAllowedSymbol = symbol;
}
/**
* Getter and Setter for Allowed Color
*/
public String getAllowedColor() {
return currentAllowedColor;
}
public void setAllowedColor(String color) {
currentAllowedColor = color;
}
}
......@@ -8,6 +8,7 @@ public class CardManager {
public CardManager() {
parser = new CardParser();
discardPile = new ArrayList<>();
initializeCardPile();
printCardPile();
}
......@@ -76,7 +77,11 @@ public class CardManager {
discardPile.add(0, cardID);
}
}
/**
* Return number of card left on discard pile
*/
public int numLeftDiscardPile() { return discardPile.size(); }
}
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment