AfterKraft / BlackJack

BlackJack Program for our Group Project
0 stars 0 forks source link

BetHandler and DeckArrayManager (new additions) #19

Closed kevinnaruse closed 11 years ago

kevinnaruse commented 11 years ago

I finally got BetHandler to work, and when ran from as an application (not an applete) it shows up just right. I am now working to add the actual functionality to the applet. will have event handler and audio files mouse click and keyboard , will commit when done. Because I had github issues with pushing upstream or commits that I had to paste the code for BetHandler on below ==>>

DeckArrayManager public class DeckArrayManager extends Deck { private static DeckArrayManager instance; private Card[] card; private int[] deck = new int[52]; private String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; private String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}; private int count = 0; private Card[] stack; private Card[] heap; private Card[] recycleBin;

/**
 *  This method is accessed from 
 *  outside the class by 
 *  
 *  deck = DeckArrayManager.getDeckArrayManager();
 * @return
 */
public int getCount()
{
    return count;
}
public void setCount(int c)
{
    count = c;
}
public boolean needShuffle()
{
    if (count == 50)
        return true;
    else
        return false;
}
public static DeckArrayManager getDeckArrayManager()
{
    if (instance == null)
    {
        instance = new DeckArrayManager();
        System.out.println("[DeckArrayManager] inside getter() method");
    }
    return instance;
}
public void serveCard()
{
    if (needShuffle() == false)
        count++;
    else
        shuffle();
}

// Recycle all cards into stack
public void initDeck()
{
    for (int i = 0; i < deck.length; i++)
        deck[i] = i;
}
// Shuffle the cards
public void shuffle()
{
    for (int i = 0; i < deck.length; i++) 
    {
      // Generate an index randomly
      int index = (int)(Math.random() * deck.length);
      int temp = deck[i];
      deck[i] = deck[index]; 
      deck[index] = temp;
    }
    System.out.println("[DeckArrayManager] shuffle() method");
}
public void serveHand(int num)
{   // Deal out one hand to one player
    for (int i = count; i < num + count; i++) 
    {
        String suit = suits[deck[i] / 13];
        String rank = ranks[deck[i] % 13];
        System.out.println("Card number " + deck[i] + ": " 
        + rank + " of " + suit);
    }
    System.out.println("[DeckArrayManager] serveHand() method");
}   

public void displayHand(int num)
{   //Display the first hand of cards with the specified size of cards
    for (int i = 0; i < num; i++) 
    {
        String suit = suits[deck[i] / 13];
        String rank = ranks[deck[i] % 13];
        System.out.println("Card number " + deck[i] + ": " 
        + rank + " of " + suit);    
    }
}
public void getCard() 
{

}
public void setCard() 
{

}
public void getStateMachine()
{

}
public void setStateMachine()
{

}

}

package com.whitejack.api.applets; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.GridLayout; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import com.whitejack.gui.WhiteJackFrame;

public class BetHandler extends JApplet implements ActionListener { private MyPanel p; private JFrame frame; private PanelListener handler; private JTextField t1 = new JTextField();

public BetHandler()
{
    setPreferredSize(new Dimension(1095, 135));
    frame = new JFrame();
    frame.setSize(1095,135);
    frame.add(this);
    p = new MyPanel();
    setBackground(Color.YELLOW);
    this.add(p, BorderLayout.CENTER);
    this.add(t1, BorderLayout.SOUTH);
    frame.setVisible(true);
    init();
}   

public void init()
{
    this.add(p, BorderLayout.CENTER);
}
public static BetHandler getBetHandler()
{
    return new BetHandler();
}
public class MyPanel extends JPanel 
{

    private URL path = BetHandler.class.getResource("/com/whitejack/images/GameTable/WoodUp.gif"); // MAKE SURE TO CHANGE THIS BACK TO THE REAL PATH
    public MyPanel()
    {
        setPreferredSize(new Dimension(1095,95));
        setBackground(Color.GREEN);
        setLayout(new BorderLayout());

// this.addActionListener(this); repaint(); }

    private ImageIcon icon = new ImageIcon(path);
    public void paintComponent(Graphics g) 
    {
        super.paintComponent(g);
        g.setColor(Color.BLACK);
//      g.drawImage(icon.getImage(), 0,0, icon.getIconWidth(), icon.getIconHeight(), this);
        g.drawImage(icon.getImage(), 0, 0, 1095, 55, this);
    }
}

// public static class PanelListener implements ActionListener // {
// TODO Auto-generated constructor stub // public void actionPerformed(ActionEvent e) // { //
// System.out.println("You just bet "); // }
// } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("You just bet "); } }