package cn.Set_20210818.HomeWork_20210818;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Cards {
Player[] player = new Player[3];
public void xiCard(){
Scanner input = new Scanner(System.in);
for (int i = 0; i < player.length; i++) {
System.out.println("请输入第"+(i+1)+"位玩家的姓名:");
player[i] = new Player(input.next());
}
List<String> Card = new ArrayList<>();
String[] card = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
String[] color = {"♠","♥","♣","♦"};
for (String cards : card) {
for (String colors : color) {
Card.add(colors + cards);
}
}
Card.add("大王");
Card.add("小王");
Collections.shuffle(Card);
for (int i = 0; i < Card.size()-3; i=i+3) {
player[0].getList().add(Card.get(i));
player[1].getList().add(Card.get(i+1));
player[2].getList().add(Card.get(i+2));
}
ArrayList<String> diPai = new ArrayList<>();
System.out.println("随机产生地主!");
int diZhu;
diZhu = (int)(Math.random()*3);
System.out.println("恭喜"+player[diZhu].name+"成为地主!获得三张底牌!");
for (int i = 51; i < 54; i++) {
player[diZhu].getList().add(Card.get(i));
diPai.add(Card.get(i));
}
System.out.println(player[0].getList());
System.out.println(player[1].getList());
System.out.println(player[2].getList());
System.out.println("地主的底牌为:"+diPai);
}
public static void main(String[] args) {
Cards cards = new Cards();
cards.xiCard();
}
}
-----------------------------------------------------------------------------------------
package cn.Set_20210818.HomeWork_20210818;
import java.util.ArrayList;
public class Player {
public String name;
ArrayList<String> list = new ArrayList<>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<String> getList() {
return list;
}
public void setList(ArrayList<String> list) {
this.list = list;
}
public Player() {
}
public Player(String name) {
this.name = name;
}
}