mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-02-01 07:39:35 +01:00
Added more comments to deck
This commit is contained in:
parent
bf63d608a7
commit
9c5a50d74a
@ -18,6 +18,9 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
this.cardList = new ArrayList<>(cardList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Randomises the order of the deck
|
||||
*/
|
||||
@Override
|
||||
public void shuffle() {
|
||||
Random randomGenerator = new Random();
|
||||
@ -31,12 +34,21 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws one card from the other deck
|
||||
* @param other The deck to draw the card from
|
||||
*/
|
||||
@Override
|
||||
public void draw(IDeck<T> other) {
|
||||
Deck<T> otherDeck = (Deck<T>) other;
|
||||
cardList.add(otherDeck.cardList.remove(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws multiple cards from the other deck
|
||||
* @param other The other deck to draw from
|
||||
* @param n The number of cards to draw
|
||||
*/
|
||||
@Override
|
||||
public void draw(IDeck<T> other, int n) {
|
||||
Deck<T> otherDeck = (Deck<T>) other;
|
||||
@ -48,27 +60,47 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the entire deck into the other deck
|
||||
* @param other The deck to move this deck's cards into
|
||||
*/
|
||||
@Override
|
||||
public void emptyInto(IDeck<T> other) {
|
||||
Deck<T> otherDeck = (Deck<T>) other;
|
||||
otherDeck.draw(this, this.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the deck is empty
|
||||
* @return Boolean for if the deck is empty
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return cardList.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the deck
|
||||
* @return int size of the deck
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return cardList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all the cards in the deck
|
||||
* @return ArrayList of cards from the deck
|
||||
*/
|
||||
@Override
|
||||
public List<T> getCards() {
|
||||
return new ArrayList<>(cardList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the card from the deck in String format
|
||||
* @return String the cards from the deck
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@ -78,11 +110,19 @@ public abstract class Deck<T> implements IDeck<T> {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks at the top card in the deck
|
||||
* @return ProgrammingCard the first card in the deck
|
||||
*/
|
||||
@Override
|
||||
public T peekTop() {
|
||||
return cardList.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks at the bottom card of the deck
|
||||
* @return ProgrammingCard the last card in the deck
|
||||
*/
|
||||
@Override
|
||||
public T peekBottom() {
|
||||
return cardList.get(size()-1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user