斗地主小游戏之洗牌
package 任务3;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
public class pokerShuffleCards {
public static void main(String[] args) {
ArrayList<String> color = new ArrayList<String>();
color.add("♠");
color.add("♥");
color.add("♦");
color.add("♣");
LinkedList<String> number = new LinkedList<String>();
for (int i = 3; i <= 10; i++) {
number.add(i + "");
}
number.add("J");
number.add("Q");
number.add("K");
number.add("A");
number.add("2");
HashMap<Integer,String> jiehe=new HashMap<Integer,String>();
int index=0;
for(String thisnumber:number) {
for(String thiscolor:color) {
jiehe.put(index++, thiscolor+thisnumber);
}
}
jiehe.put(index++, "大王");
jiehe.put(index++, "小王");
LinkedList<Integer>daluan=new LinkedList<Integer>();
for(int i=0;i<=53;i++) {
daluan.add(i);
}
Collections.shuffle(daluan);
LinkedList<Integer>play=new LinkedList<Integer>();
LinkedList<Integer>play1=new LinkedList<Integer>();
LinkedList<Integer>play2=new LinkedList<Integer>();
LinkedList<Integer>dipai=new LinkedList<Integer>();
for(int i=0;i<daluan.size();i++) {
if(i>=51) {
dipai.add(daluan.get(i));
}else {
if(i%3==0) {
play.add(daluan.get(i));
}else if(i%3==1) {
play1.add(daluan.get(i));
} else{
play2.add(daluan.get(i));
}
}
}
Collections.sort(play);
Collections.sort(play1);
Collections.sort(play2);
LinkedList<String> isplay=new LinkedList<String>();
LinkedList<String> isplay1=new LinkedList<String>();
LinkedList<String> isplay2=new LinkedList<String>();
LinkedList<String> iddipai=new LinkedList<String>();
for (Integer key : dipai) {
iddipai.add(jiehe.get(key));
}
for(Integer key : play1) {
isplay1.add(jiehe.get(key));
}
for(int i=0;i<play2.size();i++) {
isplay2.add(jiehe.get(i));
}
for (Integer key : play) {
isplay.add(jiehe.get(key));
}
System.out.println("玩家1:"+isplay);
System.out.println("玩家2:"+isplay1);
System.out.println("玩家3:"+isplay2);
System.out.println("底牌:"+iddipai);
}
}