import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map; public class DouDiZhu {
public static Integer[] index = new Integer[54];
private static Map<Integer, String> allCard = new HashMap<Integer, String>(); public static void main(String[] args) {
initMap(allCard);//1.) 初始化卡牌
List<Integer> list = Arrays.asList(initIndex(index));
Collections.shuffle(list);//2.)洗牌
//3.)发牌
List<Integer> player1 = list.subList(0, 17);
List<Integer> player2 = list.subList(17, 34);
List<Integer> player3 = list.subList(34, 51);
List<Integer> dipai = list.subList(51, 54);
//4.)按大小排序
Collections.sort(player1);
Collections.sort(player2);
Collections.sort(player3);
Collections.sort(dipai);
System.out.print("玩家1:");
for (Integer i :player1){
System.out.print(allCard.get(i));
}
System.out.println();
System.out.print("玩家2:");
for (Integer i :player2){
System.out.print(allCard.get(i));
}
System.out.println();
System.out.print("玩家3:");
for (Integer i :player3){
System.out.print(allCard.get(i));
}
System.out.println();
System.out.print("底牌 :");
for (Integer i :dipai){
System.out.print(allCard.get(i));
} }
// 初始化卡牌数量
public static Integer[] initIndex(Integer[] index) {
for (int i = 1; i < 55; i++) {
index[i - 1] = i;
}
return index;
}
//将卡牌按大小以及花色(黑红梅方)添加到map
public static void initMap(Map<Integer, String> map) {
String[] num = { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6",
"5", "4", "3" };
String[] color = { "♠","♥","♦","♣"};
map.put(1, "|BK|");
map.put(2, "|SK|");
int k = 3;
for (int i = 0; i < num.length; i++) {
for (int j = 0; j < color.length; j++) {
map.put(k, color[j] + num[i]);
k++;
}
}
}
}
运行结果:

Java模拟斗地主(实现大小排序)的更多相关文章

  1. java 模拟斗地主发牌洗牌

    一 模拟斗地主洗牌发牌 1.案例需求 按照斗地主的规则,完成洗牌发牌的动作. 具体规则: 1. 组装54张扑克牌 2. 将54张牌顺序打乱 3. 三个玩家参与游戏,三人交替摸牌,每人17张牌,最后三张 ...

  2. Java 模拟斗地主

    模拟斗地主 public class M1 { public static void main(String args[]) { DouDiZhu02(); } private static void ...

  3. java字符串数组进行大小排序

    若是将两个字符串直接比较大小,会包:The operator > is undefined for the argument type(s) java.lang.String, java.lan ...

  4. java模拟斗地主发牌看牌

    import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; public class Dou ...

  5. Java模拟斗地主发牌和洗牌

    package cn.itcast_04; import java.util.ArrayList; import java.util.Collections; import java.util.Has ...

  6. Java基础知识强化之集合框架笔记71:模拟斗地主洗牌和发牌并对牌进行排序的案例

    1. 模拟斗地主洗牌和发牌并对牌进行排序的原理图解: 2. 代码实现: 思路: • 创建一个HashMap集合 • 创建一个ArrayList集合 • 创建花色数组和点数数组 • 从0开始往HashM ...

  7. Java基础知识强化之集合框架笔记70:模拟斗地主洗牌和发牌(ArrayList)

    1. 模拟斗地主洗牌和发牌 分析:     A:创建一个牌盒     B:装牌     C:洗牌     D:发牌     E:看牌 2. 代码实现: package cn.itcast_03; im ...

  8. Java 二维数组,排序、切换顺序,查表法二进制十进制,这班查找、排序(冒泡、选择)、遍历,获取最大小值(4)

    Java 二维数组,排序.切换顺序,查表法二进制十进制,折半查找.排序(冒泡.选择).遍历,获取最大小值(4)

  9. 通过Java实现斗地主

    功能:洗牌,发牌,对玩家手中的牌排序,看牌 package demo06; import java.util.ArrayList; import java.util.Collections; impo ...

随机推荐

  1. 详解nginx.conf文件配置项(包括负载均衡)

    http://www.cnblogs.com/hsapphire/archive/2010/04/08/1707109.html #运行用户 user  nobody nobody; #启动进程 wo ...

  2. (转)Spring提供的CharacterEncoding和OpenSessionInView功能

    http://blog.csdn.net/yerenyuan_pku/article/details/52902282 前面我们以一种更加优雅的方式集成了Spring4.2.5+Hibernate4. ...

  3. Types of Security Vulnerabilities

    1)内存空间安全.2)参量级别数据安全:3)通信级别数据安全:4)数据访问控制:5)通信对象身份确认. https://developer.apple.com/library/content/docu ...

  4. VBA Promming入门教程——变量的使用

    数据类型 VBA中的数据类型可分为两种 示例 String Sub Main Dim s as string s = "Hello" msgbox(s) End Sub Singl ...

  5. zabbix 报警通知选项配置

    {TRIGGER.STATUS} host: {HOSTNAME} IP: {HOST.IP} events_time:{EVENT.DATE} {EVENT.TIME} notice_time:{D ...

  6. stay hungry stay foolish.

    I am honored to be with you today at your commencement from one of the finest universities in the wo ...

  7. QT+ 状态栏+核心控件+浮动窗口

    #include "mainwindow.h" #include <QStatusBar> #include <QLabel> #include<QT ...

  8. 《3+1团队》【Alpha】Scrum meeting 5

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 3+1团队 团队博客地址 https://home.cnblogs.com/u/3-1group ...

  9. Python打包成exe,pyc

    D:\mypython\path\ C:\Python27\Scripts\pyinstaller.exe -w mypython.py # Python打包成exe D:\mypython\path ...

  10. Oracle中的for和while循环

    实例: beginfor i in 51..500 loop delete from test t where t.date=to_date('2016-07-01', 'yyyy-MM-dd') a ...