Results 1 to 2 of 2
Thread: blackjack help
- 12-11-2009, 01:27 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
blackjack help
i have my cards printed to the screen but i cant make the dealer any thoughts here is my code
this is the Card Class
import javax.swing.*;
public class CardClass {
private int suitInt, valueInt, valueInt2,valueInt3,valueInt1,suitInt1;
private String suitString,suitString1;
private String suit[]={"Hearts","Spades","Diamonds","Clubs"};
private int value[]={2,3,4,5,6,7,8,9,10,11};
public void setSuit(){
suitInt=(int)(Math.random()*4);
suitString = suit[suitInt];
}
public String getSuit(){
return suitString;
}
public void setValue(){
valueInt=(int) ((Math.random()*10));
valueInt2= value[valueInt];
}
public int getValue(){
return valueInt2;
}
public void setsuit(){
suitInt1=(int)(Math.random()*4);
suitString1 = suit[suitInt1];
}
public String getsuit(){
return suitString1;
}
public void setvalue(){
valueInt1=(int) ((Math.random()*10));
valueInt3= value[valueInt1];
}
public int getvalue(){
return valueInt3;
}
}
This is my main class
import javax.swing.*;
import java.util.*;
public class BlackJack1 {
public static void main(String [] args){
String myInput;
CardClass card=new CardClass();
String s,v;
int totalCards = 0;
int card1Val, card2Val;
double bet=0.0;
boolean gameDone = false;
myInput=JOptionPane.showInputDialog("Welcome to the Black jack table care to play\n1-yes\n2-no");
if(myInput.equals("1")){
myInput=JOptionPane.showInputDialog("Place your bet");
bet=Double.parseDouble(myInput);
System.out.println("Your current bet is $" + bet);
JOptionPane.showMessageDialog(null,"here are your cards sir");
card.setValue();
card.setSuit();
System.out.println(card.getValue() + " of " + card.getSuit());
card1Val = card.getValue();
card.setValue();
card.setSuit();
System.out.println(card.getValue() + " of " + card.getSuit());
card2Val = card.getValue();
totalCards=card1Val + card2Val;
System.out.println("your total amount is " + totalCards);
}
/////////////////////////////
while(gameDone == false){
myInput=JOptionPane.showInputDialog("what would you like to do" + "\n1-Hit"+"\n2-Stay"+"\n3-Surrender" +"\n4-doubledown"+"\n5-Done turn");
if(myInput.equals("1")){
card.setValue();
card.setSuit();
System.out.println(card.getValue() + " of " + card.getSuit());
totalCards+=card.getValue();
System.out.println("your new total is " + totalCards);
if(totalCards>21){
System.out.println("bad luck buddy you break");
gameDone = true;
}
}
if(myInput.equals("2")){
//totalCards=card.getValue() + card.getCardValue();
System.out.println("your new total is " + totalCards);
}
if(myInput.equals("3")){
bet= bet/2;
System.out.println("$"+bet);
System.exit(1);
}
if(myInput.equals("4")){
bet=bet*2;
System.out.println("$"+bet);
card.setvalue();
card.setsuit();
System.out.println(card.getvalue() + " of " + card.getsuit());
totalCards+=card.getvalue();
System.out.println("your Total amount is " + totalCards);
if(totalCards>21){
System.out.println("sorry but you busted");
System.exit(1);
}
}
if(myInput.equals("5")){
System.out.println("now it's the dealers turn");
myInput=JOptionPane.showInputDialog("what would you like to do" + "\n1-Hit"+"\n2-Stay"+"\n3-Surrender" +"\n4-doubledown"+"\n5-Done turn");
System.out.println(card.getValue() + " of " + card.getSuit());
card1Val = card.getValue();
card.setValue();
card.setSuit();
System.out.println(card.getValue() + " of " + card.getSuit());
card2Val = card.getValue();
totalCards+=card.getValue();
System.out.println("your new total is " + totalCards);
while(gameDone == false){
myInput=JOptionPane.showInputDialog("what would you like to do" + "\n1-Hit"+"\n2-Stay");
if(totalCards<15){
myInput=1;
}
if(myInput.equals("1")){
card.setValue();
card.setSuit();
System.out.println(card.getValue() + " of " + card.getSuit());
totalCards+=card.getValue();
System.out.println("your new total is " + totalCards);
if(totalCards>21){
System.out.println("i breakguess you win");
gameDone = true;
}else
if(myInput.equals("2")){
//totalCards=card.getValue() + card.getCardValue();
System.out.println("your new total is " + totalCards);
}
}
}
}
}
}
}
- 12-11-2009, 05:44 AM #2
Compiling your (renamed) code:
When it's the dealer's turn call a method that will automatically play the dealers hand, score it and return the final result, eg, a score or a special code for 'busted'. Then you can finish up the round in you main loop.Java Code:C:\jexp>javac bj.java bj.java:87: incompatible types found : int required: java.lang.String myInput=1; ^ 1 error
Similar Threads
-
My blackjack games random generator doesnt work!
By Addez in forum New To JavaReplies: 16Last Post: 08-17-2009, 05:29 AM -
Multiplayer BlackJack Applet
By lostwake in forum Java AppletsReplies: 0Last Post: 07-23-2009, 11:04 PM -
Need ideas and help for a simple BlackJack Game
By Dannii in forum New To JavaReplies: 5Last Post: 04-27-2009, 10:53 AM -
Help with simple Blackjack Program?
By meeper3000 in forum New To JavaReplies: 2Last Post: 04-26-2009, 09:46 AM -
BlackJack help please,, adding hand values
By javakid9000 in forum New To JavaReplies: 1Last Post: 11-18-2007, 04:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks