该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
初学见谅。。目前能洗牌,发牌,发牌后的排序。但是用的方法很蠢。以下是代码。
package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class test {
public static void main(String[] args) {
// 创建string存放牌
String[] paixing = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2" };
// 创建STRING存放花色
String[] huase = { "黑桃", "红桃", "梅花", "方块", };
// 用集合创建一副牌
List pai = new ArrayList<>();
// 在集合中添加牌
for (int i = 0; i < paixing.length; i++) {
for (int j = 0; j < huase.length; j++) {
pai.add(huase[j] + paixing[i]);
}
}
pai.add("大王");
pai.add("小王");
// 洗牌
Collections.shuffle(pai);
// 创建3个玩家和底牌的集合
List gamer1 = new ArrayList();
List gamer2 = new ArrayList();
List gamer3 = new ArrayList();
List dipai = new ArrayList();
// 发牌
for (int i = 0; i < pai.size(); i++) {
if (i < 3) {
dipai.add(pai.get(i));
}
// 如果牌摸3等于1就给玩家1
else if (i % 3 == 1) {
gamer1.add(pai.get(i));
} else if (i % 3 == 2) {
gamer2.add(pai.get(i));
} else {
gamer3.add(pai.get(i));
}
}
System.out.println("玩家1的牌:" + gamer1);
System.out.println("玩家2的牌:" + gamer2);
System.out.println("玩家3的牌:" + gamer3);
System.out.println("底牌:" + dipai);
bidaxiao bidaxiao=new bidaxiao();
gamer1=bidaxiao.bidaxiao(gamer1);
System.out.println("TEMP"+gamer1);
}
}
package test;
import java.util.ArrayList;
import java.util.List;
public class bidaxiao {
public bidaxiao() {
}
public List bidaxiao(List s) {
List temp = new ArrayList();
// 取出10以内的牌
for (int i = 0; i < 8; i++) {
// 取出红桃牌
if (s.indexOf("红桃" + (i + 3)) != -1) {
temp.add(s.get(s.indexOf("红桃" + (i + 3))));
s.remove(s.indexOf("红桃" + (i + 3)));
} // 取出黑桃牌
if (s.indexOf("黑桃" + (i + 3)) != -1) {
temp.add(s.get(s.indexOf("黑桃" + (i + 3))));
} // 取出梅花牌
if (s.indexOf("梅花" + (i + 3)) != -1) {
temp.add(s.get(s.indexOf("梅花" + (i + 3))));
s.remove(s.indexOf("梅花" + (i + 3)));
} // 取出方块牌
if (s.indexOf("方块" + (i + 3)) != -1) {
temp.add(s.get(s.indexOf("方块" + (i + 3))));
s.remove(s.indexOf("方块" + (i + 3)));
}
}
// 取出10以上的牌
for (int i = 0; i < 8; i++) {
if (s.indexOf("红桃J") != -1) {
temp.add(s.get(s.indexOf("红桃J")));
s.remove(s.indexOf("红桃J"));
}
if (s.indexOf("黑桃J") != -1) {
temp.add(s.get(s.indexOf("黑桃J")));
s.remove(s.indexOf("黑桃J"));
}
if (s.indexOf("梅花J") != -1) {
temp.add(s.get(s.indexOf("梅花J")));
s.remove(s.indexOf("梅花J"));
}
if (s.indexOf("方块J") != -1) {
temp.add(s.get(s.indexOf("方块J")));
s.remove(s.indexOf("方块J"));
}if (s.indexOf("红桃Q") != -1) {
temp.add(s.get(s.indexOf("红桃Q")));
s.remove(s.indexOf("红桃Q"));
}
if (s.indexOf("黑桃Q") != -1) {
temp.add(s.get(s.indexOf("黑桃Q")));
s.remove(s.indexOf("黑桃Q"));
}
if (s.indexOf("梅花Q") != -1) {
temp.add(s.get(s.indexOf("梅花Q")));
s.remove(s.indexOf("梅花Q"));
}
if (s.indexOf("方块Q") != -1) {
temp.add(s.get(s.indexOf("方块Q")));
s.remove(s.indexOf("方块Q"));
}if (s.indexOf("红桃K") != -1) {
temp.add(s.get(s.indexOf("红桃K")));
s.remove(s.indexOf("红桃K"));
}
if (s.indexOf("黑桃K") != -1) {
temp.add(s.get(s.indexOf("黑桃K")));
s.remove(s.indexOf("黑桃K"));
}
if (s.indexOf("梅花K") != -1) {
temp.add(s.get(s.indexOf("梅花K")));
s.remove(s.indexOf("梅花K"));
}
if (s.indexOf("方块K") != -1) {
temp.add(s.get(s.indexOf("方块K")));
s.remove(s.indexOf("方块K"));
}if (s.indexOf("红桃A") != -1) {
temp.add(s.get(s.indexOf("红桃A")));
s.remove(s.indexOf("红桃A"));
}
if (s.indexOf("黑桃A") != -1) {
temp.add(s.get(s.indexOf("黑桃A")));
s.remove(s.indexOf("黑桃A"));
}
if (s.indexOf("梅花A") != -1) {
temp.add(s.get(s.indexOf("梅花A")));
s.remove(s.indexOf("梅花A"));
}
if (s.indexOf("方块A") != -1) {
temp.add(s.get(s.indexOf("方块A")));
s.remove(s.indexOf("方块A"));
}if (s.indexOf("红桃2") != -1) {
temp.add(s.get(s.indexOf("红桃2")));
s.remove(s.indexOf("红桃2"));
}
if (s.indexOf("黑桃2") != -1) {
temp.add(s.get(s.indexOf("黑桃2")));
s.remove(s.indexOf("黑桃2"));
}
if (s.indexOf("梅花2") != -1) {
temp.add(s.get(s.indexOf("梅花2")));
s.remove(s.indexOf("梅花2"));
}
if (s.indexOf("方块2") != -1) {
temp.add(s.get(s.indexOf("方块2")));
s.remove(s.indexOf("方块2"));
}if (s.indexOf("小王") != -1) {
temp.add(s.get(s.indexOf("小王")));
s.remove(s.indexOf("小王"));
}if (s.indexOf("大王") != -1) {
temp.add(s.get(s.indexOf("大王")));
s.remove(s.indexOf("大王"));
}
}
System.out.println("temp"+temp);
return temp;
}
}