package day0816;
import java.util.ArrayList;
import java.util.Collections;
/**
* @author 王旭阳
*/
public class Fight {
public static void main(String[] args) {
//构建扑克牌
//大王 小王 完成
//其他牌 定义两个数组
//一个存放四种牌 一个存放牌数
String[] types = {"♣","♥","♦","♠"};
String[] brand = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
//创建存放扑克的集合
ArrayList<String> pai = new ArrayList<>();
//放入大王 小王
pai.add("大王");
pai.add("小王");
//使用for循环和add()方法传入值
for (String type : types) {
for (String s : brand) {
pai.add(type+s);
}
}
System.out.println(pai);
//创建三个用户 和 一个底牌
ArrayList<String> a = new ArrayList<>();
ArrayList<String> b = new ArrayList<>();
ArrayList<String> c = new ArrayList<>();
ArrayList<String> d = new ArrayList<>();
//洗牌
/*
static void shuffle(List<?> list)
使用默认随机源对指定列表进行置换。
*/
Collections.shuffle(pai);
//放入数据
/*
条件:
1.当牌数大于51张时放入底牌中
2.牌数%3
*/
for (int i = 0; i < pai.size(); i++) {
if (i>50){
d.add(pai.get(i));
}else if (i%3 == 0){
a.add(pai.get(i));
}else if (i%3 == 1){
b.add(pai.get(i));
}else if (i%3 == 2){
c.add(pai.get(i));
}
}
System.out.println("我"+a);
System.out.println("你"+b);
System.out.println("他"+c);
System.out.println("底牌"+d);
}
// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
// 0 1 2 3 4 5 6 7 8 9 10 11 12
// 1 1 1 1 1 1 1 1 1
/*
[大王, 小王, ♣A, ♣2, ♣3, ♣4, ♣5, ♣6, ♣7, ♣8, ♣9, ♣10, ♣J, ♣Q, ♣K, ♥A, ♥2, ♥3, ♥4, ♥5, ♥6, ♥7, ♥8, ♥9, ♥10, ♥J, ♥Q, ♥K, ♦A, ♦2, ♦3, ♦4, ♦5, ♦6, ♦7, ♦8, ♦9, ♦10, ♦J, ♦Q, ♦K, ♠A, ♠2, ♠3, ♠4, ♠5, ♠6, ♠7, ♠8, ♠9, ♠10, ♠J, ♠Q, ♠K]
我[♠J, ♣2, ♦A, ♦2, ♠Q, ♥J, ♠5, 小王, ♥7, ♥8, ♥A, ♦9, ♠6, ♣7, ♥3, ♠10, ♦10]
你[♣Q, ♠A, ♥4, ♠9, ♠8, ♥5, ♥K, ♦4, ♣K, ♣8, ♠K, ♦K, ♠3, ♣3, ♦Q, ♣6, ♦7]
他[♦8, ♣9, ♦5, ♠7, ♥2, ♣4, ♦J, ♣10, ♥Q, ♣5, ♣J, ♠2, 大王, ♦3, ♥6, ♦6, ♥10]
底牌[♣A, ♠4, ♥9]
*/
}
斗地主案例
最新推荐文章于 2021-08-31 18:46:16 发布