java中扑克牌排序_用了一个很蠢的办法进行扑克牌排序,求大神指导好的方法。...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

初学见谅。。目前能洗牌,发牌,发牌后的排序。但是用的方法很蠢。以下是代码。

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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值