黑马程序员技术交流社区
标题:
斗地主小游戏
[打印本页]
作者:
孙广浩
时间:
2015-11-11 22:37
标题:
斗地主小游戏
package com.heima.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class Test3 {
public static void main(String[] args) {
String[] num = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
String[] color = {"红桃","黑桃","方片","梅花"};
HashMap<Integer, String> hm = new HashMap<>();
ArrayList<Integer> list = new ArrayList<>();
int index = 0;
for(String s1 : num) {
for(String s2 : color) {
hm.put(index, s2.concat(s1));
list.add(index);
index++;
}
}
hm.put(index, "小王");
list.add(index);
index++;
hm.put(index, "大王");
list.add(index);
Collections.shuffle(list);
TreeSet<Integer> zhourunfa = new TreeSet<>();
TreeSet<Integer> zhouxingchi = new TreeSet<>();
TreeSet<Integer> me = new TreeSet<>();
TreeSet<Integer> dipai = new TreeSet<>();
for(int i = 0; i < list.size(); i++) {
if(i >= list.size() - 3) {
dipai.add(list.get(i));
}else if(i % 3 == 0) {
zhourunfa.add(list.get(i));
}else if(i % 3 == 1) {
zhouxingchi.add(list.get(i));
}else {
me.add(list.get(i));
}
}
lookPoker(hm, gaojin, "周润发");
lookPoker(hm, longwu, "周星驰");
lookPoker(hm, me, "我");
lookPoker(hm, dipai, "底牌");
}
public static void lookPoker(HashMap<Integer, String> hm,TreeSet<Integer> ts ,String name) {
System.out.print(name + "的牌是:");
for(Integer i : ts) {
System.out.print(hm.get(i) + " ");
}
System.out.println();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2