⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardpile.java

📁 this is asimple java code to play with event free sill
💻 JAVA
字号:
// File  : cards2/CardPile.java// Description: A pile of cards (can be used for a hand, deck, discard pile...)//               Subclasses: Deck (a CardPile of 52 Cards)// Author: Fred Swartz - December 2004 - Placed in public domain.package freecell;import java.util.*;public class CardPile implements Iterable<Card> {    //======================================================= instance variables    private ArrayList<Card> _cards = new ArrayList<Card>(); // All the cards.        //========================================================== pushIgnoreRules    public void pushIgnoreRules(Card newCard) {        _cards.add(newCard);    }        //========================================================== pushIgnoreRules    public Card popIgnoreRules() {        int lastIndex = size()-1;        Card crd = _cards.get(lastIndex);        _cards.remove(lastIndex);        return crd;    }        //===================================================================== push    public boolean push(Card newCard) {        if (rulesAllowAddingThisCard(newCard)) {            _cards.add(newCard);            return true;        } else {            return false;        }    }        //================================================= rulesAllowAddingThisCard    //... Subclasses may override this to enforce their rules for adding.    public boolean rulesAllowAddingThisCard(Card card) {        return true;    }        //===================================================================== size    public int size() {        return _cards.size();    }        //====================================================================== pop    public Card pop() {        if (!isRemovable()) {            throw new UnsupportedOperationException("Illegal attempt to remove.");        }        return popIgnoreRules();    }        //================================================================== shuffle    public void shuffle() {        Collections.shuffle(_cards);    }        //================================================================== peekTop    public Card peekTop() {        return _cards.get(_cards.size() - 1);    }        //================================================================= iterator    public Iterator<Card> iterator() {        return _cards.iterator();    }        //========================================================== reverseIterator    public ListIterator<Card> reverseIterator() {        return _cards.listIterator(_cards.size());    }        //==================================================================== clear    public void clear() {        _cards.clear();    }        //============================================================== isRemovable    public boolean isRemovable() {        return true;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -