public class DoudizhuText {
public static void main(String[] args) {
//造牌
String[] number = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
String[] first = {"♠","♥","♦","♣"};
//装牌
ArrayList<String> alpai = new ArrayList<String>();
alpai.add("大王");
alpai.add("小王");
//正常牌
for (String sf :number ) {
for (String sn : first) {
alpai.add(sn.concat(sf));
}
}
// System.out.println(alpai);
//带序号牌
TreeMap<String,Integer> tmpai = new TreeMap<String,Integer>();
for (int i = 0; i < alpai.size(); i++) {
tmpai.put(alpai.get(i),i );
}
//System.out.println(tmpai);
//洗牌
Collections.shuffle(alpai);
//System.out.println(alpai);
//发牌
ArrayList<String> p1 = new ArrayList<String>();
ArrayList<String> p2 = new ArrayList<String>();
ArrayList<String> p3 = new ArrayList<String>();
for(int i = 0; i <alpai.size()-3; i ++)
{
if(i%3 == 0)
{
p1.add(alpai.get(i));
}else if(i%3 == 1){
p2.add(alpai.get(i));
}else{
p3.add(alpai.get(i));
}
}
System.out.print("底牌是:");
for (int i = alpai.size()-3; i < alpai.size() ; i++) {
System.out.print(alpai.get(i)+" ");
}
System.out.println("");
// System.out.println(p1);
// System.out.println(p2);
// System.out.println(p3);
//排序
//p1
TreeMap<Integer, String> tmp1 = new TreeMap<Integer, String>();
for (int i = 0; i < p1.size(); i++) {
String s = p1.get(i);
tmp1.put(tmpai.get(s),s);
}
Collection<String> c1 = tmp1.values();
System.out.print("p1的牌是:");
System.out.println(c1);
//p2
TreeMap<Integer, String> tmp2 = new TreeMap<Integer, String>();
for (int i = 0; i < p2.size(); i++) {
String s = p2.get(i);
tmp2.put(tmpai.get(s),s);
}
Collection<String> c2 = tmp2.values();
System.out.print("p2的牌是:");
System.out.println(c2);
//p3
TreeMap<Integer, String> tmp3 = new TreeMap<Integer, String>();
for (int i = 0; i < p3.size(); i++) {
String s = p3.get(i);
tmp3.put(tmpai.get(s),s);
}
Collection<String> c3 = tmp3.values();
System.out.print("p3的牌是:");
System.out.println(c3);
}
} |
|