小手机屏幕的红心大战.rar(JAVA源码-J2EE源码)
源代码在线查看: deck.java
- 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();
- }
- }
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();
}
}