Results 1 to 4 of 4

Thread: Help me plz.

  1. #1
    50285858 is offline Banned
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default Help me plz.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;


    public class BlackJack extends JPanel {
    public BlackJack() {




    int total[] = new int[3];
    boolean valid = true;

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

    String name1;
    String name2;
    int b;





    total[0] = Player1 + Player2;


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


    for(int y = 1 ;y<= number ;y++){

    if(number<=2){
    if(y==1){

    try{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("\nEnter your name : ");
    name1 = in.readLine();
    System.out.println("\n----->>>>>"+name1+"<<<<<-----");
    }catch(IOException e){
    System.out.println(e.getMessage());
    }
    }
    if(y==2){

    try{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("\nEnter your name : ");
    name2 = in.readLine();
    System.out.println("\n----->>>>>"+name2+"<<<<<-----");
    }catch(IOException e){
    System.out.println(e.getMessage());
    }
    }





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

    total[y] = random + random2;
    if((random==10)&&(random2!=10)){

    int random4 = 1 +(int)(Math.random()*3);
    if(random4==1)
    System.out.println("Card 1 : J");
    else if(random4==2)
    System.out.println("Card 1 : Q");
    else if(random4==3)
    System.out.println("Card 1 : K");


    if((random2==1)||(random2==11)){
    if(total[y]<22){
    System.out.print("Card 2 : A");//card = 11
    total[y]=11 + random;}
    else{
    total[y]=1 + random;
    System.out.print("Card 2 : A");}}//card = 1

    else if((random2!=1)||(random2!=11)){

    System.out.print("Card 2 : "+random2);
    System.out.println(" <<-->> Total : "+total[y]);}

    }

    else if((random2==10)&&(random!=10)){


    if((random==1)||(random==11)){
    if(total[y]<22){
    System.out.println("Card 1 : A");//card = 11
    total[y]=11 + random2;}
    else{
    total[y]=1 + random2;
    System.out.println("Card 1 : A");}}//card = 1

    else if((random!=1)||(random!=11)){
    System.out.println("Card 1 : "+random);}

    int random4 = 1 +(int)(Math.random()*3);
    if(random4==1)
    System.out.print("Card 2 : J");
    else if(random4==2)
    System.out.print("Card 2 : Q");
    else if(random4==3)
    System.out.print("Card 2 : K");



    System.out.println(" <<-->> Total : "+total[y]);

    }

    else if((random==10)&&(random2==10)){

    int random4 = 1 +(int)(Math.random()*3);
    if(random4==1)
    System.out.println("Card 1 : J");
    else if(random4==2)
    System.out.println("Card 1 : Q");
    else if(random4==3)
    System.out.println("Card 1 : K");
    int random5 = 1 +(int)(Math.random()*3);
    if(random5==1)
    System.out.print("Card 2 : J");
    else if(random5==2)
    System.out.print("Card 2 : Q");
    else if(random5==3)
    System.out.print("Card 2 : K");


    System.out.println(" <<-->> Total : "+total[0]);

    }

    else if((random==11)&&(random2==11)){
    random = 1;
    }


    else if((random==1)||(random==11)){
    if(total[y]<22){
    System.out.println("Card 1 : A");//card = 11
    System.out.print("Card 2 : "+random2);
    total[y]=11 + random2;
    System.out.println(" <<-->> Total : "+total[y]);}
    else{
    total[y]=1 + random2;
    System.out.println("Card 1 : A");//card = 1
    System.out.print("Card 2 : "+random2);
    System.out.println(" <<-->> Total : "+total[y]);}
    }
    else if((random2==1)||(random2==11)){
    if(total[y]<22){
    System.out.println("Card 1 : "+random);
    System.out.print("Card 2 : A");//card = 11
    total[y]=11 + random;
    System.out.println(" <<-->> Total : "+total[y]);}
    else{
    System.out.println("Card 1 : "+random);
    System.out.print("Card 2 : A");//card = 1
    total[y]=1 + random;
    System.out.println(" <<-->> Total : "+total[y]);}
    }
    else if((random!=11)||(random2!=11)){

    System.out.println("Card 1 : "+random);
    System.out.print("Card 2 : "+random2);
    System.out.println(" <<-->> Total : "+total[y]);}


    if (( total[y] != 21) && (total[y]<=21)){

    //1 +(int)(Math.random()*11)
    //////////////////////////////////////////////// Random card 3 /////////////////////////////////////////
    do{
    int x = GetInput();
    if ( x == JOptionPane.YES_OPTION){
    valid = false ;
    if(total[y]<=21){
    int random3 = 1+(int)(Math.random()*11);
    total[y] = total[y] + random3;

    if(random3==10){
    int random4 = 1 +(int)(Math.random()*3);

    if(random4==1)
    System.out.print("Card : J");
    else if(random4==2)
    System.out.print("Card : Q");
    else if(random4==3)
    System.out.print("Card : K");
    System.out.println(" <<-->> Total : "+total[y]);
    }

    else if((random3==1)||(random3==11)){
    if(total[y]<=9){
    System.out.print("Card : A");//card = 11
    total[y]=10 + total[y];
    System.out.println(" <<-->> Total : "+total[y]);
    }
    else{
    total[y]=0 + total[y];
    System.out.print("Card : A");//card = 1
    System.out.println(" <<-->> Total : "+total[y]);
    }

    }
    else if((random3!=1)||(random3!=11)){
    System.out.print("Card : "+random3);
    System.out.println(" <<-->> Total : "+total[y]);}
    }
    }
    else {valid =true ; }
    }while (valid == false);

    }
    else if(total[y] == 21){
    System.out.println(" <<-->> Total : "+total[y]);
    System.out.println("\n***** BLACKJACK *****");
    }



    }
    }

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

    total[d]=total[d] - total[d];
    }
    }
    //////////////////////////////////////////////////// ComPuter Ai ////////////////////////////////////////////////////
    System.out.println("\n----->>>>> Computer <<<<<-----");
    if((Player2==10)&&(Player1!=10)){


    if((Player1==1)||(Player1==11)){
    if(total[0]<22){
    System.out.println("Card 1 : A");//card = 11
    total[0]=11 + Player2;}
    else{
    total[0]=1 + Player2;
    System.out.println("Card 1 : A");}}//card = 1
    else if((Player1!=1)&&(Player1!=11)){
    System.out.println("Card 1 : "+Player1);}


    int random4 = 1 +(int)(Math.random()*3);
    if(random4==1)
    System.out.print("Card 2 : J");
    else if(random4==2)
    System.out.print("Card 2 : Q");
    else if(random4==3)
    System.out.print("Card 2 : K");


    System.out.println(" <<-->> Total : "+total[0]);
    }

    else if((Player1==10)&&(Player2!=10)){


    if((Player2==1)||(Player2==11)){
    if(total[0]<22){
    System.out.print("Card 2 : A");//card = 11
    total[0]=11 + Player1;}
    else{
    total[0]=1 + Player1;
    System.out.print("Card 2 : A");}}//card = 1



    int random4 = 1 +(int)(Math.random()*3);
    if(random4==1)
    System.out.println("Card 1 : J");
    else if(random4==2)
    System.out.println("Card 1 : Q");
    else if(random4==3)
    System.out.println("Card 1 : K");

    System.out.print("Card 2 : "+Player2);
    System.out.println(" <<-->> Total : "+total[0]);
    }
    else if((Player1==10)&&(Player2==10)){

    int random4 = 1 +(int)(Math.random()*3);
    if(random4==1)
    System.out.println("Card 1 : J");
    else if(random4==2)
    System.out.println("Card 1 : Q");
    else if(random4==3)
    System.out.println("Card 1 : K");
    int random5 = 1 +(int)(Math.random()*3);
    if(random5==1)
    System.out.print("Card 2 : J");
    else if(random5==2)
    System.out.print("Card 2 : Q");
    else if(random5==3)
    System.out.print("Card 2 : K");


    System.out.println(" <<-->> Total : "+total[0]);


    }
    else if(total[0] == 21){
    System.out.println(" <<-->> Total : "+total[0]);
    System.out.println("\n***** BLACKJACK *****");
    }
    else {
    System.out.println("Card 1 : "+Player1);
    System.out.print("Card 2 : "+Player2);
    System.out.println(" <<-->> Total : "+total[0]);}

    //////////////////////////////////////////////////// Result //////////////////////////////////////////////////////////
    System.out.println("\n\n<<<<<----->>>>> concisely <<<<<----->>>>>");
    System.out.println("\n Computer Has "+total[0]);
    if(number==1)
    System.out.println(" Player 1 Has "+total[1]);
    else if(number==2){
    System.out.println(" Player 1 Has "+total[1]);
    System.out.println(" Player 2 Has "+total[2]);
    }





    java.util.Date time;
    time = new java.util.Date();


    if ((total[0] > total[1]) && (total[0] > total[2])){
    System.out.println("\n\n----->>>>>Computer Has Won!!<<<<<----->>>>>"+time);
    }

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

    else if (( total[2] > total[0] ) && (total[2] > total[1])){
    System.out.println("\n\n----->>>>>Player 2 Has Won!!<<<<<----->>>>>"+time);
    }
    else if ( (total[1] == total[0]) && (total[1] == total[2])) {
    System.out.println("\n\n----->>>>>Draw!!!<<<<<----->>>>> " );
    }
    else if ( total[1] == total[0] ){
    System.out.println("\n\n----->>>>> Draw Computer!!!<<<<<----->>>>> "+time );
    }
    else if ( total[1] == total[2] ){
    System.out.println("\n\n----->>>>>Player.1 Draw Player.2!!!<<<<<----->>>>> " +time);
    }
    else if ( total[2] == total[0] ){
    System.out.println("\n\n----->>>>>Player.2 Draw Computer!!!<<<<<----->>>>> " +time);
    }


    int z = Playagain();



    }



    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

    public static int Playagain(){
    return JOptionPane.showConfirmDialog(null,"Play again?","Choose",JOptionPane.YES_NO_OPTION);}


    }
























    i want Button "Playagain" be able to
    sorry language i bad enlish language.

  2. #2
    Join Date
    Feb 2009
    Location
    Bangalore
    Posts
    6
    Rep Power
    0

    Default

    couldn't get u?

  3. #3
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    1.CODE tags please. Sorry, I am not going to try to read your code that way.
    2. What have you tried? You can't expect us to write whatever it is you need for you.
    3. Use an appropriate title please. Help me plz is not. In fact people will be more likely to ignore this topic because of its name.

    For people who don't understand, I think he wants Playagain to play the game again when it's clicked. 50285858, This forum is meant for you to bring your problems when your stuck. You don't have a problem because you haven't tried or started what you're trying to do yet. You can't just say help plz and expect people to do work for you.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  4. #4
    50285858 is offline Banned
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default

    Thx all people .
    sorry i don't writing not good.
    Programs me good :
    ขอบคุณมากครับ สำหรับทุกคำตอบ ผมขอโทษที่ผมเขียนคำถามไม่รู้เรื่อง

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •