diff --git a/src/main/java/inf112/fiasko/roborally/objects/Deck.java b/src/main/java/inf112/fiasko/roborally/objects/Deck.java index 25f364e..76a58a6 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Deck.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Deck.java @@ -8,115 +8,65 @@ import java.util.Random; * This class represents a deck of cards */ public abstract class Deck implements IDeck { - private ArrayList cardDeck; - + private final ArrayList cardList; /** - * Initilazes the deck with cards + * Initializes the deck with cards * @param cardList list of cards */ - public Deck (ArrayList cardList){ - this.cardDeck = cardList; + public Deck (ArrayList cardList) { + this.cardList = 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 randomIndex = randomNumber.nextInt(i); - - T CardRandomIndex = cardDeck.get(randomIndex); - cardDeck.add(randomIndex, cardDeck.get(i)); - cardDeck.remove(randomIndex+1); - cardDeck.add(i, CardRandomIndex); - cardDeck.remove(i+1); - + Random randomGenerator = new Random(); + int deckSize = cardList.size(); + int halfDeckSize = deckSize / 2; + int timesToShuffle = 30 * deckSize; + for (int i = 0; i < timesToShuffle; i++) { + int oldPosition = randomGenerator.nextInt(halfDeckSize); + int newPosition = randomGenerator.nextInt(deckSize - halfDeckSize) + halfDeckSize; + cardList.add(newPosition, cardList.remove(oldPosition)); } } - /** - * draws a card form the other deck and adds it to the current deck - * @param other The deck to draw the card from - */ @Override - public void draw(IDeck other){ - Deck otherDeck = (Deck) other; - cardDeck.add(otherDeck.cardDeck.get(0)); - otherDeck.cardDeck.remove(0); + public void draw(IDeck other) { + Deck otherDeck = (Deck) other; + cardList.add(otherDeck.cardList.remove(0)); } - /** - * 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 - */ @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"); + Deck otherDeck = (Deck) other; + if (n < 1 || n > otherDeck.size()) { + throw new IllegalArgumentException("n can't be below 1 or over the size of the other card deck"); } - else { - for (int i=0; i other) { - Deck otherDeck = (Deck) other; - int size = otherDeck.size(); - for (int i=0; i otherDeck = (Deck) other; + otherDeck.draw(this, this.size()); } - /** - * checks if the deck is empty - * @return true if deck is empty false otherwise - */ @Override public boolean isEmpty() { - return cardDeck.isEmpty(); + return cardList.isEmpty(); } - /** - * gets the size of the current deck - * @return size of the deck - */ @Override public int size() { - return cardDeck.size(); + return cardList.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 (T card:cardDeck){ - returnDeck.add(card); - } - return returnDeck; - + return new ArrayList<>(cardList); } - - } diff --git a/src/main/java/inf112/fiasko/roborally/objects/PlayerDeck.java b/src/main/java/inf112/fiasko/roborally/objects/PlayerDeck.java deleted file mode 100644 index b2af4a9..0000000 --- a/src/main/java/inf112/fiasko/roborally/objects/PlayerDeck.java +++ /dev/null @@ -1,15 +0,0 @@ -package inf112.fiasko.roborally.objects; - -import java.util.ArrayList; - -public class PlayerDeck extends Deck { - - /** - * initalizes the PlayerDeck with a list of cards - * @param cardlist list of programing cards - */ - public PlayerDeck(ArrayList cardlist) { - super(cardlist); - } - -} diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java index ba6ed98..3ee46b2 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java +++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java @@ -5,37 +5,33 @@ import inf112.fiasko.roborally.element_properties.Action; /** * This class represents a programming card */ - public class ProgrammingCard implements ICardWithoutSuit { - private Integer cardValue; - private Action cardAction; + private final Integer cardValue; + private final Action cardAction; /** * Initializes the value and the action of the card * @param cardValue the value of the card * @param cardAction the action of the card */ - public ProgrammingCard(int cardValue,Action cardAction){ - this.cardValue=cardValue; - this.cardAction=cardAction; + public ProgrammingCard(int cardValue, Action cardAction){ + this.cardValue = cardValue; + this.cardAction = cardAction; } - /** - * Returns the value of the card - * @return the value of the card - */ @Override public Integer getValue() { return cardValue; } - /** - * Returns the action the card should perform - * @return the action of the card - */ @Override public Action getSymbol() { return cardAction; } + + @Override + public String toString() { + return this.getValue() + " " + this.cardAction.toString(); + } } diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java new file mode 100644 index 0000000..aeb18cf --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java @@ -0,0 +1,17 @@ +package inf112.fiasko.roborally.objects; + +import java.util.ArrayList; + +/** + * This class represents a deck containing programming cards + */ +public class ProgrammingCardDeck extends Deck { + + /** + * Initializes the PlayerDeck with a list of cards + * @param cardList list of programing cards + */ + public ProgrammingCardDeck(ArrayList cardList) { + super(cardList); + } +} diff --git a/src/test/java/inf112/fiasko/roborally/objects/TestPlayerDeck.java b/src/test/java/inf112/fiasko/roborally/objects/TestProgrammingCardDeck.java similarity index 61% rename from src/test/java/inf112/fiasko/roborally/objects/TestPlayerDeck.java rename to src/test/java/inf112/fiasko/roborally/objects/TestProgrammingCardDeck.java index 7669cd7..62fb3f1 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/TestPlayerDeck.java +++ b/src/test/java/inf112/fiasko/roborally/objects/TestProgrammingCardDeck.java @@ -4,20 +4,22 @@ import inf112.fiasko.roborally.element_properties.Action; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; 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; +public class TestProgrammingCardDeck { + private final ProgrammingCard programmingCard1 = new ProgrammingCard(5, Action.MOVE_1); + private final ProgrammingCard programmingCard2 = new ProgrammingCard(6, Action.MOVE_2); + private final ProgrammingCard programmingCard3 = new ProgrammingCard(7, Action.MOVE_3); + private final ProgrammingCard programmingCard4 = new ProgrammingCard(55, Action.MOVE_1); + private final ProgrammingCard programmingCard5 = new ProgrammingCard(66, Action.MOVE_2); + private final ProgrammingCard programmingCard6 = new ProgrammingCard(756, Action.MOVE_3); + private final ArrayList cardlist = new ArrayList<>(); + private final ArrayList cardlist2 = new ArrayList<>(); + private ProgrammingCardDeck testDeck; + private ProgrammingCardDeck testDeck2; @Before public void setUp() { cardlist.add(programmingCard1); @@ -26,8 +28,8 @@ public class TestPlayerDeck { cardlist2.add(programmingCard4); cardlist2.add(programmingCard5); cardlist2.add(programmingCard6); - testDeck = new PlayerDeck(cardlist); - testDeck2 = new PlayerDeck(cardlist2); + testDeck = new ProgrammingCardDeck(cardlist); + testDeck2 = new ProgrammingCardDeck(cardlist2); } @Test public void testSize(){ @@ -61,9 +63,9 @@ public class TestPlayerDeck { } @Test public void testIsEmpty(){ - assertEquals(false,testDeck.isEmpty()); + assertFalse(testDeck.isEmpty()); testDeck.emptyInto(testDeck2); - assertEquals(true,testDeck.isEmpty()); + assertTrue(testDeck.isEmpty()); } @Test @@ -76,11 +78,11 @@ public class TestPlayerDeck { @Test public void testshuffle(){ - ProgrammingCard card1 =(ProgrammingCard) testDeck.getCards().get(0); + ProgrammingCard card1 = testDeck.getCards().get(0); int noe = card1.getValue(); - ProgrammingCard card2 =(ProgrammingCard) testDeck.getCards().get(1); + ProgrammingCard card2 = testDeck.getCards().get(1); int noe2 = card2.getValue(); - ProgrammingCard card3 =(ProgrammingCard) testDeck.getCards().get(2); + ProgrammingCard card3 = testDeck.getCards().get(2); int noe3 = card3.getValue(); System.out.println(noe); @@ -89,21 +91,15 @@ public class TestPlayerDeck { testDeck.shuffle(); - ProgrammingCard scard1 =(ProgrammingCard) testDeck.getCards().get(0); + ProgrammingCard scard1 = testDeck.getCards().get(0); int snoe = scard1.getValue(); - ProgrammingCard scard2 =(ProgrammingCard) testDeck.getCards().get(1); + ProgrammingCard scard2 = testDeck.getCards().get(1); int snoe2 = scard2.getValue(); - ProgrammingCard scard3 =(ProgrammingCard) testDeck.getCards().get(2); + ProgrammingCard scard3 = testDeck.getCards().get(2); int snoe3 = scard3.getValue(); System.out.println(snoe); System.out.println(snoe2); System.out.println(snoe3); - - - } - - - }