package Liuks;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class 炸金花 {
public static void main(String[] args) {
String sz[] = new String[]{"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
List<String> l = new ArrayList<>();
String dl[] = new String[52];
l.add("红桃");
l.add("黑桃");
l.add("方片");
l.add("梅花");
System.out.println("买牌");
String s = "";int count = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
s = l.get(i) + sz[j];
dl[count] = s;
count++;
System.out.print(s + " ");
if(j == 12){
System.out.println();
}
}
}
//洗牌
System.out.println("洗牌");
Random r = new Random();
String s1 = "";int a = 0;
for (int i = 0; i < 52; i++) {
a = r.nextInt(52);
s = dl[a];
dl[a] = dl[1];
dl[1] = s;
}
for (int i = 0; i < 52; i++) {
System.out.print(dl[i] + " ");
if((i+1) % 13 == 0){
System.out.println();
}
}
//发牌
System.out.println("发牌");
List<String> l1 = new ArrayList<>();
List<String> l2 = new ArrayList<>();
List<String> l3 = new ArrayList<>();
for (int i = 0; i < 15; i++) {
if (i % 3 == 0){
l1.add(dl[i]);
} else if (i % 3 == 1) {
l2.add(dl[i]);
} else if (i % 3 == 2) {
l3.add(dl[i]);
}
}
System.out.print("第一个人的牌:");
for (int i = 0; i < l1.size(); i++) {
System.out.print(l1.get(i) + " ");
}
System.out.println();
System.out.print("第二个人的牌:");
for (int i = 0; i < l2.size(); i++) {
System.out.print(l2.get(i) + " ");
}
System.out.println();
System.out.print("第三个人的牌:");
for (int i = 0; i < l3.size(); i++) {
System.out.print(l3.get(i) + " ");
}
}
}
炸金花代码
最新推荐文章于 2024-08-14 21:03:52 发布