FAQ  •  Register  • 
  • Login
  • Help with Java?

    <<

    Gamage

    User avatar

    Member
    Member

    Posts: 277

    Joined: Sun Mar 21, 2010

    Location: Mississauga, Onatario

    Division: Bad Company 2

    Reputation: 0

    Post Thu Jan 20, 2011 4:31 am

    Help with Java?

    Basically I need help with a blackjack program. I got everything except images working. I've been trying for a few hours now and am asking for help now. Basically I have a png with all cards on it and need to extract certain parts/cards. I have the code but nothing will show while if I use lets say fillrect or something it appears help?

    The cards
    Image

    The code
      Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.net.URL;
    public class blackjack extends JFrame implements ActionListener{   
     
    /////////////////////////////////////////Declerations///////////////////////////////////////////////////////////////////
    ///////////////////////All variables and gui components are declared here//////////////////////////////////////////////
      String []cards,suits;
      int w=0,a=0,l=0,playercardsheld=0,dealercardsheld=0;
      int [][]checklist1,playercards,dealercards;
      String[]checklist2;
      int playertotal=0,value=0,dealertotal=0,playerace=0,dealerace=0;
      String getchar,turn=("Player");
      String getcardchar;
      int getcharlength=0,searchchar=0 ;
      boolean dealerdone=false;
      int[]playercardvalue,playercardsuit;
      int[]dealercardvalue,dealercardsuit;
      MyDrawPanel drawpanel1;
      JPanel panel1;
      Image cardImages;
      JButton buttonstart,buttondeal,buttonstop,buttonreset;
     
      public static void main(String[ ] args)
      {
        new blackjack ();
      } 
     
    //////////////////////////////////Main Routine//////////////////////////////////////////////////////////////////////////
    ///////////////Where gui components and arrays are created/prepared////////////////////////////////////////////////////
      public blackjack (){
        panel1=new JPanel();
        panel1.setLayout(new GridLayout(2,2,4,4));
        this.setLayout(new BorderLayout());
       
        cards=new String [13];
        suits=new String [4];
        checklist1=new int [13][4];
        playercards=new int [13][4];
        dealercards=new int [13][4];
        checklist2=new String [52];
        playercardvalue=new int[52];
        playercardsuit=new int[52];
        dealercardvalue=new int[52];
        dealercardsuit=new int[52];
       
        buttonstart=new JButton("Start");
        buttonstart.addActionListener(this);
        panel1.add(buttonstart);
        buttondeal=new JButton("Hit");
        buttondeal.addActionListener(this);
        panel1.add(buttondeal);
        buttonstop=new JButton("Hold");
        buttonstop.addActionListener(this);
        panel1.add(buttonstop);
        buttonreset=new JButton("Reset");
        buttonreset.addActionListener(this);
        panel1.add(buttonreset);
       
        for (int a=0;a<13;a++)
          cards[a]=(""+a);
        cards[0]=("Ace");
        cards[1]=("Jack");
        cards[11]=("Queen");
        cards[12]=("King");
        suits[0]=("Clubs");
        suits[1]=("Diamonds");
        suits[3]=("Spades");
        suits[2]=("Hearts");
       
        drawpanel1=new MyDrawPanel();
        this.add(panel1,BorderLayout.SOUTH);
        this.add(drawpanel1,BorderLayout.CENTER);
        this.setSize(900,800);
        this.setVisible(true);
        buttonreset.setEnabled (false);
        buttondeal.setEnabled (false);
        buttonstop.setEnabled (false);
       
        randomize();
      }
     
    ////////////////////////////////////Buttons/////////////////////////////////////////////////////////////////////////////
    ///////////////////////Where all button clicks are stored//////////////////////////////////////////////////////////////
      public void actionPerformed(ActionEvent e)
      {
       
       
       
        if (e.getSource()==buttonstart)
        {
          buttonreset.setEnabled (true);
          buttondeal.setEnabled (true);
          buttonstop.setEnabled (true);
          buttonstart.setEnabled (false);
          if (dealercardsheld==0||playercardsheld==0)
          {
            for(int r=0;r<2;r++) 
            {
              changer();
              playercardsheld++;
              playertotal=playertotal+value;
              System.out.println(checklist2[l]);
              l++;
              turn=("Dealer");
              changer();
              dealercardsheld++;
              dealertotal=dealertotal+value;
              System.out.println(checklist2[l]);
              l++;
              turn=("Player");
            }
           
            System.out.println("Player Total: "+playertotal);
            System.out.println("Dealer Total: "+dealertotal);
          }
        }
        if (e.getSource()==buttondeal)
        {
          give();
        }
        if (e.getSource()==buttonreset)
        {
          buttonreset.setEnabled (false);
          buttondeal.setEnabled (false);
          buttonstop.setEnabled (false);
          buttonstart.setEnabled (true);
          reset();
        }
        if (e.getSource()==buttonstop)
        {
          turn=("Dealer");
          give();
          win();
        }
      }
     
    /////////////////////////Change Value Code/////changer();///////////////////////////////////////////////////////////////
    ////////////////////Used to change character values to values//////////////////////////////////////////////////////////
      public void changer() {
        getchar=""+checklist2[l].charAt(0);
        getcharlength=checklist2[l].length();
        searchchar=getcharlength-2;
        getcardchar=""+checklist2[l].charAt(searchchar);
        if (turn.equals("Player"))
        {
          if (getcardchar.equals("b"))
          {
            playercardsuit[l]=0;
          }
          else if (getcardchar.equals("d"))
          {
            playercardsuit[l]=1;
          }
          else if (getcardchar.equals("e"))
          {
            playercardsuit[l]=3;
          }
          else if (getcardchar.equals("t"))
          {
            playercardsuit[l]=2;
          }
          if (getchar.equals("1"))
          {
            getchar=""+getchar+checklist2[l].charAt(1);
            value=Integer.parseInt(getchar);
            playercardvalue[l]=value;
          }
          else if (getchar.equals("J"))
          {
            value=10;
            playercardvalue[l]=1;
          }
          else if (getchar.equals("Q"))
          {
            value=10;
            playercardvalue[l]=11;
          }
          else if (getchar.equals("K"))
          {
            value=10;
            playercardvalue[l]=12;
          }
          else if (getchar.equals("A"))
          {
            ace();
            playercardvalue[l]=0;
          }
          else
            value=Integer.parseInt(getchar);
        }
        else if (turn.equals("Dealer"))
        {
          if (getcardchar.equals("b"))
          {
            dealercardsuit[l]=0;
          }
          else if (getcardchar.equals("d"))
          {
            dealercardsuit[l]=1;
          }
          else if (getcardchar.equals("e"))
          {
            dealercardsuit[l]=2;
          }
          else if (getcardchar.equals("t"))
          {
            dealercardsuit[l]=3;
          }
         
          System.out.println(getcardchar);
          if (getchar.equals("1"))
          {
            getchar=""+getchar+checklist2[l].charAt(1);
            value=Integer.parseInt(getchar);
            dealercardvalue[l]=value;
          }
          else if (getchar.equals("J"))
          {
            value=10;
            dealercardvalue[l]=1;
          }
          else if (getchar.equals("Q"))
          {
            value=10;
            dealercardvalue[l]=11;
          }
          else if (getchar.equals("K"))
          {
            value=10;
            dealercardvalue[l]=12;
          }
          else if (getchar.equals("A"))
          {
            ace();
            dealercardvalue[l]=0;
          }
          else
            value=Integer.parseInt(getchar);
        }
      }
     
    /////////////////////////Reset Code////////reset();/////////////////////////////////////////////////////////////////////
    /////////////////Used to reset the game/round//////////////////////////////////////////////////////////////////////////
      public void reset (){
        if (playercardsheld==0&&playertotal==0&&checklist1[1][1]==0)
        {
          randomize();
        }
        else
        {
          for (int w=0;w<13;w++)
          {
            for (int a=0;a<4;a++)
            {
              checklist1[w][a]=0;
            }
          }
          for (int p=0;p<52;p++)
          {
            checklist2[p]=(null);
          }
        }
        playertotal=0;
        dealertotal=0;
        dealercardsheld=0;
        playercardsheld=0;
        playerace=0;
        dealerace=0;
        turn=("Player");
        randomize();
      }
     
     
    ////////////////////////////Shuffle cards////////randomize();///////////////////////////////////////////////////////////
    //////////////Used to shuffle the cards and reset if necessary/////////////////////////////////////////////////////////
      public void randomize(){
        l=0;
        if (checklist1[1][1]==1)
          reset();
        else
        {
          for (int p=0;p<52;p++)
          {
            do
            {
              w=(int)(Math.random()*13);
              a=(int)(Math.random()*4);
            }while(checklist1[w][a]==1);
            {
              checklist1[w][a]++;
              checklist2[p]=(cards[w]+" "+suits[a]);
            }
          }
        }
      }
     
    //////////////////////////////Deal Code/////////give();/////////////////////////////////////////////////////////////////
    ////////////////////Used to deal/hit the cards to players//////////////////////////////////////////////////////////////
      public void give(){
        if (turn.equals("Player"))
        {
          System.out.println(checklist2[l]);
          playercardsheld++;
          changer();
          playercardvalue[l]=value;
          playertotal=playertotal+value;
          l++;
          System.out.println("Player Total: "+playertotal);
        }
        else if (turn.equals("Dealer"))
        {
          while (dealertotal<17)
          {
            System.out.println(checklist2[l]);
            dealercardsheld++;
            changer();
            dealertotal=dealertotal+value;
            l++;
            System.out.println("Dealer Total: "+dealertotal);
          }
          dealerdone=true;
        }
        bust();
      }
     
    ///////////////////////////////Win Checker/////////win();///////////////////////////////////////////////////////////////
    ///////////////////////////Checks win conditions///////////////////////////////////////////////////////////////////////
      public void win(){
        if (playertotal<dealertotal&&dealertotal<22||dealertotal==playertotal&&dealertotal<22||dealercardsheld==5&&dealertotal<22)
        {
          System.out.println("Win for Dealer");
        }
        else if (dealertotal<playertotal&&playertotal<22&&dealerdone==true||playercardsheld==5&&playertotal<22&&dealerdone==true)
        {
          System.out.println("Win for Player");
        }
      }
     
    /////////////////////////////Bust Checker/////////bust();///////////////////////////////////////////////////////////////
    ///////////////////////////Checks for busts////////////////////////////////////////////////////////////////////////////
      public void bust(){
        if (playertotal>21)
        {
          System.out.println("Player busts");
          System.out.println("Dealer Wins");
        }
        else if (dealertotal>21)
        {
          System.out.println("dealer busts");
          System.out.println("Player wins");
        }
      }
     
    /////////////////////////////ACE Checker//////////ace();////////////////////////////////////////////////////////////////
    //////////////////////Used to check the Ace value//////////////////////////////////////////////////////////////////////
      public void ace()
      {
        if (turn.equals("Player"))
        {
          if (playertotal>10||playerace>1)
          {
            value=1;
            playerace++;
          }
          else if (playertotal<11||playerace==0)
          {
            value=11;
            playerace++;
          }
        }
        else if (turn.equals("Dealer"))
        {
          if (dealertotal>10||dealerace>1)
          {
            value=1;
          }
          else if (dealertotal<11||dealerace==0)
          {
            value=11;
          }
        }
      }
      class MyDrawPanel extends JPanel
      {
        public void paintComponent(Graphics g) {
          //Converts the ordinay graphics object into a Graphics2d object
          Graphics2D g2 = (Graphics2D)g;
          //This line takes away the jaggedness and smooths out the lines
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
         
          g2.setColor(new Color(255,0,0));
          g2.fillRect (1,1,500,500);
          g2.drawImage(cardImages, 1,1, 20+79, 20+123,0,0 , 79, 123, drawpanel1);
         
        }
            private void loadImage() {
          ClassLoader cl = blackjack.class.getClassLoader();
          URL imageURL = cl.getResource("cards.png");
          if (imageURL != null)
            cardImages = Toolkit.getDefaultToolkit().createImage(imageURL);
        }
      }
    }


    I'm going to ask my teacher but want a second opinion
    • 0

    <<

    (TKC)TheCrimsonStar

    User avatar

    Exalted Member
    Exalted Member

    Posts: 4393

    Joined: Thu May 28, 2009

    Location: Knoxville, Tennessee

    Division: Battlefield 3

    Steam Name: thecrimsonstar

    BF3 Soldier: TheCrimsonStar

    Reputation: 0

    Post Thu Jan 20, 2011 9:56 pm

    Re: Help with Java?

    well I'm in Java...but I'm just starting the advanced class so I'm lost on this :icon_razz:
    • 0

    ASUS Sabertooth P67 | Intel Core i5-2500k @ 3.3GHz | Corsair XMS3 1600 8GB (2 x 4GB) | XFX Radeon HD 6970 | Corsair CMPSU-850TX 850W | Corsair H80 High Performance Liquid CPU Cooler |
    ImageImage
    <<

    Gamage

    User avatar

    Member
    Member

    Posts: 277

    Joined: Sun Mar 21, 2010

    Location: Mississauga, Onatario

    Division: Bad Company 2

    Reputation: 0

    Post Thu Jan 20, 2011 10:05 pm

    Re: Help with Java?

    Lol im just finishing the basic class and starting the advanced class next year. Anyway thanks for trying I managed to get part of this
    • 0

    <<

    »mk(stéálthÉnigma)

    User avatar

    Esteemed Member
    Esteemed Member

    Posts: 1152

    Joined: Thu Jun 18, 2009

    Location: Ohio, USA

    Division: Battlefield 3

    Reputation: 0

    Post Thu Jan 20, 2011 11:13 pm

    Re: Help with Java?

    Im in basic too. LOL. This aint basic.
    • 0

    SwagInYourAO
    CPU: Intel i5-750 2.67GHz (TurboBoost) Memory: 8GB DDR3 1337MHz GPU: ATi Radeon HD 5670 1GB DDR5 OCed 840MHz-Core 1040MHz-Mem Screen: LG 21" 1600x900
    Image
    Image
    Image
    Image Image
    Image
    <<

    (TKC)TheCrimsonStar

    User avatar

    Exalted Member
    Exalted Member

    Posts: 4393

    Joined: Thu May 28, 2009

    Location: Knoxville, Tennessee

    Division: Battlefield 3

    Steam Name: thecrimsonstar

    BF3 Soldier: TheCrimsonStar

    Reputation: 0

    Post Thu Jan 20, 2011 11:27 pm

    Re: Help with Java?

    Gamage wrote:Lol im just finishing the basic class and starting the advanced class next year. Anyway thanks for trying I managed to get part of this


    THAT'S BASIC???? No way...I just finished the intro (basic) class last semester, and we NEVER had something this complex!
    • 0

    ASUS Sabertooth P67 | Intel Core i5-2500k @ 3.3GHz | Corsair XMS3 1600 8GB (2 x 4GB) | XFX Radeon HD 6970 | Corsair CMPSU-850TX 850W | Corsair H80 High Performance Liquid CPU Cooler |
    ImageImage
    <<

    Gamage

    User avatar

    Member
    Member

    Posts: 277

    Joined: Sun Mar 21, 2010

    Location: Mississauga, Onatario

    Division: Bad Company 2

    Reputation: 0

    Post Fri Jan 21, 2011 12:12 am

    Re: Help with Java?

    I swear this is my grade 11 introduction to programming class (University level)
    anyway I found out how to do it ill post below this is my 99% complete code image has to be in the same folder and I only need to add bets

    It may look complicated but this is our sumitive project (worth 15%) we could pick the game mastermind, text twist or basic blackjack.

    Also if your interested this is the "textbook" we use http://math.hws.edu/javanotes/index.html

      Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.net.URL;

    public class blackjack extends JFrame implements ActionListener{   
     
    /////////////////////////////////////////Declerations///////////////////////////////////////////////////////////////////
    ///////////////////////All variables and gui components are declared here//////////////////////////////////////////////
      String []cards,suits;
      int w=0,a=0,l=0,playercardsheld=0,dealercardsheld=0,dealershow=0;
      int [][]checklist1,playercards,dealercards;
      String[]checklist2;
      int playertotal=0,value=0,dealertotal=0,playerace=0,dealerace=0;
      String getchar,turn=("Player");
      String getcardchar;
      int getcharlength=0,searchchar=0 ;
      boolean dealerdone=false;
      int[]playercardvalue,playercardsuit;
      int[]dealercardvalue,dealercardsuit;
      MyDrawPanel drawpanel1;
      JPanel panel1;
      Image cardImages;
      JButton buttonstart,buttondeal,buttonstop,buttonreset;
     
      public static void main(String[ ] args)
      {
        new blackjack ();
      } 
     
    //////////////////////////////////Main Routine//////////////////////////////////////////////////////////////////////////
    ///////////////Where gui components and arrays are created/prepared////////////////////////////////////////////////////
      public blackjack (){
        panel1=new JPanel();
        panel1.setLayout(new GridLayout(2,2,4,4));
        this.setLayout(new BorderLayout());
       
        cards=new String [13];
        suits=new String [4];
        checklist1=new int [13][4];
        playercards=new int [13][4];
        dealercards=new int [13][4];
        checklist2=new String [52];
        playercardvalue=new int[52];
        playercardsuit=new int[52];
        dealercardvalue=new int[52];
        dealercardsuit=new int[52];
        for (int x=0;x<52;x++)
        {
          playercardvalue[x]=2;
          dealercardvalue[x]=2;
          playercardsuit[x]=4;
          dealercardsuit[x]=4;
        }
       
        buttonstart=new JButton("Start");
        buttonstart.addActionListener(this);
        panel1.add(buttonstart);
        buttondeal=new JButton("Hit");
        buttondeal.addActionListener(this);
        panel1.add(buttondeal);
        buttonstop=new JButton("Hold");
        buttonstop.addActionListener(this);
        panel1.add(buttonstop);
        buttonreset=new JButton("Reset");
        buttonreset.addActionListener(this);
        panel1.add(buttonreset);
       
        for (int a=0;a<13;a++)
          cards[a]=(""+a);
        cards[0]=("Ace");
        cards[1]=("Jack");
        cards[11]=("Queen");
        cards[12]=("King");
        suits[0]=("Clubs");
        suits[1]=("Diamonds");
        suits[3]=("Spades");
        suits[2]=("Hearts");
       
        drawpanel1=new MyDrawPanel();
        this.add(panel1,BorderLayout.SOUTH);
        this.add(drawpanel1,BorderLayout.CENTER);
        this.setSize(900,800);
        this.setVisible(true);
        buttonreset.setEnabled (false);
        buttondeal.setEnabled (false);
        buttonstop.setEnabled (false);
        loadImage();
        randomize();
      }
     
    ////////////////////////////////////Buttons/////////////////////////////////////////////////////////////////////////////
    ///////////////////////Where all button clicks are stored//////////////////////////////////////////////////////////////
      public void actionPerformed(ActionEvent e)
      {
       
       
       
        if (e.getSource()==buttonstart)
        {
          buttonreset.setEnabled (true);
          buttondeal.setEnabled (true);
          buttonstop.setEnabled (true);
          buttonstart.setEnabled (false);
          dealershow=1;
          if (dealercardsheld==0||playercardsheld==0)
          {
            for(int r=0;r<2;r++) 
            {
              changer();
              playertotal=playertotal+value;
              System.out.println(checklist2[l]);
              l++;
              playercardsheld++;
              turn=("Dealer");
              changer();
              dealertotal=dealertotal+value;
              System.out.println(checklist2[l]);
              l++;
              dealercardsheld++;
              turn=("Player");
            }
           
            System.out.println("Player Total: "+playertotal);
            System.out.println("Dealer Total: "+dealertotal);
          }
          repaint();
        }
        if (e.getSource()==buttondeal)
        {
          give();
        }
        if (e.getSource()==buttonreset)
        {
          buttonreset.setEnabled (false);
          buttondeal.setEnabled (false);
          buttonstop.setEnabled (false);
          buttonstart.setEnabled (true);
          reset();
        }
        if (e.getSource()==buttonstop)
        {
          turn=("Dealer");
         
          give();
          dealershow=dealercardsheld;
          repaint();
          win();
        }
      }
     
    /////////////////////////Change Value Code/////changer();///////////////////////////////////////////////////////////////
    ////////////////////Used to change character values to values//////////////////////////////////////////////////////////
      public void changer() {
        getchar=""+checklist2[l].charAt(0);
        getcharlength=checklist2[l].length();
        searchchar=getcharlength-2;
        getcardchar=""+checklist2[l].charAt(searchchar);
        if (turn.equals("Player"))
        {
          if (getcardchar.equals("b"))
          {
            playercardsuit[playercardsheld]=0;
          }
          else if (getcardchar.equals("d"))
          {
            playercardsuit[playercardsheld]=1;
          }
          else if (getcardchar.equals("e"))
          {
            playercardsuit[playercardsheld]=3;
          }
          else if (getcardchar.equals("t"))
          {
            playercardsuit[playercardsheld]=2;
          }
          if (getchar.equals("1"))
          {
            getchar=""+getchar+checklist2[l].charAt(1);
            value=Integer.parseInt(getchar);
            playercardvalue[playercardsheld]=9;
          }
          else if (getchar.equals("J"))
          {
            value=10;
            playercardvalue[playercardsheld]=10;
          }
          else if (getchar.equals("Q"))
          {
            value=10;
            playercardvalue[playercardsheld]=11;
          }
          else if (getchar.equals("K"))
          {
            value=10;
            playercardvalue[playercardsheld]=12;
          }
          else if (getchar.equals("A"))
          {
            ace();
            playercardvalue[playercardsheld]=0;
          }
          else
          {
            value=Integer.parseInt(getchar);
            playercardvalue[playercardsheld]=value-1;
          }
        }
        else if (turn.equals("Dealer"))
        {
          if (getcardchar.equals("b"))
          {
            dealercardsuit[dealercardsheld]=0;
          }
          else if (getcardchar.equals("d"))
          {
            dealercardsuit[dealercardsheld]=1;
          }
          else if (getcardchar.equals("e"))
          {
            dealercardsuit[dealercardsheld]=3;
          }
          else if (getcardchar.equals("t"))
          {
            dealercardsuit[dealercardsheld]=2;
          }
         
          System.out.println(getcardchar);
          if (getchar.equals("1"))
          {
            getchar=""+getchar+checklist2[l].charAt(1);
            value=Integer.parseInt(getchar);
            dealercardvalue[dealercardsheld]=9;
          }
          else if (getchar.equals("J"))
          {
            value=10;
            dealercardvalue[dealercardsheld]=10;
          }
          else if (getchar.equals("Q"))
          {
            value=10;
            dealercardvalue[dealercardsheld]=11;
          }
          else if (getchar.equals("K"))
          {
            value=10;
            dealercardvalue[dealercardsheld]=12;
          }
          else if (getchar.equals("A"))
          {
            ace();
            dealercardvalue[dealercardsheld]=0;
          }
          else
          {
            value=Integer.parseInt(getchar);
            dealercardvalue[dealercardsheld]=value-1;
          }
        }
      }
     
    /////////////////////////Reset Code////////reset();/////////////////////////////////////////////////////////////////////
    /////////////////Used to reset the game/round//////////////////////////////////////////////////////////////////////////
      public void reset (){
        if (playercardsheld==0&&playertotal==0&&checklist1[1][1]==0)
        {
          randomize();
        }
        else
        {
          for (int w=0;w<13;w++)
          {
            for (int a=0;a<4;a++)
            {
              checklist1[w][a]=0;
            }
          }
          for (int p=0;p<52;p++)
          {
            checklist2[p]=(null);
          }
        }
        playertotal=0;
        dealertotal=0;
        dealercardsheld=0;
        playercardsheld=0;
        playerace=0;
        dealerace=0;
        turn=("Player");
        for (int x=0;x<52;x++)
        {
          playercardvalue[x]=2;
          dealercardvalue[x]=2;
          playercardsuit[x]=4;
          dealercardsuit[x]=4;
        }
        dealershow=0;
        repaint();
        randomize();
      }
     
     
    ////////////////////////////Shuffle cards////////randomize();///////////////////////////////////////////////////////////
    //////////////Used to shuffle the cards and reset if necessary/////////////////////////////////////////////////////////
      public void randomize(){
        l=0;
        if (checklist1[1][1]==1)
          reset();
        else
        {
          for (int p=0;p<52;p++)
          {
            do
            {
              w=(int)(Math.random()*13);
              a=(int)(Math.random()*4);
            }while(checklist1[w][a]==1);
            {
              checklist1[w][a]++;
              checklist2[p]=(cards[w]+" "+suits[a]);
            }
          }
        }
      }
     
    //////////////////////////////Deal Code/////////give();/////////////////////////////////////////////////////////////////
    ////////////////////Used to deal/hit the cards to players//////////////////////////////////////////////////////////////
      public void give(){
        if (turn.equals("Player"))
        {
          System.out.println(checklist2[l]);
          changer();
          playercardsheld++;
          playertotal=playertotal+value;
          if (playertotal>21&&playerace<1)
            playertotal=playertotal-10;
          l++;
          System.out.println("Player Total: "+playertotal);
        }
        else if (turn.equals("Dealer"))
        {
          while (dealertotal<17)
          {
            System.out.println(checklist2[l]);
            changer();
            dealercardsheld++;
            dealertotal=dealertotal+value;
            l++;
            System.out.println("Dealer Total: "+dealertotal);
            repaint();
          }
          if (dealertotal>21&&dealerace<1)
            dealertotal=dealertotal-10;
          dealerdone=true;
        }
        bust();
        repaint();
      }
     
    ///////////////////////////////Win Checker/////////win();///////////////////////////////////////////////////////////////
    ///////////////////////////Checks win conditions///////////////////////////////////////////////////////////////////////
      public void win(){
        if (playertotal<dealertotal&&dealertotal<22||dealertotal==playertotal&&dealertotal<22||dealercardsheld==5&&dealertotal<22)
        {
          System.out.println("Win for Dealer");
        }
        else if (dealertotal<playertotal&&playertotal<22&&dealerdone==true||playercardsheld==5&&playertotal<22&&dealerdone==true)
        {
          System.out.println("Win for Player");
        }
      }
     
    /////////////////////////////Bust Checker/////////bust();///////////////////////////////////////////////////////////////
    ///////////////////////////Checks for busts////////////////////////////////////////////////////////////////////////////
      public void bust(){
        if (playertotal>21)
        {
          System.out.println("Player busts");
          System.out.println("Dealer Wins");
        }
        else if (dealertotal>21)
        {
          System.out.println("dealer busts");
          System.out.println("Player wins");
        }
      }
     
    /////////////////////////////ACE Checker//////////ace();////////////////////////////////////////////////////////////////
    //////////////////////Used to check the Ace value//////////////////////////////////////////////////////////////////////
      public void ace()
      {
        if (turn.equals("Player"))
        {
          if (playertotal>10||playerace>1)
          {
            value=1;
            playerace++;
          }
          else if (playertotal<11||playerace==0)
          {
            value=11;
            playerace++;
          }
        }
        else if (turn.equals("Dealer"))
        {
          if (dealertotal>10||dealerace>1)
          {
            value=1;
          }
          else if (dealertotal<11||dealerace==0)
          {
            value=11;
          }
        }
      }
      private void loadImage() {
        ClassLoader cl = blackjack.class.getClassLoader();
        URL imageURL = cl.getResource("cards.png");
        if (imageURL != null)
          cardImages = Toolkit.getDefaultToolkit().createImage(imageURL);
      }
     
     
      class MyDrawPanel extends JPanel {
       
        public void paintComponent(Graphics g) {
          Graphics2D g2 = (Graphics2D)g;
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
         
          for (int x=0; x<playercardsheld; x++)
          {
            g.drawImage(cardImages, 20+(110*x),20, 20+(110*x)+79, 20+123,playercardvalue[x]*79, playercardsuit[x]*123, (playercardvalue[x]*79)+79,(playercardsuit[x]*123)+123, drawpanel1);
          }
         
          for (int x=0; x<dealershow; x++)
          {
            g.drawImage(cardImages, 20+(110*x),160, 20+(110*x)+79, 160+123,dealercardvalue[x]*79, dealercardsuit[x]*123, (dealercardvalue[x]*79)+79,(dealercardsuit[x]*123)+123, drawpanel1);
          }
        }
      }
    }
    • 0

    <<

    ME.

    User avatar

    Esteemed Member
    Esteemed Member

    Posts: 1338

    Joined: Thu Aug 6, 2009

    Division: Half-Life 2 Deathmatch

    Reputation: 0

    Post Fri Jan 21, 2011 12:23 am

    Re: Help with Java?

    Sorry, i speak VB, C#, and C++.
    • 0

    ImageImage
    Sometimes measuring the bottleneck can be interpreted in so many ways. The only Thing ATI can render better then Nvidia is BSoD.
    <<

    Gamage

    User avatar

    Member
    Member

    Posts: 277

    Joined: Sun Mar 21, 2010

    Location: Mississauga, Onatario

    Division: Bad Company 2

    Reputation: 0

    Post Fri Jan 21, 2011 12:39 am

    Re: Help with Java?

    ME. wrote:Sorry, i speak VB, C#, and C++.

    Aww I'm jealous of the C# and C++
    • 0

    <<

    ME.

    User avatar

    Esteemed Member
    Esteemed Member

    Posts: 1338

    Joined: Thu Aug 6, 2009

    Division: Half-Life 2 Deathmatch

    Reputation: 0

    Post Fri Jan 21, 2011 1:18 am

    Re: Help with Java?

    Gamage wrote:
    ME. wrote:Sorry, i speak VB, C#, and C++.

    Aww I'm jealous of the C# and C++

    They take time to learn and is a pain in the butt but I started off with VB.net when I was 12 and SQL when I was 13, so switching to C# then later C++ screwed me up with the syntax, but now, I'm working on PHP development with MySQL. Then next semester at school, im taking a C# Course, and my teacher is trying to get Microsoft XNA working, so we can program games for the xbox 360 :D

    I'm jealous of my dad, he programs in every language...
    He does Assembler, C++, C #, java, PHP, ASP.NET, SQL,VB and he can pretty much pick up any language.
    He once wrote a Cash register from scratch in assembler that accepted debit and credit cards. Thats beast. Thats before they had APIs, and addins too.

    Assembler FTW.
    • 0

    ImageImage
    Sometimes measuring the bottleneck can be interpreted in so many ways. The only Thing ATI can render better then Nvidia is BSoD.
    <<

    Gamage

    User avatar

    Member
    Member

    Posts: 277

    Joined: Sun Mar 21, 2010

    Location: Mississauga, Onatario

    Division: Bad Company 2

    Reputation: 0

    Post Fri Jan 21, 2011 1:28 am

    Re: Help with Java?

    I learned VB in grade 9 but it seemed too simple for me so I didn't really expand it and went straight to Java. I wish I followed the same path as you. As for your dad, he's my new idol :icon_eyes:
    • 0


    Return to General Discussion

    Who is online

    Users browsing this forum: No registered users and 2 guests

    cron
    x

    #{title}

    #{text}