本帖最后由 王国平 于 2015-12-9 23:12 编辑
- <blockquote>public class GamoDemo {
复制代码 public class GamoDemo {
/**
* @param args
*
*
* 0 1 2 3 4 5 6 7 8 9 10
* * * * *
*/
public static void main(String[] args) {
HashMap<Integer,String> hm = new HashMap<>();//创建牌盒
//创造牌
String[] colors = {"♠","♦","♣","♥"};
String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
ArrayList<Integer> list = new ArrayList<>();
int index = 0;
for (String num : numbers) {
for(String col : colors) {
String pai = col.concat(num);
hm.put(index, pai);
list.add(index);
index++;
}
}
hm.put(index, "小王");
list.add(index++);
hm.put(index, "大王");
list.add(index);
//打印,查看是否缺牌
for (Integer integer : list) {
System.out.print(hm.get(integer)+" ");
}
System.out.println();
Collections.shuffle(list);//洗牌
//查看洗牌后的效果
for (Integer integer : list) {
System.out.print(hm.get(integer)+" ");
}
System.out.println();
//创建玩家
TreeSet<Integer> keno = new TreeSet<>();
TreeSet<Integer> apple = new TreeSet<>();
TreeSet<Integer> sun = new TreeSet<>();
TreeSet<Integer> dipai = new TreeSet<>();
/*
* 0 1 2 3 4 5 6 7 8 9 10
* * * * *
*
* */
for(int i = 0 ; i < list.size() ; i ++) {
if(i >= list.size() - 3) {
dipai.add(list.get(i));
}else if(i % 3 == 0 ) {
System.out.println("第一个人拿到第 "+i +" 张");
keno.add(list.get(i));
}else if((i+2) % 3 == 0) {
apple.add(list.get(i));
System.out.println("第二个人拿到第 "+i +" 张");
}else if((i+1) % 3 == 0){
sun.add(list.get(i));
System.out.println("第三个人拿到第 "+i +" 张");
}
}
//检测是否有作弊,不能拿到相同的牌
print(keno);
System.out.println("--------------------");
print(apple);
System.out.println("--------------------");
print(sun);
System.out.println("--------------------");
print(dipai);
System.out.println("--------------------");
//看牌
lookPoker("Keno",keno,hm);
lookPoker("apple",apple,hm);
lookPoker("sun",sun,hm);
lookPoker("底牌",dipai,hm);
}
public static void lookPoker(String name, TreeSet<Integer> ts,HashMap<Integer,String> hm){
System.out.println(name+" 在看牌 :");
for (Integer integer : ts) {
System.out.print(hm.get(integer)+" ");
}
System.out.println();
}
public static void print(TreeSet<Integer> ts ) {
for (Integer integer : ts) {
System.out.print(integer+" ");
}
System.out.println();
}
}
|
|