package fuck;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class fff {
static HashMap<String,Integer> pai;
public static void main(String[] args) {
pai=new HashMap<String,Integer>();
pai(pai);
//System.out.println(pai);
ArrayList<wanjia> wj=newwanjia(2);
ArrayList<String> xipai=new ArrayList<String>(pai.keySet());
xipai = xipai(xipai);
fapai(wj,xipai,2);
gameStart(wj);
}
private static ArrayList<String> xipai(ArrayList<String> xipai) {
// TODO 自动生成的方法存根
String s;
int x;
for(int i=0;i<10000;i++)
{
x=(int)(Math.random()*52);
s=xipai.get(x);
xipai.remove(x);
xipai.add(s);
}
return xipai;
}
private static void gameStart(ArrayList<wanjia> wj) {
int i =0;
String s="";
for(wanjia w:wj)
{
if(i<w.getMaxPai())
{
i=w.getMaxPai();
s=w.name;
}
System.out.println("玩家"+w.name+"最大的牌是"+w.shoupai.get(w.getMaxPai()));
}
System.out.println("最后冠军是玩家"+s);
System.out.println("玩家各自的手牌为");
for(wanjia w:wj)
{
System.out.print("\n玩家"+w.name);
Set<Integer> st=w.shoupai.keySet();
for(int t:st)
{
System.out.print(w.shoupai.get(t)+" ");
}
}
}
public static void pai(HashMap<String,Integer> pai)
{
String[] hs={"方片","梅花","红桃","黑桃"};
for(int i=0;i<4;i++)
{
for(int j=2;j<15;j++)
{
int m=4*(j-2)+i+1;
switch (j) {
case 14:pai.put(hs[i]+"A",m);
break;
case 11:pai.put(hs[i]+"J",m);
break;
case 12:pai.put(hs[i]+"Q",m);
break;
case 13:pai.put(hs[i]+"K",m);
break;
default:pai.put(hs[i]+j,m);
break;
}
}
}
System.out.println("牌组创建完毕");
}
public static ArrayList<wanjia> newwanjia(int n)
{
Scanner inp=new Scanner(System.in);
ArrayList<wanjia> wj=new ArrayList<wanjia>();
for(int t=1;t<=n;t++)
{
System.out.println("请输入第"+t+"位玩家的ID和姓名");
System.out.println("请输入ID");
int i=inp.nextInt();
System.out.println("请输入姓名");
String s=inp.next();
wj.add(new wanjia(i,s));
}
return wj;
}
public static void fapai(ArrayList<wanjia> wj,ArrayList<String> xipai,int n)
{
for(wanjia w:wj)
{
System.out.println("欢迎玩家"+w.name);
} System.out.println("开始发牌");
Iterator<String> it=xipai.iterator();
//System.out.println(xipai);
while(it.hasNext()){
for(wanjia w:wj)
{
System.out.println("玩家"+w.name+"拿牌");
String s=it.next();
w.shoupai.put(pai.get(s),s);
}
n--;
if(n==0)break;
}
System.out.println("发牌结束");
}
}
class wanjia
{
int id;
String name;
TreeMap<Integer,String> shoupai;
wanjia(int id,String name)
{
this.id=id;
this.name=name;
this.shoupai=new TreeMap<Integer,String>();
}
int getMaxPai()
{
return shoupai.lastKey();
}
}