Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyProgram
- {
- public static Deck deck = new Deck();
- public static void main(String[] args)
- {
- //printDeck();
- deck.shuffle2();
- //DEAL 2 CARDS
- Card c = new Card();
- int points = 0;
- int count = 0; //START AT THE TOP OF DECK
- System.out.println(deck.cards[0]);
- System.out.println(deck.cards[1]);
- points += deck.cards[0].getPoint();
- points += deck.cards[1].getPoint();
- System.out.println(points);
- }
- public static void printDeck(){
- for(int i = 0; i < 52; i++){
- System.out.println(deck.cards[i]);
- }
- }
- }
- public class Deck {
- Card[] cards = new Card[52];
- public Deck(){
- int count = 0;
- for(int i = 0; i < 4; i++){
- for(int j = 0; j < 13; j++){
- cards[count] = new Card(i, j);
- count++;
- }
- }
- }
- //Shuffle by going through deck and swapping
- public void shuffle2(){
- for(int i = 0; i < 52; i++){
- int c = (int)(Math.random()*52);
- Card a = cards[c];
- cards[c] = cards[i];
- cards[i] = a;
- }
- }
- }
- public class Card {
- public static String values = "23456789TJQKA";
- public static String suits = "CDHS";
- private char suit;
- private char val;
- private int point;
- public Card(){
- int index = randomInt(0,13);
- val = values.charAt(index);
- index = randomInt(0,4);
- suit = suits.charAt(index);
- if(index < 8){
- point = index + 2;
- } else if (index == 12) { //ACE
- point = 1;
- } else {
- point = 10; //FACES & 10
- }
- }
- public int getPoint(){
- return point;
- }
- public Card(int s, int v){
- val = values.charAt(v);
- suit = suits.charAt(s);
- if(v < 8){
- point = v + 2;
- } else if (v == 12) { //ACE
- point = 1;
- } else {
- point = 10; //FACES & 10
- }
- }
- public String toString(){
- return "" + val + suit;
- }
- public int randomInt(int lower, int higher){
- return (int)(Math.random()*(higher-lower))+lower;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment