package doudizhu;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import _Collections.Person;
/*
- 创建牌
- 洗牌
- 发牌
- 看牌
- 叫地主
- 再次看牌
*/
public class Play_doudizhu {
public static void main(String[] args) {
//创建一组牌 54张
ArrayList puke = new ArrayList<>();
puke.add(“大王”);
puke.add(“小王”);
String[] huase = {“♥”,“♠”,“♣”,“♦”};
String[] shuzi = {“2”,“A”,“K”,“Q”,“J”,“10”,“9”,“8”,“7”,“6”,“5”,“4”,“3”};
for(String hs :huase) {
for(String sz : shuzi ) {
puke.add(hs+sz);
}
}
//检查牌组 System.out.println(puke);
//洗牌
Collections.shuffle((List<?>) puke);
//检查洗牌后的牌组 System.out.println(puke);
//发牌
ArrayList dipai = new ArrayList<>();
ArrayList<String> player01 = new ArrayList<>();
ArrayList<String> player02 = new ArrayList<>();
ArrayList<String> player03 = new ArrayList<>();
for(int i =0;i<puke.size();i++) {
String pai = puke.get(i);
if(i>=51) {//留三张底牌
dipai.add(pai);
}else if(i%3 ==0) {
player01.add(pai);//给一号玩家发牌
}else if (i%3 ==1) {
player02.add(pai);//给二号玩家发牌
}else {
player03.add(pai);//给三号玩家发牌
}
}//发牌结束
//三位玩家看牌
player01.sort(null);
player02.sort(null);
player03.sort(null);
System.out.println(player01);
System.out.println(player02);
System.out.println(player03);
//叫地主阶段
Scanner sc = new Scanner(System.in);
System.out.println("player01开始叫地主,请输入:0(不叫)/1/2/3");
int jiaofen = sc.nextInt();
if(jiaofen == 0||jiaofen ==1||jiaofen==2) {
System.out.println("因为player01叫了"+jiaofen+"分,所以");
System.out.println("请player02叫地主,请输入:0/1/2/3");
int jiaofen_1 = sc.nextInt();
int jiaofensum = jiaofen+ jiaofen_1;
//想要添加叫分积分大于6那么本家自动成为地主的功能,位置不对,程序运行出现bug 搁置
//if(jiaofensum <6) {
if(jiaofen_1 == 0||jiaofen_1 ==1||jiaofen_1==2) {
System.out.println("因为player02叫了"+jiaofen_1+"分,所以");
System.out.println("请player03叫地主,请输入:0/1/2/3");
int jiaofen_2 = sc.nextInt();
jiaofensum =jiaofensum+ jiaofen_2;
//想要添加叫分积分大于6那么本家自动成为地主的功能,位置不对,程序运行出现bug 搁置
//if(jiaofensum<6) {
if(jiaofen_2 == 0||jiaofen_2 ==1||jiaofen_2==2) {
System.out.println("player03叫了"+jiaofen_2+"分");
}else {
System.out.println("player03成为地主");
for(int k=0;k<dipai.size();k++) {
player01.add((String) dipai.get(k));
}
}
}else {
System.out.println("player02成为地主");
for(int k=0;k<dipai.size();k++) {
player01.add((String) dipai.get(k));
}
}
}else {
System.out.println("player01成为地主");
for(int k=0;k<dipai.size();k++) {
player01.add((String) dipai.get(k));
}
}
/* //想要添加叫分积分大于6那么本家自动成为地主的功能,位置不对,程序运行出现bug 搁置
//代码如下 以及上方两个if
}else {
System.out.println("因为jiaofensum>6,所以player03成为地主");
for(int k=0;k<dipai.size();k++) {
player01.add((String) dipai.get(k));
}
}
}else {
System.out.println("因为jiaofensum>6,所以player02成为地主");
for(int k=0;k<dipai.size();k++) {
player01.add((String) dipai.get(k));
}
*/
System.out.println("===========================");
System.out.println(“再次看牌”);
player01.sort(null);
player02.sort(null);
player03.sort(null);
System.out.println(player01);
System.out.println(player02);
System.out.println(player03);
}
}