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);
|
this.cardList = new ArrayList<>(cardList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Randomises the order of the deck
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void shuffle() {
|
public void shuffle() {
|
||||||
Random randomGenerator = new Random();
|
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
|
@Override
|
||||||
public void draw(IDeck<T> other) {
|
public void draw(IDeck<T> other) {
|
||||||
Deck<T> otherDeck = (Deck<T>) other;
|
Deck<T> otherDeck = (Deck<T>) other;
|
||||||
cardList.add(otherDeck.cardList.remove(0));
|
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
|
@Override
|
||||||
public void draw(IDeck<T> other, int n) {
|
public void draw(IDeck<T> other, int n) {
|
||||||
Deck<T> otherDeck = (Deck<T>) other;
|
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
|
@Override
|
||||||
public void emptyInto(IDeck<T> other) {
|
public void emptyInto(IDeck<T> other) {
|
||||||
Deck<T> otherDeck = (Deck<T>) other;
|
Deck<T> otherDeck = (Deck<T>) other;
|
||||||
otherDeck.draw(this, this.size());
|
otherDeck.draw(this, this.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the deck is empty
|
||||||
|
* @return Boolean for if the deck is empty
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return cardList.isEmpty();
|
return cardList.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size of the deck
|
||||||
|
* @return int size of the deck
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return cardList.size();
|
return cardList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of all the cards in the deck
|
||||||
|
* @return ArrayList of cards from the deck
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<T> getCards() {
|
public List<T> getCards() {
|
||||||
return new ArrayList<>(cardList);
|
return new ArrayList<>(cardList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the card from the deck in String format
|
||||||
|
* @return String the cards from the deck
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -78,11 +110,19 @@ public abstract class Deck<T> implements IDeck<T> {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks at the top card in the deck
|
||||||
|
* @return ProgrammingCard the first card in the deck
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public T peekTop() {
|
public T peekTop() {
|
||||||
return cardList.get(0);
|
return cardList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks at the bottom card of the deck
|
||||||
|
* @return ProgrammingCard the last card in the deck
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public T peekBottom() {
|
public T peekBottom() {
|
||||||
return cardList.get(size()-1);
|
return cardList.get(size()-1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user