package 模拟斗地主洗牌发牌;
import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeSet;
class Poker implements Comparable
{
String name;
int age;
public Poker(String name,int age)
{
this.name=name;
this.age=age;
}
@Override
public int compareTo(Object o)
{
Poker p=(Poker)o;
if(p.age==this.age)
return p.name.compareTo(this.name);
return p.age-this.age;
}
}
public class Test
{
public static int pos=1;
public static void main(String[] args)
{
ArrayList<Poker> al=new ArrayList<>();
String[] arr={"♥","♠","♣","♦"};
String[] arr1={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
for(String color : arr)
{
int count=1;
for(String num : arr1)
{
Poker p=new Poker((color+num),count++);
al.add(p);
}
}
al.add(new Poker("大王",15));
al.add(new Poker("小王",14));
Collections.shuffle(al);
TreeSet<Poker> ts=new TreeSet<>();
TreeSet<Poker> ts1=new TreeSet<>();
TreeSet<Poker> ts2=new TreeSet<>();
ArrayList<Poker> al4=new ArrayList<>();
for(int i=0;i<al.size();i++)
{
if(i>=al.size()-3)
{
al4.add(al.get(i));
}
else
{
if(i%3==0)
ts.add(al.get(i));
if(i%3==1)
ts1.add(al.get(i));
if(i%3==2)
ts2.add(al.get(i));
}
}
getPoker(ts);
getPoker(ts1);
getPoker(ts2);
System.out.print("底牌: ");
for(Poker p : al4)
{
System.out.print(p.name+" ");
}
}
public static void getPoker(TreeSet<Poker> ts)
{
System.out.print("玩家"+pos+++": ");
for(Poker s : ts)
{
System.out.print(s.name+" ");
}
System.out.println();
System.out.println("---------------------------------------------------------");
}
}
|
|