斗地主游戏的简单实现
public class GameDemo {
/**
1、定义一个静态的集合存储54张牌对象
*/
public static List<Card> allCards = new ArrayList<>();
/**
2、做牌:定义静态代码块初始化牌数据
*/
static {
// 3、定义点数:个数确定,类型确定,使用数组
String[] sizes = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
// 4、定义花色:个数确定,类型确定,使用数组
String[] colors = {"♠", "♥", "♣", "♦"};
int index=0;
// 5、组合点数和花色
for (String size : sizes) {
index++;
for (String color : colors) {
// 6、封装成一个牌对象。
Card c = new Card(size, color,index);
// 7、存入到集合容器中去
allCards.add(c);
}
}
// 8 大小王存入到集合对象中去 "