Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
2102-Group-Project-Spring-2017/src/model/CardStack.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (57 sloc)
1.13 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package model; | |
import java.util.ArrayList; | |
import java.util.Random; | |
import java.util.Stack; | |
/** | |
* Made this class just to add functionality to a general stack to keep track of its size | |
* @author Joe | |
* | |
*/ | |
public class CardStack extends Stack<Card> | |
{ | |
private static final long serialVersionUID = 1L; | |
private int _size; | |
public CardStack() | |
{ | |
super(); | |
_size = 0; | |
} | |
@Override | |
public Card push(Card c) | |
{ | |
_size++; | |
return super.push(c); | |
} | |
@Override | |
public Card pop() | |
{ | |
_size--; | |
return super.pop(); | |
} | |
public Card pickCard() | |
{ | |
return this.pop(); | |
} | |
public int getSize() | |
{ | |
return _size; | |
} | |
// Randomizes the stack with the cards in the array argument | |
public void randomizeCards(Card[] cardArray) | |
{ | |
// CardStack cardStack = new CardStack(); | |
ArrayList<Card> cardList = new ArrayList<Card>(); | |
Random r = new Random(); | |
// Add all array contents to list | |
for(Card c : cardArray) | |
{ | |
cardList.add(c); | |
} | |
// Pushes a card at a random index in the card list | |
int initialLength = cardList.size(); | |
for(int i=0; i < initialLength; i++) | |
{ | |
push(cardList.remove(r.nextInt(cardList.size()))); | |
} | |
} | |
} |