<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    數據加載中……
    今天終于完成了洗牌程序.不過可能有點亂!
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class puke extends JApplet
    {
    ?JFrame f=new JFrame();
    ?Container y=getContentPane();
    ?JButton wash=new JButton("洗牌");
    ??JButton post=new JButton("發牌");
    ?JLabel first=new JLabel("The first is:");
    ?JLabel second=new JLabel("The second is:");
    ?JLabel third=new JLabel("The third is:");
    ?JLabel fourth=new JLabel("The fourth is:");
    ?public void init()
    ?{??
    ??y.setLayout(new GridLayout(3,2));
    ??y.add(wash);
    ??y.add(post);
    ??y.add(first);
    ??y.add(second);
    ??y.add(third);
    ??y.add(fourth);
    ??wash.addActionListener(new WashActionAdapter());
    ??post.addActionListener(new PostActionAdapter());??????
    ?}
    //---------------------------------------------------------------
    ?? class MyThread extends Thread
    ?? {
    ?? ?public void run()
    ?? ?{
    ?? ??Stack save=new Stack();
    ?? ??Vector MyVector=new Vector(1,1);
    ????String[] wpkp={"紅桃","黑桃","方片","草花"};
    ????? Random i=new Random();
    ?? ???? int a,j;
    ?? ???? a=4;
    ????try
    ????{
    ???????? while(a!=0)
    ???{
    ? ???j=i.nextInt(4);
    ???? if(wpkp[j]!="NULL")
    ????? {
    ????? ?save.push(wpkp[j]);
    ??? ???? wpkp[j]="NULL";
    ???? ?? a-=1;
    ???? }
    ???? else continue;
    ????}
    ???? while(!save.empty())??????
    ???????? ?MyVector.addElement(save.pop());
    ???????? ?for(int ii=0;ii<MyVector.capacity();ii++)
    ???????? ?{
    ???????? ??switch(ii%5)
    ?????{
    ??????case 0:first.setText("The first is:"+MyVector.get(ii).toString());break;
    ??????case 1:second.setText("The second is:"+MyVector.get(ii).toString());break;
    ??????case 2:third.setText("The third is:"+MyVector.get(ii).toString());break;
    ??????case 3:fourth.setText("The fourth is:"+MyVector.get(ii).toString());break;
    ?????}
    ?????}
    ????}
    ????catch(Exception ee)
    ????{
    ????}
    ?? ??}
    ?? ?}
    //----------------------------------------------------------------
    ??class WashActionAdapter implements ActionListener
    ??{
    //?? Stack save=new Stack();
    ??????
    ?????
    ??
    ???public? void actionPerformed(ActionEvent e)
    ???{
    ??????????? first.setText("The first is:");
    ??????second.setText("The second is:");
    ??????third.setText("The third is:");
    ??????fourth.setText("The fourth is:");????
    ????}
    ???}
    //-------------------------------------------------------------------------------------
    ???class PostActionAdapter implements ActionListener
    ???{
    ????public? void actionPerformed(ActionEvent e)
    ????{
    ?????String cmd=e.getActionCommand();
    ?????String title="Message Dialog";
    ?????String message="";
    ?????int type;
    ?????if(first.getText().equals("The first is:"))
    ?????{
    ??????Thread t=new MyThread();
    ??????? t.start();
    ??????}
    ?????else
    ?????{
    ??????type=JOptionPane.PLAIN_MESSAGE;
    ??????message="請先洗牌";
    ?????JOptionPane.showMessageDialog(f,message,title,type);
    ??????}
    ????
    ???? }
    ???}
    //---------------------------------------------------------------------------------------???
    }





    自己感覺有點亂,大家有好的方法可以告訴我,精誠合作,金石為開

    posted on 2006-04-01 16:50 牛浪de流 閱讀(535) 評論(1)  編輯  收藏 所屬分類: 爪哇學習

    評論

    # re: 今天終于完成了洗牌程序.不過可能有點亂![未登錄] 2007-10-23 21:13 zc

    package Poker.Game;

    class Card {

    private String face;
    private String suit;
    public Card(String suit, String face)
    {
    this.face = face;
    this.suit = suit;
    }
    protected String getFace()
    {
    return face;
    }
    protected String getSuit()
    {
    return suit;
    }
    public String toString()
    {
    return suit+" "+face;
    }

    public static void shuffle(Card[] deck,int startIndex,int size, int splitIndex)
    {
    if (splitIndex * 2 > size)
    {
    Card.swap(deck,startIndex,splitIndex,size-splitIndex);
    shuffle(deck,size-splitIndex,splitIndex,size-splitIndex);
    }
    else if (splitIndex * 2 < size)
    {
    Card.swap(deck,startIndex,size-splitIndex,splitIndex);
    shuffle(deck,startIndex,size-splitIndex,splitIndex);
    }
    else
    {
    Card.swap(deck,startIndex,splitIndex,splitIndex);
    }

    }
    public static void swap(Card[] deck,int srcIndex,int dstIndex, int size)
    {
    String face = "";
    String suit = "";
    for (int i=0; i<size;i++)
    {
    face = deck[srcIndex+i].face;
    suit = deck[srcIndex+i].suit;
    deck[srcIndex+i].face = deck[dstIndex+i].face;
    deck[srcIndex+i].suit = deck[dstIndex+i].suit;
    deck[dstIndex+i].face = face;
    deck[dstIndex+i].suit = suit;
    }
    }
    /**
    * @param args
    */
    public static void main(String[] args) {
    Card[] deck = new Card[52];
    String f[] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
    String s[] ={ "黑桃", "紅桃", "梅花", "方塊" };
    for(int i=0; i<s.length; i++)
    {
    for(int j=0; j<f.length; j++)
    {
    deck[i*13+j] = new Card(s[i],f[j]);
    }
    }
    int rnd = 0;
    int numOfShuffle = 10;
    for (int i=0; i<numOfShuffle; i++)
    {
    rnd = (int) Math.abs(Math.random()*52);
    Card.shuffle(deck,0,deck.length,rnd);
    }
    // Test
    for (int i=0; i<deck.length; i++)
    {
    System.out.println(deck[i]);
    }
    }

    }
      回復  更多評論    
    主站蜘蛛池模板: 亚洲性无码一区二区三区| 亚洲国产另类久久久精品小说| 久久亚洲私人国产精品| 中文字幕免费视频精品一| 亚洲日产韩国一二三四区| 久久久久女教师免费一区| 国产精品亚洲一区二区三区在线| 岛国岛国免费V片在线观看| 一本色道久久综合亚洲精品| jzzjzz免费观看大片免费| 亚洲免费视频一区二区三区| 一区二区免费在线观看| 丝袜熟女国偷自产中文字幕亚洲| a毛片成人免费全部播放| 亚洲av永久无码精品国产精品| 国产精品免费看久久久 | 亚洲熟妇无码一区二区三区| 成人A级毛片免费观看AV网站| 在线aⅴ亚洲中文字幕| 国产jizzjizz免费视频| A级毛片成人网站免费看| 久久久久亚洲av无码专区蜜芽| 亚欧免费一级毛片| 亚洲国产日韩视频观看| 日本牲交大片免费观看| 黄色网页在线免费观看| 亚洲精品天天影视综合网| 亚洲综合精品一二三区在线| 国产成人免费高清激情明星| 亚洲国产成人无码AV在线影院| 亚洲精品国精品久久99热| 99爱视频99爱在线观看免费| 亚洲日本久久久午夜精品| 亚洲第一福利网站在线观看| 午夜影院免费观看| 亚洲AV日韩AV一区二区三曲 | 日本人的色道免费网站| 美女无遮挡免费视频网站| 亚洲国产精品一区二区第一页 | 亚洲av女电影网| 免费理论片51人人看电影|