Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.card;
- import java.util.Random;
- public class DeckOfCards {
- int FACE[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
- String SUIT[] = { "Diamonds", "Clubs", "Hearts", "Spades" };
- Card deck[] = new Card[52];
- Random randomGenerator = new Random();
- void createDeck() {
- int count = 0;
- int count2 = 0;
- int temp = 0;
- for (int i = 0; i < 4; i++) {
- for (int j = 0+temp; j < 13+temp; j++) {
- deck[j] = new Card(FACE[count2], SUIT[count]);
- count2++;
- }
- count2=0;
- count++;
- temp += 13;
- }
- }
- void shuffleDeck() {
- for(int i = 0; i < 52; i++) {
- int rand = randomGenerator.nextInt(51);
- Card temp = new Card();
- temp = deck[rand];
- deck[rand] = deck[i];
- deck[i] = temp;
- }
- }
- Card dealCard() {
- Card deal = new Card();
- for(int i = 0; i < 52; i++) {
- if(deck[i] != null) {
- deal = deck[i];
- deck[i] = null;
- return deal;
- }
- if(deck[51] == null) {
- return null;
- }
- }
- deck[0] = null;
- return deal;
- }
- int cardsLeft() {
- int count=0;
- for(int i = 0; i < deck.length ; i++) {
- if(deck[i] != null) {
- count++;
- }
- }
- return count;
- }
- }
- class Card {
- int face;
- String suit;
- public Card(int f, String s) {
- face = f;
- suit = s;
- }
- public Card() {
- face = 0;
- suit = null;
- }
- public int getFace() {
- return face;
- }
- public String getSuit() {
- return suit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement