qq斗地主主问题?

斗地主洗牌,顺序发牌问题,求大神..........._java吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:279,165贴子:
斗地主洗牌,顺序发牌问题,求大神...........收藏
public class PUKE {static
int [] tags=new int[54];
static String[] cards= {"方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块k","方块A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃","黑桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃k","红桃A","麻花2","麻花3","麻花4","麻花5","麻花6","麻花7","麻花8","麻花9","麻花10","麻花J","麻花Q","麻花k","麻花A","小王","大王"};/***
args*/public static void main(String[] args) {// TODO Auto-generated method stub
int current=1;//当前摸牌人
for(i=0;i&54;i++)
tags[i]=0;for(i=0;i&51;i++){Random rm=new Random();int temp=rm.nextInt(54);
if(tags[temp]!=0){
tags[temp]=current%3+1;
current++;
}}showW(1);showW(2);showW(3);showW(0);}private
static void showW(int w){int i=0;if(w==0)System.out.print("底牌:");elseSystem.out.print("玩家"+w+":");for(i=0;i&54;i++){if(tags[i]==w)System.out.print(cards[i]+" ");}System.out.println();}}这是洗牌发牌, 发的牌是乱的怎么样发完之后 排序显示;求解答,本人新手。
可以把牌定义成一个类,类里面2个成员变量:牌的ID,牌的信息。接下来的排序就简单了吧
新手别做这些东西,,等学了几个月后再做这些东西,,牌肯定是一个类,里面有牌的各种信息,最好能实现Compareable接口比较大小
//调用方法如下。分牌的时候,你可以吧pokers顺序打乱,然后每个人分等量的牌,用数组保存,然后分别对每个人的牌调用排序。再决定地主之后,你把底牌给该人,然后再对该人的牌调用一次排序。//获取所有的牌Poker[] pokers = PokerUtil.getBasePokers();//把牌打乱,你也可以实现自己的算法,这种是最简单的但并不是高效及公平的PokerUtil.randPokers(pokers);//对整副牌排序[仅作参考,你可以类比对单个人的牌排序]Arrays.sort(pokers, Poker.pokerSortDesc);//下边是必须的类。class Poker {static class PokerSort implements Comparator&Poker& {public PokerSort(boolean desc) {this.desc =}public int compare(Poker o1, Poker o2) {if (o1 == null || o2 == null) {if (o1 != null) {return desc ? 1 : -1;}if (o2 != null) {return desc ? -1 : 1;}return 0;}int value = pare(o1.index, o2.index);if (value == 0) {value = pare(o1.type, o2.type);}return desc ? value : -}}public static PokerSort pokerSortAsc = new PokerSort(false);public static PokerSort pokerSortDesc = new PokerSort(true); // 0, 1, 2, ..., 12, 13, 14[13, 14 =& 大王,小王]private S // A, 2, 3, ..., J, Q, K, 小王, 大王// 0 =& 未设置, 1 =& 方片,2 =& 梅花, 3 =& 红桃, 4 =& 黑桃public Poker(int type, String name, int index) {super();this.type =this.name =this.index =}public int getIndex() {}public String getName() {}public int getType() {}public String toString() {return String.format("%2d =& %d
%s", index, type, name);}}class PokerUtil {public static Poker[] getBasePokers() {Poker[] pokers = new Poker[54];String[] names = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10","J", "Q", "K", "小王", "大王" };for (int i = 0; i & 13; i++) {pokers[i] = new Poker(1, names[i], i);pokers[i + 13] = new Poker(2, names[i], i);pokers[i + 26] = new Poker(3, names[i], i);pokers[i + 39] = new Poker(4, names[i], i);}pokers[52] = new Poker(0, names[13], 13);pokers[53] = new Poker(0, names[14], 14);}public static void randPokers(Poker[] pokers) {if (pokers == null || pokers.length & 2) {}int indexA = 0;int indexB = 0;Poker poker =int length = pokers.Random random = new Random();for (int i = 1000; i & 0; i--) {indexA = random.nextInt(length);indexB = random.nextInt(length);poker = pokers[indexA];pokers[indexA] = pokers[indexB];pokers[indexB] =}}}
不明觉厉,顶一个。卤煮你的肥皂掉地上了
马克,大神
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或斗地主一人几张牌?_百度知道
斗地主一人几张牌?
提问者采纳
农民17张地主21张
提问者评价
太给力了,你的回答完美解决了我的问题!
其他类似问题
为您推荐:
斗地主的相关知识
其他2条回答
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁您还未登陆,请登录后操作!
QQ欢乐斗地主问题
欢乐斗地主同一IP不能登陆,怎么设置呢
是腾讯为了防作弊
你要想把你一台机子改出两个IP地址就上不了网啦~
大家还关注QQ斗地主计分有问题啊?_百度知道
QQ斗地主计分有问题啊?
如果不是这个原因://fcm://fcm。。。.com带上身份证号(十八周以上的)去填个防沉迷后就不会了:一定要18周以上的身份证才不会被防不然填了还是会被防的。。就不得更改了。可能是。然后带上图去客服处填单.qq。PS。楼主进入防沉迷了哦。还有一种办法就是.com/cgi-bin/ShowQuestionIndex。http。而且一经绑定后。。防沉迷网址。所以填写的时候要慎重。另外如果你在申请QQ密保的时候有用身份证绑定的话:http。如果用的是18周以下的。要注意哦://service。。记好你游戏的时间.qq。五小时以上就没有分了。。你不要玩三小时以上。只在到该身份证年满18周后才会被免防哦。。。就按原来已经绑定过的号。如果楼主发现自己的积分少了.com/cgi-bin/ShowQuestionIndex
其他类似问题
为您推荐:
qq斗地主的相关知识
其他2条回答
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 斗地主 的文章

 

随机推荐