<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]);
    }
    }

    }
      回復  更多評論    
    主站蜘蛛池模板: 1000部免费啪啪十八未年禁止观看| 国产精品高清免费网站| 青娱乐免费视频在线观看| 91精品国产亚洲爽啪在线影院| 久久精品中文字幕免费| 亚洲AV无码专区国产乱码电影 | 亚洲妇女无套内射精| 国产成人亚洲综合无码| 国产成人 亚洲欧洲| 免费观看在线禁片| 亚洲AV无码一区二区二三区入口 | av网站免费线看| 亚洲中文字幕无码中文字在线| 中国人免费观看高清在线观看二区| 国产成A人亚洲精V品无码| 久久国产乱子伦精品免费一| 18亚洲男同志videos网站| 99久久精品日本一区二区免费| 亚洲性色AV日韩在线观看| 免费看国产一级片| 中文永久免费观看网站| 18亚洲男同志videos网站| 热99re久久精品精品免费| h片在线观看免费| 久久久无码精品亚洲日韩京东传媒| 久久午夜免费视频| 深夜福利在线免费观看| 亚洲成AV人片在| 成人激情免费视频| 精品人妻系列无码人妻免费视频| 亚洲综合色丁香麻豆| 精品国产免费观看一区| a毛片免费观看完整| 亚洲av无码久久忘忧草| 亚洲精品尤物yw在线影院| 日韩av无码久久精品免费| 亚洲av无码成人精品区一本二本| 久久九九亚洲精品| 蜜桃精品免费久久久久影院| 最近免费字幕中文大全| 亚洲色无码国产精品网站可下载 |