Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-12-2007, 04:18 PM
Member
 
Join Date: Jul 2007
Posts: 1
stormviper is on a distinguished road
Need help with my code.
Well, its a blackjack game, a very simple one i made for my college assignment, but im having several problems on adding and atm, im having such a headache with it. The game doesnt loopback to the start and I dont know if my "logical" thinking is good enough for the computer though.

Ive done the basics of it, so if anyone could help me "add on" to it, your help is greatly appreciated. If its not too much trouble, could you also make it crash proof.

These are the leftover requirements that i cant figure out yet on how to do.

1)The computer must be able to deal as good as you can. In other words, it will try its best to reach to 21. Implement this “thinking” logic.

2) There is a initial cash balance of 500 for each player, when the game starts.

3) Either players(i.e. you or the computer) can place a bet for each deal, and the program ends when a player has won the game. (remember to display the outcome of the game)

4) A way to repeat the game process till either player or computer loses all his cash.



Code:
Quote:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class BlackJack {
public static void main(String[] args) {
int total[] = new int[3];
boolean valid = true;

int Player1 = 9+(int)(Math.random()*2);
int Player2 =6+(int)(Math.random()*5);
total[0] = Player1 + Player2;

int number = Integer.parseInt(JOptionPane.showInputDialog("Ente r the number of player : Maximum 2 players"));

if (number <= 2){

for(int y = 1 ;y<= number ;y++){
System.out.println("Player :"+y);

int random = 1 +(int)(Math.random()*11);
int random2 = 1 +(int)(Math.random()*11);

System.out.println("1 :"+random);
System.out.println("2 :"+random2);

total[y] = random + random2;

if ( total[y] != 22){
System.out.println(total[y]);

do{
int x = GetInput();
if ( x == JOptionPane.YES_OPTION){
valid = false ;
int random3 = 1 +(int)(Math.random()*11);
total[y] = total[y] + random3;
System.out.println(total[y]);
}

else {

valid =true ;
}
}while (valid == false);

}
else if(total[y] == 22){
total[y] = total[y] - 1;
System.out.println(total[y]+"BLACKJACK");
}
}
}

for(int d = 1;d<=number;d++){
if( total[d] > 21){

total[d]=total[d] - total[d];
}
}

if ((total[0] > total[1] ) && (total[0] > total[2] )){

System.out.println("Computer Has Won!! : " + total[0] );
}
else if (( total[1] > total[0] ) && (total[1] > total[2]) ){

System.out.println("Player 1 Has Won!! : " + total[1] );
}
else if (( total[2] > total[1] ) && (total[2] > total[0] )){

System.out.println("Player 2 Has Won!! : " + total[2] );
}
else if ( (total[2] == total[1] ) && (total[1] == total[0] ) && (total[2] == total[0] )) {

System.out.println("Draw!!! " );
}
else if ( total[2] == total[1] ){

System.out.println("Draw!!! " );
}
else if ( total[2] == total[0] ){

System.out.println("Draw!!! " );
}
else if ( total[1] == total[0] ){

System.out.println("Draw!!! " );
}

System.out.println("pc1 :"+Player1);
System.out.println("pc2 :"+Player2);
System.out.println(total[0]);

}

public static int GetInput(){

return JOptionPane.showConfirmDialog(null,"would u like to deal again?","Choose",JOptionPane.YES_NO_OPTION);
}
}

Last edited by stormviper : 07-12-2007 at 04:59 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help fixing my code.. or non code? MrHuggykins New To Java 1 03-19-2008 11:12 PM
Pls some one to help mi wit this code _nik_ New To Java 3 02-10-2008 03:02 AM
I need help on my code jason27131 New To Java 4 07-28-2007 05:23 AM
tic tac toe code zoe New To Java 1 07-23-2007 05:36 PM
Generating Code Automatically Using Custom code Template In Eclipse JavaForums Eclipse 1 04-26-2007 04:52 PM


All times are GMT +3. The time now is 12:23 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org