Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Deck.java :
- package Deck;
- import java.util.ArrayList;
- import java.util.Random;
- //pages.cs.wisc.edu/~hasti/cs302/examples/Deck/Deck.java
- public class Deck {
- public static final int DECK_SIZE = 52;
- public static Card[] cards; // array holding all 52 cards
- private int cardsInDeck; // the current number of cards in the deck
- public static ArrayList<Integer> pCards = new ArrayList<>();//player cards
- public Deck() {
- cards = new Card[DECK_SIZE];
- cardsInDeck = DECK_SIZE;
- for (int i = 0; i < 13; i++) {
- cards[i] = new Card(i + 1, Card.DIAMONDS);
- cards[i + 13] = new Card(i + 1, Card.CLUBS);
- cards[i + 26] = new Card(i + 1, Card.HEARTS);
- cards[i + 39] = new Card(i + 1, Card.SPADES);
- }
- }
- public Card deal() {
- if (cardsInDeck>0) {
- pCards.add(cards[0].cNumber);
- for(int i=0;i<cardsInDeck;i++) {
- cards[i] = cards[i+1];
- cards[cardsInDeck-1] = new Card(0,0);
- cardsInDeck--;
- }
- return cards[0];
- }else
- System.out.println("ERROR: No More Cards");
- return new Card(0,0);
- }
- public static void swapCards(Card[] a, int i, int swapped) {
- Card swapper = a[i];
- a[i] = a[swapped];
- a[swapped] = swapper;
- }
- public int getpCard(Card[] a) {
- return 0;
- }
- public void shuffle(Card[] a) {
- int n = a.length;
- Random random = new Random();
- random.nextInt(52);
- for (int i = 0; i<n; i++) {
- int swapped = i + random.nextInt(n - i);
- swapCards(a, i, swapped);
- }
- }
- }
- Main.java
- package Deck;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main extends Deck{
- //Player Wallet
- public int pWallet = 200;
- public int pSum;
- public int pSum() {
- int sum = 0;
- for(int i=0;i<pCards.size();i++) {
- sum = sum + pCards.get(i);
- }
- return sum;
- }
- public void play() {
- if
- System.out.println("hit? stay?");
- }
- public int hitMe (int a) {
- deal();
- return 0;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Deck playingCards = new Deck();
- /* **************************Testing Testing*************************
- shuffles and displays all cards
- playingCards.shuffle(cards);
- for (Card i : cards) {
- System.out.println(i);
- }
- Dealing Tester
- int choice = 1;
- while(choice==1) {
- System.out.println(playingCards.deal());
- Scanner yourDeal = new Scanner(System.in);
- System.out.println("Deal? 1=Deal");
- choice = yourDeal.nextInt();
- System.out.println(cardsInDeck);
- }
- ***************************Testing Testing************************ */
- playingCards.shuffle(cards);
- System.out.println("Welcome to Black Jack. You start with $200");
- System.out.println("How much money would you like to bet?");
- Scanner yourBet = new Scanner(System.in);
- int Bet = yourBet.nextInt();
- System.out.println("your cards are " + playingCards.deal() + " and " + playingCards.deal());
- playingCards.play();
- // Dealing Tester
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement