Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unit4.collectionsLib.Stack;
- public class MainDeck {
- Stack<Card> faceDown;
- Stack<Card> faceUp;
- public MainDeck(Card[] cardsArr) {
- faceDown = new Stack<Card>();
- faceUp = new Stack<Card>();
- for (Card c : cardsArr) {
- faceDown.push(c);
- }
- showCard();
- }
- public void showCard() {
- if (faceDown.isEmpty()) {
- // return all faceUp cards
- while (!faceUp.isEmpty())
- faceDown.push(faceUp.pop());
- }
- // show one card
- if (!faceDown.isEmpty())
- faceUp.push(faceDown.pop());
- }
- // move card to final deck
- public boolean moveToFinalDeck(FinalDeck finalDeck) {
- if (!faceUp.isEmpty()) {
- if (finalDeck.add(faceUp.top())) {
- faceUp.pop();
- if (faceDown.isEmpty()) {
- showCard();
- }
- return true;
- }
- }
- return false;
- }
- // move card to column deck
- public boolean moveToColumn(Column col) {
- if (!faceUp.isEmpty()) {
- if (col.add(faceUp.top())) {
- faceUp.pop();
- if (faceDown.isEmpty()) {
- showCard();
- }
- return true;
- }
- }
- return false;
- }
- @Override
- public String toString() {
- String hidden, shown;
- if (faceDown.isEmpty())
- hidden = " ";
- else
- hidden = "[( )]";
- if (faceUp.isEmpty())
- shown = " ";
- else
- shown = "[" + faceUp.top() + "]";
- return String.format("%s %s", hidden, shown);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement