2 Replies - 330 Views - Last Post: 03 January 2014 - 04:51 PM Rate Topic: -----

#1 jlark13343  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-January 14

Making Black Jack in processing

Posted 03 January 2014 - 11:18 AM

I'm trying to make it so that when I pass 21 or click stay it will go to the dealers cards. I am a bit confused on how to do that so any advice or help would be awesome. (Right now when I click Hit It adds cards and counts the value also the first two dealer cards show up)

import java.util.ArrayList; 

ArrayList<Integer> theCards = new ArrayList<Integer>();
ArrayList<Integer> myCards = new ArrayList<Integer>();
ArrayList<Integer> dealCards = new ArrayList<Integer>();


  Cards c = new Cards();
    PImage chip1;
    PImage chip2;
    int rnd = (int) (Math.random( ) * (52)) + 1;
    int x=0;
    int Money = 100;
    int Bet= 0;
    int Hit= "Hit";
    int Stay= "Stay";
    int value=0;
   int dealValue=0;


 
void setup(){
  size(500, 500);
  openDeal();
  chip1 = loadImage("cards/greenchip.png");
  chip2 = loadImage("cards/redchip.png");

  
        
}

void draw(){
  background(50,205,50);
  fill(255,0,0);
  rect(420,10,75,30);
  fill(0,0,255);
  text( Hit ,450,30);
  rect(420,50,75,30);
  fill(255,0,0);
  text( Stay,450,70);
  image(chip1,300,400);
  image(chip2,400,400);
  fill(255,255,255);
  rect(300,10,100,30);
  rect(300,50,100,30);
  fill(0,0,0);
  text("Bet: ",310, 70);
  text("Money: ",310, 30);
  cardValue();
  text("My Cards "+ value,200,205);
  text("Dealer Cards "+ dealValue,200,405);
  text(Money,350,30);
  text(Bet,335,70);
  
  //image(myCards[rnd],10,10);
  x=10;
    for(int i=0;i<myCards.size(); i++){
    
    image(c.myCards[myCards.get(i)],x,10);
    x+=50;
    
   
    }
    
    
      x=10;
    for(int i=0;i<dealCards.size(); i++){
    
    image(c.myCards[dealCards.get(i)],x,200);
    x+=50;
    
   
    }

  
    
  
  
    }


void deal(){
  rnd = (int) (Math.random( ) * (52)) + 0;
  theCards.add(rnd);
  
}
void openDeal(){
  for(int i=0; i<4; i++){
   deal(); 
  }
  myCards.add(theCards.get(0));
  dealCards.add(theCards.get(1));
  myCards.add(theCards.get(2));
  dealCards.add(theCards.get(3));
  
  
  
  
}
void mousePressed(){
if(mouseX<350 && mouseX>250  && mouseY>300 && mouseY<450){
 Money -= 5;
}
if(mouseX<350 && mouseX>250  && mouseY>300 && mouseY<450){
 Bet += 5;
 }
if(mouseX<450 && mouseX>350  && mouseY>300 && mouseY<450){
 Money += 5;
}
if(mouseX<450 && mouseX>350  && mouseY>300 && mouseY<450){
  Bet -= 5;
 }
 if(mouseX<490 && mouseX>430  && mouseY>10 && mouseY<30){
  hit();
 }
if(mouseX<490 && mouseX>430 && mouseY>30 && mouseY<50){
 stay(); 
}

}

void hit (){
deal();
myCards.add(rnd);
  
}


void stay(){
  
}


void cardValue(){
  value=0;
  dealValue=0;
  for(int i =0; i<myCards.size(); i++){
    value+=c.cardNum[myCards.get(i)];
    
  }
  
   for(int i =0; i<dealCards.size(); i++){
    dealValue+=c.cardNum[dealCards.get(i)];
    
  }
  
}


Is This A Good Question/Topic? 0
  • +

Replies To: Making Black Jack in processing

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10464
  • View blog
  • Posts: 38,783
  • Joined: 27-December 08

Re: Making Black Jack in processing

Posted 03 January 2014 - 12:39 PM

Moved to Other Languages. Processing != Java. And yes, I am well aware of what Processing is.
Was This Post Helpful? 0
  • +
  • -

#3 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1152
  • View blog
  • Posts: 2,530
  • Joined: 05-May 05

Re: Making Black Jack in processing

Posted 03 January 2014 - 04:51 PM

1. Format your code. Make it easy for others to read your code.
2. Post the snippet of your code where you check the user's hand and determine what to do. Make it so we don't have to peruse all the code to find the focus point.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1