diff --git a/src/main/java/inf112/fiasko/roborally/objects/Deck.java b/src/main/java/inf112/fiasko/roborally/objects/Deck.java index ae1e3ad..867a7f2 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Deck.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Deck.java @@ -1,31 +1,37 @@ package inf112.fiasko.roborally.objects; import java.util.ArrayList; +import java.util.List; import java.util.Random; /** * This class represents a deck of cards */ -public class Deck { - private ArrayList cardDeck; +public abstract class Deck implements IDeck { + private ArrayList cardDeck; + /** - * Initalizes the card deck. - * @param cardDeck a list of starting cards. + * Initilazes the deck with cards + * @param cardList list of cards */ - public Deck(ArrayList cardDeck){ - this.cardDeck=cardDeck; + public Deck (ArrayList cardList){ + this.cardDeck = cardList; } + /** * This method shuffles the cards in the deck so that they are in a random order */ + + @Override public void shuffle() { Random randomNumber = new Random(); + for (int i = cardDeck.size() - 1; i > 0; i--) { int index = randomNumber.nextInt(i); - ProgrammingCard CardIndex = cardDeck.get(index); + T CardIndex = cardDeck.get(index); cardDeck.add(index, cardDeck.get(i)); cardDeck.remove(index+1); cardDeck.add(i, CardIndex); @@ -35,78 +41,79 @@ public class Deck { } /** - * draws the first card in the card deck - * @return first card in the card deck list + * draws a card form the other deck and adds it to the current deck + * @param other The deck to draw the card from */ - public ProgrammingCard drawCard(){ - ProgrammingCard draw = cardDeck.get(0); - cardDeck.remove(0); - return draw; + @Override + public void draw(IDeck other){ + Deck otherDeck = (Deck) other; + cardDeck.add(otherDeck.cardDeck.get(0)); + otherDeck.cardDeck.remove(0); } /** - * draws n cards for another card deck and adds it to this card deck - * @param n number of cards you want to draw from the other deck - * @param otherDeck the other card deck + * draws n cards from the other deck and adds them to the current deck + * @param other The other deck to draw from + * @param n The number of cards to draw */ - public void drawNCardsFromOtherDeck(int n, Deck otherDeck){ - if (n<1 || n>otherDeck.getCard().size()){ - throw new IllegalArgumentException("cant draw negativ cards or more cards then are in the other deck"); + @Override + public void draw(IDeck other, int n) { + Deck otherDeck = (Deck) other; + if(n<1||n>otherDeck.size()){ + throw new IllegalArgumentException("n cant be below 1 or over the size of the other card deck"); } - else{ - for (int i=0;i drawAllCard(){ - ArrayList allCards= new ArrayList<>(); - int cardDeckSize = cardDeck.size(); - for (int i=0;i other) { + Deck otherDeck = (Deck) other; + for (int i=0; i getCard(){ - return cardDeck; - } - - /** - * checks if this deck is empty - * @return true if empty false otherwise - */ - public Boolean isEmpty(){ + @Override + public boolean isEmpty() { return cardDeck.isEmpty(); } /** - * gets the size of this deck + * gets the size of the current deck * @return size of the deck */ - public int size(){ + @Override + public int size() { return cardDeck.size(); } + /** + * gets the list of cards inn this deck + * @return list of cards inn the deck + */ + @Override + public List getCards() { + ArrayList returnDeck = new ArrayList(); + for (int i=0;i extends Deck { + + public PlayerDeck(ArrayList cardlist) { + super(cardlist); + } +} diff --git a/src/test/java/inf112/fiasko/roborally/objects/TestPlayerDeck.java b/src/test/java/inf112/fiasko/roborally/objects/TestPlayerDeck.java new file mode 100644 index 0000000..b9e608a --- /dev/null +++ b/src/test/java/inf112/fiasko/roborally/objects/TestPlayerDeck.java @@ -0,0 +1,42 @@ +package inf112.fiasko.roborally.objects; + +import inf112.fiasko.roborally.element_properties.Action; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +public class TestPlayerDeck { + private ProgrammingCard programmingCard1 = new ProgrammingCard(5, Action.MOVE_1); + private ProgrammingCard programmingCard2 = new ProgrammingCard(6, Action.MOVE_2); + private ProgrammingCard programmingCard3 = new ProgrammingCard(7, Action.MOVE_3); + private ProgrammingCard programmingCard4 = new ProgrammingCard(55, Action.MOVE_1); + private ProgrammingCard programmingCard5 = new ProgrammingCard(66, Action.MOVE_2); + private ProgrammingCard programmingCard6 = new ProgrammingCard(756, Action.MOVE_3); + private ArrayList cardlist = new ArrayList(); + private ArrayList cardlist2 = new ArrayList(); + private PlayerDeck testDeck; + private PlayerDeck testDeck2; + @Before + public void setUp() { + cardlist.add(programmingCard1); + cardlist.add(programmingCard2); + cardlist.add(programmingCard3); + cardlist2.add(programmingCard4); + cardlist2.add(programmingCard5); + cardlist2.add(programmingCard6); + testDeck = new PlayerDeck(cardlist); + testDeck2 = new PlayerDeck(cardlist2); + } + @Test + public void testDrawCard(){ + assertEquals(3,testDeck.size()); + assertEquals(3,testDeck2.size()); + testDeck.draw(testDeck2); + assertEquals(4,testDeck.size()); + assertEquals(2,testDeck2.size()); + } + + +}