标签:简单斗地主
/* * 一副扑克 * 洗牌 * 发牌 *看牌 */ public static void fightLandlord(){ //一副扑克 String[] num={"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; String[] color={"梅花","红桃","方片","黑桃"}; HashMap<Integer, String> hm=new HashMap<Integer, String>(); //存储索引和扑克 ArrayList<Integer> list=new ArrayList<Integer>(); //存储索引 int index=0; for(String n:num){ for(String c:color){ String p=c.concat(n); hm.put(index, p); list.add(index); index++; } } list.add(index); hm.put(index, "小王"); index++; list.add(index); hm.put(index, "大王"); //洗牌 Collections.shuffle(list); TreeSet<Integer> landlord=new TreeSet<Integer>(); TreeSet<Integer> peasant1=new TreeSet<Integer>(); TreeSet<Integer> peasant2=new TreeSet<Integer>(); TreeSet<Integer> extra=new TreeSet<Integer>(); //发牌 for(int i=0;i<list.size();i++){ if(i>=list.size()-3){ extra.add(list.get(i)); }else if(i % 3 ==0){ landlord.add(list.get(i)); }else if(i%3==1){ peasant1.add(list.get(i)); }else{ peasant2.add(list.get(i)); } } //看牌 seePoker(hm,landlord,"地主"); seePoker(hm,peasant1,"农民1"); seePoker(hm,peasant2,"农民2"); seePoker(hm,extra,"底牌"); } public static void seePoker(HashMap<Integer, String> hm,TreeSet<Integer> p,String name){ System.out.print(name+"的牌是:"); for(Integer i:p){ System.out.print(hm.get(i)+" "); } System.out.println(); }
本文出自 “穆枫” 博客,请务必保留此出处http://mufeng219.blog.51cto.com/12764296/1943447
标签:简单斗地主
原文地址:http://mufeng219.blog.51cto.com/12764296/1943447