[java practices] 扑克 洗牌,抽牌

public class Main {

    public static void main(String[] args)
    {
	    Poker p = new Poker();
        p.flush();
        p.getCard(1);
    }
}



public class Card
{
    private int m_values;
    private String m_color;

    public Card(int m_values, String m_color)
    {
        this.m_values = m_values;
        this.m_color = m_color;
    }


    @Override
    public String toString()
    {
        //为了什么写
        String str = null;
        switch (m_values)
        {
            case 1:
            {
                str = "A";
                break;
            }
            case 11:
            {
                str = "J";
                break;
            }
            case 12:
            {
                str = "Q";
                break;
            }
            case 13:
            {
                str = "K";
                break;
            }
            default:
                str = String.valueOf(m_values);

        }
        return str + m_color ;
    }
}




public class Poker
{
    private Card[] poker = null;
    private int[] value = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    private String[] color = {"♡", "♠", "♢", "♧"};

    public Poker()
    {
        poker = new Card[52];
        for (int i = 0; i < value.length; i++)
            for (int j = 0; j < color.length; j++)
            {
                poker[i * color.length + j] = new Card(value[i], color[j]);
            }
    }

    public void out()
    {

        for (int n = 0; n < poker.length; n++)
        {
            System.out.println(poker[n]+"  "+n);
        }

    }

    public void flush()
    {
        for(int x = 0 ; x <100;x++)
        {
            int a = (int) (Math.random() * 52);
            int b = (int) (Math.random() * 52);
            Card temp = null;
            temp = poker[a];
            poker[a] = poker[b];
            poker[b] = temp;
        }
    }

    public void getCard(int v)
    {
        int arr[] = new int[v];
        for(int i =0;i<v;i++)
        {
            arr[i] = (int)(Math.random()*51);
            for(int n =0; n<i ;n++)
            {
                if (arr[i]==arr[n])
                {
                    arr[i] = (int)(Math.random()*51);
                }
            }
        }
        for(int i =0;i<v;i++)
        {
            System.out.println(poker[arr[i]]);
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值