黑马程序员技术交流社区
标题:
模拟斗地主洗牌发牌
[打印本页]
作者:
七色★碎羽
时间:
2015-9-11 21:37
标题:
模拟斗地主洗牌发牌
public class DouDiZhu {
public static void main(String[] args) {
HashMap<Integer , String> map=new HashMap<Integer, String>();
ArrayList<Integer> num=new ArrayList<Integer>();
String[] colors={"♥","♠","♣","♦"};
String[] numbers={"3","4","5","6","7","8","9","10","j","q","k","A","2"};
int index=0;
for(String number:numbers){
for(String color:colors){
map.put(index, color+number);
num.add(index);
index++;
}
}
map.put(52, "小王");
num.add(index);
index++;
map.put(53, "大王");
num.add(index);
//System.out.println(map);
Collections.shuffle(num);
TreeSet<Integer> player1=new TreeSet<Integer>();
TreeSet<Integer> player2=new TreeSet<Integer>();
TreeSet <Integer>player3=new TreeSet<Integer>();
TreeSet<Integer> dipai=new TreeSet<Integer>();
for(int x=0;x<num.size();x++){
if( x < 3){
dipai.add(num.get(x));
}else if ( x % 3 == 0){
player1.add( num.get(x));
}else if( x % 3 == 1){
player2.add( num.get(x));
}else{
player3.add( num.get(x));
}
}
look("玩家1",player1,map);
look("玩家2",player2,map);
look("玩家3",player3,map);
look("底牌",dipai,map);
}
public static void look(String name,TreeSet<Integer> set,HashMap<Integer,String>map){
System.out.print(name+"\t");
for(Integer key : set){
System.out.print(map.get(key)+" ");
}
System.out.println();
}
}
作者:
凌端浩
时间:
2015-9-11 23:37
挺好的例子,学习了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2