/***************************** 會考題第三題:梭哈 圖形檔名規則是: 1-13 梅花 1-13 14-26 方塊 1-13 27-39 紅心 1-13 40-52 黑桃 1-13 ********************************/ import javax.swing.*; import java.awt.*; import java.io.*; import java.awt.event.*; import javax.swing.event.*; public class b3ss extends JTest3b implements ActionListener { JButton button1,button2; JFrame frame1; Container c; JPanel pan0,pan1; ImageIcon icon1; JLabel[] label1 = new JLabel[6];//設定放牌與顯示牌型用的label; String result; String[] cardname=new String[52]; int[] pcard = new int[5]; //發到的牌存放的地方; static int point[] = new int[5];//存點數 static int color[] = new int[5];//存花色 static int tempdiff[] = new int[5]; static int temp,tempi,k,l,m; int samekind=1; //同花 int straight=1; //順 public b3ss() //建構元,送入bridge目錄 { int i,j; //把牌初始化 for (i=0;i<=51;i=i+1) { cardname[i]=new String(Integer.toString(i)); } frame1 = new JFrame("梭哈"); c = frame1.getContentPane(); c.setLayout(new GridLayout(2,1)); //panel 0 放按鈕,panel 1放玩家的牌與牌型 pan0 = new JPanel(); pan1 = new JPanel(); for(j=0;j<6;j++) { label1[j] = new JLabel();//先設定沒有牌與牌型 pan1.add(label1[j]); } button1 = new JButton("發牌"); button2 = new JButton("牌型"); button1.addActionListener(this); button2.addActionListener(this); pan0.add(button1); pan0.add(button2); c.add(pan0); //設定關閉視窗,因為不是繼承JFrame,所以必須另外處理 frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setSize(200,200); frame1.show(); //show 出來 } public void actionPerformed(ActionEvent e)//處理按鈕事件 { String poker; if(e.getSource()==button1) //發牌 { shuffle(cardname); //繼承來的發牌方法 for(int j=0;j<5;j++) { //取得牌的數值 pcard[j] = Integer.parseInt(cardname[j]);//每個人發五張牌 //取得牌的圖形,要牌的點數加一 if (pcard[j]<9) poker = new String("bridge/0"+(pcard[j]+1)+".GIF"); else poker =new String("bridge/"+(pcard[j]+1)+".GIF"); icon1 = new ImageIcon(poker); //把牌當icon處理 label1[j].setIcon(icon1); } label1[5].setText("");//清除牌型資料 c.add(pan1);//show 出牌 frame1.pack(); //自動設定大小 frame1.show(); } if(e.getSource()==button2) //計算牌型 { straight=1; //順 samekind=1; //同花 //分別記錄五張牌的花色與點數 for(int j=0;j<5;j++) { color[j] = pcard[j]/13; //花色 point[j] = pcard[j]%13; //點數 } //照點數排序 for( k=0;k<5;k++) { for( l=4;l>k;l--) { if(point[l]