added some comments to deck class

This commit is contained in:
Tobydrama 2020-03-03 04:46:03 +01:00
parent f3a02b7ecc
commit d4aae02932

View File

@ -3,13 +3,23 @@ package inf112.fiasko.roborally.objects;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
/**
* This class represents a deck of cards
*/
public class Deck { public class Deck {
private ArrayList<ProgrammingCard> cardDeck; private ArrayList<ProgrammingCard> cardDeck;
/**
* Initalizes the card deck.
* @param cardDeck a list of starting cards.
*/
public Deck(ArrayList<ProgrammingCard> cardDeck){ public Deck(ArrayList<ProgrammingCard> cardDeck){
this.cardDeck=cardDeck; this.cardDeck=cardDeck;
} }
/**
* This method shuffles the cards in the deck so that they are in a random order
*/
public void shuffle() { public void shuffle() {
Random randomNumber = new Random(); Random randomNumber = new Random();
for (int i = cardDeck.size() - 1; i > 0; i--) { for (int i = cardDeck.size() - 1; i > 0; i--) {
@ -23,15 +33,25 @@ public class Deck {
} }
} }
/**
* draws the first card in the card deck
* @return first card in the card deck list
*/
public ProgrammingCard drawCard(){ public ProgrammingCard drawCard(){
ProgrammingCard draw = cardDeck.get(0); ProgrammingCard draw = cardDeck.get(0);
cardDeck.remove(0); cardDeck.remove(0);
return draw; return draw;
} }
/**
* 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
*/
public void drawNCardsFromOtherDeck(int n, Deck otherDeck){ public void drawNCardsFromOtherDeck(int n, Deck otherDeck){
if (n<1 || n>otherDeck.getCards().size()){ if (n<1 || n>otherDeck.getCard().size()){
throw new IllegalArgumentException("cant draw negativ cards or more cards then are in the deck"); throw new IllegalArgumentException("cant draw negativ cards or more cards then are in the other deck");
} }
else{ else{
for (int i=0;i<n;i++){ for (int i=0;i<n;i++){
@ -40,10 +60,18 @@ public class Deck {
} }
} }
/**
* draws the first card from the other deck and adds it to this deck
* @param otherCardDeck the other card deck
*/
public void drawCardOtherDeck(Deck otherCardDeck){ public void drawCardOtherDeck(Deck otherCardDeck){
cardDeck.add(otherCardDeck.drawCard()); cardDeck.add(otherCardDeck.drawCard());
} }
/**
* draws all the cards from this card deck
* @return returns a list of all the cards from this deck
*/
public ArrayList<ProgrammingCard> drawAllCard(){ public ArrayList<ProgrammingCard> drawAllCard(){
ArrayList<ProgrammingCard> allCards= new ArrayList<>(); ArrayList<ProgrammingCard> allCards= new ArrayList<>();
int cardDeckSize = cardDeck.size(); int cardDeckSize = cardDeck.size();
@ -56,13 +84,26 @@ public class Deck {
return allCards; return allCards;
} }
public ArrayList<ProgrammingCard> getCards(){ /**
* gives a list of all the cards inn this deck
* @return a list of all the cards inn this deck
*/
public ArrayList<ProgrammingCard> getCard(){
return cardDeck; return cardDeck;
} }
/**
* checks if this deck is empty
* @return true if empty false otherwise
*/
public Boolean isEmpty(){ public Boolean isEmpty(){
return cardDeck.isEmpty(); return cardDeck.isEmpty();
} }
/**
* gets the size of this deck
* @return size of the deck
*/
public int size(){ public int size(){
return cardDeck.size(); return cardDeck.size();
} }