Advertisement
mmayoub

Solitaire, FinalDeck

Jul 30th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1.  
  2. public class FinalDeck {
  3. Card topCard;
  4.  
  5. public FinalDeck() {
  6. topCard = null;
  7. }
  8.  
  9. public boolean add(Card card) {
  10. if (topCard == null) {
  11. if (card.getValue() == 1) {
  12. topCard = card;
  13. return true;
  14. }
  15. } else if (topCard.getType() == card.getType() && topCard.getValue() + 1 == card.getValue()) {
  16. topCard = card;
  17. return true;
  18. }
  19.  
  20. return false;
  21. }
  22.  
  23. // move card to Temp deck
  24. public boolean moveToTemp(Column tempDeck) {
  25. if (topCard != null) {
  26. if (tempDeck.add(topCard)) {
  27. this.removeTop();
  28. return true;
  29. }
  30. }
  31.  
  32. return false;
  33. }
  34.  
  35. private void removeTop() {
  36. if (topCard != null) {
  37. if (topCard.getValue() == 1)
  38. topCard = null;
  39. else
  40. topCard = new Card(topCard.getType(), topCard.getValue() - 1);
  41. }
  42. }
  43.  
  44. public boolean isFull() {
  45. if (topCard == null)
  46. return false;
  47.  
  48. return topCard.getValue() == 13;
  49. }
  50.  
  51. @Override
  52. public String toString() {
  53. if (topCard == null)
  54. return " ";
  55.  
  56. return "[" + topCard.toString() + "]";
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement