ドラクエ的ポーカー


http://www.wikiroom.com/java/index.php?SourcePost__#b21645ddのポーカーの改良です。
だいぶソースが汚くなりました。
ジョーカーをいれたのと戦績を表示するのが変更点です。
戦績の出しかたはソース読んでください。

   // DQPoker.java
   import java.io.EOFException;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.ObjectInputStream;
   import java.util.HashMap;
   
   import javax.swing.WindowConstants;
   
   public class DQPoker {
       public static void main(String[] args) {
           ObjectInputStream ois = null;
           HashMap<String, Integer> map = null;
           while (true) {
               try {
                   ois = new ObjectInputStream(new FileInputStream(Constants.SCORE_SAVE_FILE));
                   map = (HashMap<String, Integer>) ois.readObject();
                   if (map == null) {
                       map = new HashMap<String, Integer>();
                       map.put(Constants.HANDS_ROYAL_STRAIGHT_FLUSH.getHandName(), 0);
                       map.put(Constants.HANDS_FIVE_CARDS.getHandName(), 0);
                       map.put(Constants.HANDS_STRAIGHT_FLUSH.getHandName(), 0);
                       map.put(Constants.HANDS_FOUR_CARDS.getHandName(), 0);
                       map.put(Constants.HANDS_FULL_HOUSE.getHandName(), 0);
                       map.put(Constants.HANDS_FLUSH.getHandName(), 0);
                       map.put(Constants.HANDS_STRAIGHT.getHandName(), 0);
                       map.put(Constants.HANDS_THREE_CARDS.getHandName(), 0);
                       map.put(Constants.HANDS_TWO_PAIRS.getHandName(), 0);
                       map.put(Constants.HANDS_ONE_PAIR.getHandName(), 0);
                       map.put(Constants.HANDS_NO_PAIRS.getHandName(), 0);
                   }
   
                   break;
               } catch (FileNotFoundException fnfe) {
                   try {
                       if (!Constants.SCORE_SAVE_FILE.createNewFile()) {
                           System.out.println("ファイル作成失敗...");
                           break;
                       }
                   } catch (IOException ioe) {
                   }
               } catch (EOFException eofe) {
                   // たぶんoisがnull
                   if (ois == null) {
                       map = new HashMap<String, Integer>();
                       map.put(Constants.HANDS_ROYAL_STRAIGHT_FLUSH.getHandName(), 0);
                       map.put(Constants.HANDS_FIVE_CARDS.getHandName(), 0);
                       map.put(Constants.HANDS_STRAIGHT_FLUSH.getHandName(), 0);
                       map.put(Constants.HANDS_FOUR_CARDS.getHandName(), 0);
                       map.put(Constants.HANDS_FULL_HOUSE.getHandName(), 0);
                       map.put(Constants.HANDS_FLUSH.getHandName(), 0);
                       map.put(Constants.HANDS_STRAIGHT.getHandName(), 0);
                       map.put(Constants.HANDS_THREE_CARDS.getHandName(), 0);
                       map.put(Constants.HANDS_TWO_PAIRS.getHandName(), 0);
                       map.put(Constants.HANDS_ONE_PAIR.getHandName(), 0);
                       map.put(Constants.HANDS_NO_PAIRS.getHandName(), 0);
                   }
                   break;
               } catch (IOException ioe) {
                   ioe.printStackTrace();
               } catch (ClassNotFoundException cnfe) {
                   cnfe.printStackTrace();
               }
           }
           Player player = new Player("ギコ", 100);
           DQPokerFrame frame = new DQPokerFrame(player, map);
           frame.setTitle("DQ Poker");
           frame.setSize(Constants.WINDOW_WIDTH, Constants.WINDOW_HEIGHT);
           frame.setResizable(false);
           frame.setVisible(true);
           frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
       }
   }
   // DQPokerFrame.java
   import java.awt.BorderLayout;
   import java.awt.Color;
   import java.awt.Font;
   import java.awt.GridLayout;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
   import java.awt.event.KeyEvent;
   import java.awt.event.KeyListener;
   import java.awt.event.MouseEvent;
   import java.awt.event.MouseListener;
   import java.io.File;
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.ObjectOutputStream;
   import java.text.DecimalFormat;
   import java.text.NumberFormat;
   import java.util.HashMap;
   import java.util.Vector;
   
   import javax.imageio.ImageIO;
   import javax.imageio.stream.FileImageInputStream;
   import javax.swing.JButton;
   import javax.swing.JFormattedTextField;
   import javax.swing.JFrame;
   import javax.swing.JLabel;
   import javax.swing.JOptionPane;
   import javax.swing.JPanel;
   import javax.swing.JSpinner;
   import javax.swing.JTextArea;
   import javax.swing.SpinnerNumberModel;
   import javax.swing.event.ChangeEvent;
   import javax.swing.event.ChangeListener;
   
   public class DQPokerFrame extends JFrame implements ActionListener, MouseListener, ChangeListener, KeyListener {
       Player player;
       HashMap<String, Integer> map;
       JPanel panel = new JPanel( new BorderLayout() );
       JPanel northPanel = new JPanel();
       JLabel playerMoney = new JLabel();
       JSpinner spinner;
       JFormattedTextField tf;
       JTextArea order = new JTextArea();
       JButton startButton = new JButton("スタート");
       JPanel centerPanel = new JPanel( new GridLayout( 1, 5 ) );
       JPanel southPanel = new JPanel( new GridLayout(3, 1) );
       JLabel message1 = new JLabel();
       JLabel message2 = new JLabel();
       JButton changeButton = new JButton( "交換" );
       JButton exitButton = new JButton( "終了" );
           Vector<Integer> cardTower;
           CardPanel[] cardPanels = new CardPanel[5];
           Card[] cards;
           Vector<Integer> changeList;
           boolean isKeyPressed;
           
           public DQPokerFrame( Player player, HashMap<String, Integer> map ) {
   order.addKeyListener(this);
           this.player = player;
           this.map = map;
           SpinnerNumberModel model = new SpinnerNumberModel(10, 1, player.getMoney(), 1);
           spinner = new JSpinner(model);
           tf = ((JSpinner.NumberEditor)spinner.getEditor()).getTextField();
           tf.setEditable(true);
           setOrder( (Integer)spinner.getValue() );
           spinner.addChangeListener(this);
           northPanel.add( spinner );
           playerMoney.setText( "" + (player.getMoney()-Integer.parseInt(tf.getText())) );
           northPanel.add( playerMoney );
           northPanel.add( startButton );
           order.setEditable(false);
           northPanel.add( order );
           startButton.addActionListener(this);
   
           message1.setFont( new Font("Dialog", Font.BOLD, 14) );
           message2.setFont( new Font("Dialog", Font.PLAIN, 12) );
           southPanel.add( message1 );
           southPanel.add( message2 );
           changeButton.addActionListener( this );
           changeButton.setEnabled( false );
           JPanel p1 = new JPanel(), p2 = new JPanel(), p3 = new JPanel();
           p1.add(message1);
           p2.add(message2);
           p3.add(changeButton);
           exitButton.addActionListener(this);
           p3.add(exitButton);
           southPanel.add( p1 );
           southPanel.add( p2 );
           southPanel.add( p3 );
           
           panel.add( northPanel, BorderLayout.NORTH );
           panel.add( centerPanel, BorderLayout.CENTER );
           panel.add( southPanel, BorderLayout.SOUTH );
           getContentPane().add( panel );
           
           reset();
       }
       
       private void reset() {
           changeList = new Vector<Integer>();
           cardTower = new Vector<Integer>();
           centerPanel.removeAll();
       }
       
       /**
        * カードを配る
        *
        */
       private void dealCards() { 
           try {
               for( int i=0; i<54; i++ ) cardTower.add( i );
   //                Collections.shuffle( cardTower );
               cards = new Card[5];
               for( int i=0 ;i<5; i++ ) {
                   int position = cardTower.remove( (int)(Math.random()*cardTower.size()) );
   //                    char mark = getMarkChar(position);
   //                    String number = getNumber(position);
                   String fileName = getFileName(position);
                   cards[i] = new Card(fileName);
                   cardPanels[i] = new CardPanel();
                   cardPanels[i].addMouseListener(this);
                   cardPanels[i].setImage( ImageIO.read( new FileImageInputStream(new File(Constants.IMAGE_DIRECTORY + fileName)) ) );
                   centerPanel.add( cardPanels[i] );
               }
               message1.setText( DQPokerRule.getHand( cards ).getHandName() );
               message1.setForeground( Color.CYAN );
               message2.setText( "交換するカードを選んで交換ボタンを押してください。" );
               changeButton.setEnabled( true );
               centerPanel.repaint();
           } catch( IOException ioe ) {
               ioe.printStackTrace();
           }
       }
       
       private String getFileName(int position) {
           String fileName;
           if( position == 53 ) fileName = Constants.JOKER1_FILE_NAME;
           else if( position == 52 ) fileName = Constants.JOKER2_FILE_NAME;
           else fileName = getMarkChar(position) + getNumber(position) + ".bmp";
           return fileName;
       }
       
       private char getMarkChar(int position) {
           int mark_num = position / 13;
           switch( mark_num ) {
               case 0: return 'c';
               case 1: return 'd';
               case 2: return 'h';
               case 3: return 's';
               default: throw new IllegalArgumentException();
           }
       }
       
       private String getNumber(int position) {
           
           NumberFormat formatter = new DecimalFormat("00");
               return formatter.format( position%13+2 );
           }
       
           public void actionPerformed(ActionEvent ae) {
               if( ae.getSource() == startButton ) {
                   reset();
                   dealCards();
                   startButton.setEnabled(false);
                   spinner.setEnabled(false);
                   
               } else if( ae.getSource() == changeButton ) {
                   try {                
                       for( int i : changeList ) {        
                           centerPanel.remove( cardPanels[i] );
                           int position = cardTower.remove((int)(Math.random()*cardTower.size()));
                           String fileName = getFileName(position);
                           cards[i] = new Card(fileName);
                           cardPanels[i] = new CardPanel();
                           cardPanels[i].addMouseListener(this);
                           cardPanels[i].setImage( ImageIO.read( new FileImageInputStream(new File(Constants.IMAGE_DIRECTORY + fileName)) ) );
                           centerPanel.add( cardPanels[i], i );
                       }
                       centerPanel.repaint();
                       for( int i=0; i<5; i++ ) cardPanels[i].removeMouseListener(this);
                       DQPokerHand hand = DQPokerRule.getHand( cards );
   map.put( hand.getHandName(), getScoreValue(map, hand) + 1 );
   ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream( Constants.SCORE_SAVE_FILE ) );
   oos.writeObject( map );
                       message1.setText( hand.getHandName() );
                       player.setMoney( Integer.parseInt(playerMoney.getText()) + ((Integer)spinner.getValue()*hand.getMagnification()) );
                       
                       message1.setForeground( Color.BLUE );
                       changeButton.setEnabled(false);                
                       
                       if( player.getMoney() <= 0 ) {
                           message2.setText( "所持金がなくなりました..." );
                       JOptionPane.showMessageDialog( this, "  _, ._\n( ゚ Д゚)<所持金がなくなりました...", null, JOptionPane.ERROR_MESSAGE, null );
                       startButton.setEnabled(false);
                       spinner.setEnabled(false);
                   } else {
                       message2.setText( "続ける場合はスタートボタンを押してください。" );
                       startButton.setEnabled(true);
                       spinner.setEnabled(true);
                       for( int i=(Integer)spinner.getValue(); ;  ){
                           try {
                               spinner.setModel( new SpinnerNumberModel(i, 1, player.getMoney(), 1) );
                               playerMoney.setText( "" + (player.getMoney() - (Integer)spinner.getValue()) );
                               break;
                           } catch( IllegalArgumentException iae ) {
                               i--;
                           }
                       }
                   }
               } catch( IOException ioe ) {
                   ioe.printStackTrace();
               }
           } else if( ae.getSource() == exitButton ) {
               System.exit(0);
           }
       }
       
       private int getScoreValue( HashMap<String, Integer> map, DQPokerHand hand ) {
           Integer value = map.get(hand.getHandName());
           if( value == null ) return 0;
           else return value;
       }
       
       public void mouseClicked(MouseEvent e) {
           if( e.getSource() instanceof CardPanel ) {
               CardPanel clickedPanel = (CardPanel)e.getSource();
               int x = 0;
               for( x=0; x<cardPanels.length; x++ ) {
                   if( clickedPanel == cardPanels[x] ) break;
               }
               try {
                   changeList.add( x );
                   cardPanels[x].setImage( ImageIO.read( new FileImageInputStream(new File(Constants.IMAGE_DIRECTORY + Constants.BACK_FILE_NAME)) ) );
                   panel.paintImmediately( 0, 0, panel.getWidth(), panel.getHeight() );
               } catch( IOException ioe ) {
                   ioe.printStackTrace();
               }
           }
       }
   
       public void mousePressed(MouseEvent e) {}
       public void mouseReleased(MouseEvent e) {}
       public void mouseEntered(MouseEvent e) {}
       public void mouseExited(MouseEvent e) {}
   
       public void stateChanged(ChangeEvent e) {
           JSpinner sp = (JSpinner)e.getSource();
           playerMoney.setText( "" + (player.getMoney()-(Integer)sp.getValue()) );
           setOrder( (Integer)sp.getValue() );
       }
       
       private void setOrder( int bet ) {
           order.setText( 
                   Constants.HANDS_ROYAL_STRAIGHT_FLUSH.getHandName() + ":" + bet + "x" + Constants.HANDS_ROYAL_STRAIGHT_FLUSH.getMagnification() + "=" + bet*Constants.HANDS_ROYAL_STRAIGHT_FLUSH.getMagnification() + "\n" +
                   Constants.HANDS_FIVE_CARDS.getHandName() + ":" + bet + "x" + Constants.HANDS_FIVE_CARDS.getMagnification() + "=" + bet*Constants.HANDS_FIVE_CARDS.getMagnification() + "\n" +
                   Constants.HANDS_STRAIGHT_FLUSH.getHandName() + ":" + bet + "x" + Constants.HANDS_STRAIGHT_FLUSH.getMagnification() + "=" + bet*Constants.HANDS_STRAIGHT_FLUSH.getMagnification() + "\n" +
                   Constants.HANDS_FOUR_CARDS.getHandName() + ":" + bet + "x" + Constants.HANDS_FOUR_CARDS.getMagnification() + "=" + bet*Constants.HANDS_FOUR_CARDS.getMagnification() + "\n" +
                   Constants.HANDS_FULL_HOUSE.getHandName() + ":" + bet + "x" + Constants.HANDS_FULL_HOUSE.getMagnification() + "=" + bet*Constants.HANDS_FULL_HOUSE.getMagnification() + "\n" +
                   Constants.HANDS_FLUSH.getHandName() + ":" + bet + "x" + Constants.HANDS_FLUSH.getMagnification() + "=" + bet*Constants.HANDS_FLUSH.getMagnification() + "\n" +
                   Constants.HANDS_STRAIGHT.getHandName() + ":" + bet + "x" + Constants.HANDS_STRAIGHT.getMagnification() + "=" + bet*Constants.HANDS_STRAIGHT.getMagnification() + "\n" +
                   Constants.HANDS_THREE_CARDS.getHandName() + ":" + bet + "x" + Constants.HANDS_THREE_CARDS.getMagnification() + "=" + bet*Constants.HANDS_THREE_CARDS.getMagnification() + "\n" +
                   Constants.HANDS_TWO_PAIRS.getHandName() + ":" + bet + "x" + Constants.HANDS_TWO_PAIRS.getMagnification() + "=" + bet*Constants.HANDS_TWO_PAIRS.getMagnification() + "\n" +
                   Constants.HANDS_ONE_PAIR.getHandName() + ":" + bet + "x" + Constants.HANDS_ONE_PAIR.getMagnification() + "=" + bet*Constants.HANDS_ONE_PAIR.getMagnification() + "\n" +
                   Constants.HANDS_NO_PAIRS.getHandName() + ":" + bet + "x" + Constants.HANDS_ONE_PAIR.getMagnification() + "=" + bet*Constants.HANDS_NO_PAIRS.getMagnification()
                   );
       }
   
       public void keyTyped(KeyEvent e) {}
   
       public void keyPressed(KeyEvent e) {
           if( e.getKeyChar() == 's' ) {
               isKeyPressed = true;
           } else if( e.getKeyChar() == 'c' ) {
               if( isKeyPressed ) {
                   isKeyPressed = false;
                   JOptionPane.showMessageDialog( this, 
                           Constants.HANDS_ROYAL_STRAIGHT_FLUSH.getHandName() + ":" + getScoreValue(map,Constants.HANDS_ROYAL_STRAIGHT_FLUSH) + "回\n" +
                           Constants.HANDS_FIVE_CARDS.getHandName() + ":" + getScoreValue(map,Constants.HANDS_FIVE_CARDS) + "回\n" +
                           Constants.HANDS_STRAIGHT_FLUSH.getHandName() + ":" + getScoreValue(map,Constants.HANDS_STRAIGHT_FLUSH) + "回\n" +
                           Constants.HANDS_FOUR_CARDS.getHandName() + ":" + getScoreValue(map,Constants.HANDS_FOUR_CARDS) + "回\n" +
                           Constants.HANDS_FULL_HOUSE.getHandName() + ":" + getScoreValue(map,Constants.HANDS_FULL_HOUSE) + "回\n" +
                           Constants.HANDS_FLUSH.getHandName() + ":" + getScoreValue(map,Constants.HANDS_FLUSH) + "回\n" +
                           Constants.HANDS_STRAIGHT.getHandName() + ":" + getScoreValue(map,Constants.HANDS_STRAIGHT) + "回\n" +
                           Constants.HANDS_THREE_CARDS.getHandName() + ":" + getScoreValue(map,Constants.HANDS_THREE_CARDS) + "回\n" +
                           Constants.HANDS_TWO_PAIRS.getHandName() + ":" + getScoreValue(map,Constants.HANDS_TWO_PAIRS) + "回\n" +
                           Constants.HANDS_ONE_PAIR.getHandName() + ":" + getScoreValue(map,Constants.HANDS_ONE_PAIR) + "回\n" +
                           Constants.HANDS_NO_PAIRS.getHandName() + ":" + getScoreValue(map,Constants.HANDS_NO_PAIRS) + "回\n"
                           );
               }
           }
       }
   
       public void keyReleased(KeyEvent e) {
           isKeyPressed = false;
       }    
   }
   // DQPokerRule.java
   import java.util.Arrays;
   import java.util.TreeMap;
   
   public final class DQPokerRule {
       private DQPokerRule() {        
       }
       
       /**
        * 役を返却。
        * @param cards
        * @return 役
        * @see ttp://slime4.hp.infoseek.co.jp/poker/page2.html
        */
       public static DQPokerHand getHand( Card[] cards ) {
           // TreeMap:マップがキーの昇順でソートされる。
           TreeMap<Character, Integer> markMap = new TreeMap<Character, Integer>();        
           TreeMap<Integer, Integer> numberMap = new TreeMap<Integer, Integer>();
           for( int i=0; i<cards.length; i++ ) {
               markMap.put( cards[i].getMark(), getMarkValue(markMap, cards[i].getMark())+1 );
               numberMap.put( cards[i].getNumber(), getNumberValue(numberMap, cards[i].getNumber())+1 );
           }
           int jokerCount = getMarkValue( markMap, '\u0000' );
           // フラッシュかどうか
           boolean isFlush = false;
           for( char c : markMap.keySet() ) {
               if( markMap.get(c) == 5 ) isFlush = true;
               else if( markMap.get(c) == 4 && jokerCount == 1 ) isFlush = true;
               else if( markMap.get(c) == 3 && jokerCount == 2 ) isFlush = true;
           }
           // ストレートかどうか
           boolean isStraight = false;
           for( int num : numberMap.keySet() ) {
               if( num < 2 ) continue;
               int count=0;
               for( int i=num; i<num+5; i++ ) {
                   if( getNumberValue(numberMap, i) == 1 ) count++;
               }
               if( count == 5 ) isStraight = true;
               else if( count == 4 && jokerCount == 1 ) isStraight = true;
               else if( count == 3 && jokerCount == 2 ) isStraight = true;
           }
           // フラッシュorストレートの場合
           if( isFlush || isStraight ) {
               // ストレートフラッシュ
               if( isFlush && isStraight ) {
                   // Aがある場合はロイヤルストレートフラッシュ.ジョーカーありは認めない。
                   if( getNumberValue( numberMap, 14 ) == 1 && jokerCount == 0 ) return Constants.HANDS_ROYAL_STRAIGHT_FLUSH;
                   else return Constants.HANDS_STRAIGHT_FLUSH;
               } else if( isFlush ) {
                   return Constants.HANDS_FLUSH;
               } else if( isStraight ) {
                   return Constants.HANDS_STRAIGHT;
               } else {
                   throw new IllegalArgumentException("ありえません..");
               }
           // フラッシュでもストレートでもない場合
           } else {
               Integer[] values = numberMap.values().toArray( new Integer[0] );
               Arrays.sort( values );
               // フォーカード
               if( values[values.length-1] == 4 ) {
                   if( jokerCount == 1 ) return Constants.HANDS_FIVE_CARDS;
                   else return Constants.HANDS_FOUR_CARDS;
               }
               // スリーカードがある場合
               else if( values[values.length-1] == 3 ) {
                   // ワンペアもある場合
                   if( values[values.length-2] == 2 ) {
                       return Constants.HANDS_FULL_HOUSE;
                   // ワンペアがない場合
                   } else {
                       if( jokerCount == 2 ) return Constants.HANDS_FIVE_CARDS;
                       else if( jokerCount == 1 ) return Constants.HANDS_FOUR_CARDS;
                       else return Constants.HANDS_THREE_CARDS;
                   }
               // ワンペアがある場合
               } else if( values[values.length-1] == 2 ) {
                   // もうひとつワンペアがある場合
                   if( values[values.length-2] == 2 ) {
                       if( jokerCount == 2 ) return Constants.HANDS_FOUR_CARDS;
                       else if( jokerCount == 1 ) return Constants.HANDS_FULL_HOUSE;
                       else return Constants.HANDS_TWO_PAIRS;
                   } else {
                       if( jokerCount == 2 ) return Constants.HANDS_THREE_CARDS;
                       else if( jokerCount == 1 )  return Constants.HANDS_THREE_CARDS;
                       else return Constants.HANDS_ONE_PAIR;
                   }
               } else if( values[values.length-1] == 1 ) {
                   if( jokerCount == 1 ) return Constants.HANDS_ONE_PAIR;
                   return Constants.HANDS_NO_PAIRS;                
               } else {
                   throw new IllegalArgumentException("ありえません..");
               }
           }        
       }
       
       private static int getMarkValue( TreeMap<Character, Integer> markMap, char mark ) {
           Integer value = markMap.get( mark );
           if( value == null ) return 0;
           else return value;
       }
       
       private static int getNumberValue( TreeMap<Integer, Integer> numberMap, int num ) {
           Integer value = numberMap.get( num );
           if( value == null ) return 0;
           else return value;
       }
   }
   // DQPokerHand.java
   public class DQPokerHand {
       private String handName;
       private int magnification;
       
       public DQPokerHand( String handName, int magnification ) {
           this.handName = handName;
           this.magnification = magnification;
       }
       
       public String getHandName() {
           return this.handName;
       }
       
       public int getMagnification() {
           return this.magnification;
       }
   }
   // Player.java
   public class Player {
       private final String name;
       private int money;
   
       public Player(String name, int money) {
           this.name = name;
           this.money = money;
       }
       public int getMoney() {
           return money;
       }
       public void setMoney(int money) {
           this.money = money;
       }
       public String getName() {
           return name;
       }
   }
   // Card.java
   import java.text.DecimalFormat;
   import java.text.NumberFormat;
   
   public class Card {
       /**
        * 'c':クラブ
        * 'd':ダイヤ
        * 'h':ハート
        * 's':スペード
        */
       private char mark = '\u0000';
       /**
        * 数字は2〜14
        */
       private int number = 0;
       private String fileName;
       
       boolean isJoker = false;
       
       public Card(char mark, int number) {
           this.mark = mark;
           this.number = number;
       }
       public Card(String fileName) {
           this.fileName = fileName;
           if( !fileName.equals(Constants.BACK_FILE_NAME) && !fileName.equals(Constants.JOKER1_FILE_NAME) && !fileName.equals(Constants.JOKER2_FILE_NAME) ) {
   	        this.mark = fileName.charAt(0);	
   	        this.number = Integer.parseInt(fileName.substring( 1, fileName.indexOf(".") ));
           } else if( fileName.equals(Constants.JOKER1_FILE_NAME) || fileName.equals(Constants.JOKER2_FILE_NAME) ) {
               isJoker = true;
           }
       }
       public char getMark() {
           return mark;
       }
       public int getNumber() {
           return number;
       }
       public String getFileName() {
           return fileName;
       }
       public String getFileName(String str) {
           NumberFormat formatter = new DecimalFormat("00");
           return mark + formatter.format( number ) + ".gif";
       }
       public String toString() {
           return "mark: " + mark + ", number: " + number + ", fileName:" + fileName; 
       }
   }
   // CardPanel.java
   import java.awt.Graphics;
   import java.awt.image.BufferedImage;
   
   import javax.swing.JPanel;
   
   public class CardPanel extends JPanel {
       private BufferedImage img=null;
       public void paint(Graphics g){
           if(img != null){
               g.drawImage(img,0,0,this);
           }
       }
       public void setImage(BufferedImage img){
           this.img = img;
       }
       public BufferedImage getImage() {
           return this.img;
       }
   }
   // Constants.java
   import java.io.File;
   public final class Constants {
       public static final int WINDOW_WIDTH = 640;
       public static final int WINDOW_HEIGHT = 480;
       public static final String IMAGE_DIRECTORY = "./img/";
       public static final String BACK_FILE_NAME = "back.bmp";
       public static final String JOKER1_FILE_NAME = "joker1.bmp";
       public static final String JOKER2_FILE_NAME = "joker2.bmp";
       
       public static final DQPokerHand HANDS_ROYAL_STRAIGHT_FLUSH = new DQPokerHand( "ロイヤルストレートフラッシュ", 500 );
       public static final DQPokerHand HANDS_FIVE_CARDS = new DQPokerHand( "ファイブカード", 100 );
       public static final DQPokerHand HANDS_STRAIGHT_FLUSH =  new DQPokerHand( "ストレートフラッシュ", 50 );
       public static final DQPokerHand HANDS_FOUR_CARDS = new DQPokerHand( "フォーカード", 20 );
       public static final DQPokerHand HANDS_FULL_HOUSE = new DQPokerHand( "フルハウス", 8 );
       public static final DQPokerHand HANDS_FLUSH = new DQPokerHand( "フラッシュ", 5 );        
       public static final DQPokerHand HANDS_STRAIGHT = new DQPokerHand( "ストレート", 4 );
       public static final DQPokerHand HANDS_THREE_CARDS = new DQPokerHand( "スリーカード", 2 );
       public static final DQPokerHand HANDS_TWO_PAIRS = new DQPokerHand( "ツーペア", 1 );
       public static final DQPokerHand HANDS_ONE_PAIR = new DQPokerHand( "ワンペア", 0 );
       public static final DQPokerHand HANDS_NO_PAIRS = new DQPokerHand( "ノーペア", 0 );
       
       public static final File SCORE_SAVE_FILE = new File("score");
   }
written by iys

CONTENTS

最新の20件

2020-11-14 2005-12-06 2006-11-04 2012-07-15 2009-06-19 2011-03-03 2006-12-13 2007-11-05 2014-07-22 2014-07-19 2014-07-09 2014-01-14 2012-09-03 2012-03-28

今日の14件

人気の30件

  • counter: 10186
  • today: 1
  • yesterday: 0
  • online: 1