扑克牌类:
public class Card {
private String suit;
private String point;
private int num;
public Card(String suit, String point, int num) {
super();
this.suit = suit;
this.point = point;
this.num = num;
}
public Card(String point, int num) {
super();
this.point = point;
this.num = num;
}
public Card() {
super();
}
public String getSuit() {
return suit;
}
public void setSuit(String suit) {
this.suit = suit;
}
public String getPoint() {
return point;
}
public void setPoint(String point) {
this.point = point;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
@Override
public String toString() {
if(suit == null) {
return point;
}else {
return suit + "" + point;
}
}
}
import java.util.ArrayList;
import java.util.Random;
public class Test {
static ArrayList<Card> org = new ArrayList<>();
static ArrayList<Card> list1 = new ArrayList<>();
static ArrayList<Card> list2 = new ArrayList<>();
static ArrayList<Card> list3 = new ArrayList<>();
static int count = 0;
static Random r = new Random();
public static void cards() {
String p = "JQKA2";
String[] su = {"黑桃", "红桃", "梅花", "方块"};
int j;
for(int t = 0; t < 4; t++) {
j = 0;
for (int i = 3; i < 10; i++,j++) {
String s = "";
char c = (char) ('0' + i);
s += c;
org.add(new Card(su[t], s, j));
}
org.add(new Card(su[t], "10", j));
j++;
for (int i = 0; i < p.length(); i++,j++) {
String s = "";
char c = p.charAt(i);
s += c;
org.add(new Card(su[t], s, j));
}
}
}
public static void input(ArrayList<Card> list) {
int cardIndex = r.nextInt(org.size());
Card card = org.get(cardIndex);
list.add(card);
count++;
org.remove(card);
}
public static int f(boolean b) {
if(b) {
return 20;
}else {
return 17;
}
}
public static void main(String[] args) {
Player p1 = new Player(1, "A", false);
Player p2 = new Player(2, "B", false);
Player p3 = new Player(3, "C", false);
int k = r.nextInt(3);
switch(k) {
case 0: p1.setLandlord(true);break;
case 1: p2.setLandlord(true);break;
case 2: p3.setLandlord(true);break;
default : break;
}
cards();
org.add(new Card("小王",13));
org.add(new Card("大王",14));
System.out.println(org);
while(count < f(p1.isLandlord())) {
input(list1);
}
count = 0;
while(count < f(p2.isLandlord())) {
input(list2);
}
count = 0;
while(count < f(p3.isLandlord())) {
input(list3);
}
p1.setList(list1);
System.out.println(p1);
p2.setList(list2);
System.out.println(p2);
p3.setList(list3);
System.out.println(p3);
}
}