扑克牌小程序--联系Collection

public class Poker {
List<String> list = new ArrayList<>();

//准备牌
public void read() {
List<String> num = new ArrayList<>();
List<String> color = new ArrayList<>();
for (int i = 2; i <= 10; i++) {
num.add(i + "");
}
num.add("A");
num.add("J");
num.add("Q");
num.add("K");
color.add("♥");
color.add("♣");
color.add("♠");
color.add("♦");
for (String n : num) {
for (String c : color) {
list.add(n + c);
}
}
list.add("大王");
list.add("小王");


}


//洗牌
public void shuffle() {
Collections.shuffle(list);
}

//发牌
List<String> play1 = new ArrayList<>();
List<String> play2 = new ArrayList<>();
List<String> play3 = new ArrayList<>();
List<String> dipai = new ArrayList<>();

public void rLicensing() {

for (int i = 3; i < list.size(); i++) {
String p = list.get(i);
if (i % 3 == 0) {
play1.add(p);
} else if (i % 3 == 1) {
play2.add(p);
} else {
play3.add(p);
}
}
dipai.add(list.get(0));
dipai.add(list.get(1));
dipai.add(list.get(2));
}

//看牌
public void show() {
System.out.println("play1:" + play1);
System.out.println("play2:" + play2);
System.out.println("play3:" + play3);
System.out.println("底牌:" + dipai);
}
}

//测试类
public class PokerTest {
public static void main(String[] args) {
Poker a=new Poker();
a.read();
a.shuffle();
a.rLicensing();
a.show();
}
}
posted @ 2021-11-26 16:36  hrhnp  阅读(270)  评论(0)    收藏  举报