Skip to content
Snippets Groups Projects
Commit e83c27e9 authored by qingyuw2's avatar qingyuw2
Browse files

misc added

parent 8ff907a6
Branches assignment1.2
No related tags found
No related merge requests found
No preview for this file type
......@@ -60,6 +60,8 @@ public class Deck {
}
deck.add(new ActionCard(3, 4));
deck.add(new ActionCard(4, 4));
deck.add(new ActionCard(5, i));
deck.add(new ActionCard(6, i));
}
}
......
......@@ -83,6 +83,21 @@ public class Player {
if (hand.get(color).size() > 0) {
ret.addAll(hand.get(color));
}
ret.addAll(returnIfNumberMatch(card));
if (ret.size() == 0 && hand.get(4).size() > 0) {
ret.addAll(hand.get(4));
}
return ret;
}
/**
* Helper function to return a list of card that number or action is matched.
* @param card card to be compared with
* @return Arraylist of cards that matched with card by number or action.
*/
private ArrayList<Card> returnIfNumberMatch(Card card) {
ArrayList<Card> ret = new ArrayList<Card>();
int color = card.getColor();
int number = card instanceof NumberCard ? ((NumberCard) card).getNumber() : ((ActionCard)card).getAction();
for (int i = 0; i < 4; ++i) {
if (i == color) {
......
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