小手机屏幕的红心大战.rar(JAVA源码-J2EE源码)

源代码在线查看: deck.java

软件大小: 175 K
上传用户: lyyfengyutongzh
关键词: JAVA 源码 EE
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.skybright.pig;
				
				import java.util.Random;
				import java.util.Vector;
				
				
				public class Deck
				{
				    private Card[] cards = null;
				    private Vector v = null;
				
				    public Deck()
				    {
				        cards = new Card[52];
				        v = new Vector();
				
				        for (int i = 0; i < 52; i++)
				        {
				            cards[i] = new Card(i);
				            v.addElement(new Integer(i));
				        }
				    }
				
				    public Card[] getCards()
				    {
				        return cards;
				    }
				
				    public Card getCard()
				    {
				        if (v.size() == 0)
				        {
				            return null;
				        }
				
				        try
				        {
				            Random r = new Random(System.currentTimeMillis());
				            int i = Math.abs(r.nextInt()) % v.size();
				            int index = ((Integer) v.elementAt(i)).intValue();
				            v.removeElementAt(i);
				
				            Card card1 = cards[index];
				
				            return card1;
				        }catch (Exception e)
				        {
				            e.printStackTrace();
				        }
				
				        Card card = null;
				
				        return card;
				    }
				
				    public Card getCard(int index)
				    {
				        return cards[index];
				    }
				
				    public void destroy()
				    {
				        if (cards != null)
				        {
				            cards = null;
				        }
				
				        if (v != null)
				        {
				            v = null;
				        }
				
				        System.gc();
				    }
				}			

相关资源