四人斗地主java程序
- 格式:doc
- 大小:120.50 KB
- 文档页数:39
JAVA代码之⽃地主发牌理解很好理解,关键是思路按照⽃地主的规则,完成洗牌发牌的动作: 具体规则:1. 组装54张扑克牌 2. 将54张牌顺序打乱3. 三个玩家参与游戏,三⼈交替摸牌,每⼈17张牌,最后三张留作底牌。
4. 查看三⼈各⾃⼿中的牌(按照牌的⼤⼩排序)、底牌⼿中扑克牌从⼤到⼩的摆放顺序:⼤王,⼩王,2,A,K,Q,J,10,9,8,7,6,5,4,3package com.oracle.demo01;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Map;public class Doudizhu {public static void main(String[] args) {//1.创建扑克牌MapMap<Integer,String> pooker=new HashMap<Integer,String>();//创建所有key所在的容器ArrayList<Integer> pookerNum=new ArrayList<Integer>();//创建花⾊数组String[] color={"♠","♣","♥","♦"};//创建牌号数组String[] number={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};//造牌并存进map集合int index=2;for(String n:number){for(String c:color){//向map中存数据pooker.put(index,c+n);//向所有key所在的容器存数据pookerNum.add(index);index++;}}//存⼤⼩王pooker.put(0, "⼤王");pookerNum.add(0);pooker.put(1, "⼩王");pookerNum.add(1);//洗牌Collections.shuffle(pookerNum);//System.out.println(pookerNum);//发牌//创建四个容器ArrayList<Integer> bottom=new ArrayList<>();ArrayList<Integer> player1=new ArrayList<>();ArrayList<Integer> player2=new ArrayList<>();ArrayList<Integer> player3=new ArrayList<>();//开始发牌for(int i=0;i<pookerNum.size();i++){//将前三张给底牌if(i<3){bottom.add(pookerNum.get(i));}else if(i%3==0){player1.add(pookerNum.get(i));}else if(i%3==1){player2.add(pookerNum.get(i));}else if(i%3==2){player3.add(pookerNum.get(i));}}//排序(key升序牌从⼤到⼩)Collections.sort(bottom);Collections.sort(player1);Collections.sort(player2);Collections.sort(player3);//看牌(调⽤⽅法)look("刘德华",player1,pooker);look("张家辉",player2,pooker);look("周润发",player3,pooker);look("底牌",bottom,pooker);}//看牌的⽅法(传参为玩家姓名,玩家的牌即键,所有牌的键值对)public static void look( String name,ArrayList<Integer> player,Map<Integer,String> pooker){ //打印玩家姓名System.out.print(name+":");//遍历所有牌号for(int num:player){System.out.print(pooker.get(num)+" ");}System.out.println();}}。
java⽃地主游戏项⽬源码部分代码如下Main.javapackage com;import java.awt.Color;import java.awt.Container;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.List;import java.util.Random;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.SwingUtilities;public class Main extends JFrame implements ActionListener {public Container container = null;// 定义容器JMenuItem start, exit, about;// 定义菜单按钮JButton landlord[]=new JButton[2];//抢地主按钮JButton publishCard[]=new JButton[2];//出牌按钮int dizhuFlag;//地主标志int turn;JLabel dizhu; //地主图标List<Card> currentList[] =new ArrayList[3]; // 当前的出牌List<Card> playerList[] = new ArrayList[3]; // 定义3个玩家表List<Card> lordList;//地主牌Card card[] = new Card[56]; // 定义54张牌JTextField time[]=new JTextField[3]; //计时器Time t; //定时器(线程)boolean nextPlayer=false; //转换⾓⾊public Main(){Init();// 初始化SetMenu();// 创建菜单按钮(抢地主,发牌,计时器)this.setVisible(true);CardInit();//发牌getLord(); //发完牌开始抢地主time[1].setVisible(true);//线程安全性,把⾮主线程的UI控制放到⾥⾯SwingUtilities.invokeLater(new NewTimer(this,10));}// 抢地主public void getLord(){//System.out.println(CardType.c0.toString());for(int i=0;i<2;i++)landlord[i].setVisible(true);}//初始化牌// 发牌洗牌public void CardInit() {int count = 1;//初始化牌for (int i = 1; i <= 5; i++) {for (int j = 1; j <= 13; j++) {if ((i == 5) && (j > 2))break;else {card[count] = new Card(this, i + "-" + j, false);card[count].setLocation(350, 50);container.add(card[count]);count++;}}}//打乱顺序for(int i=0;i<100;i++){Random random=new Random();int a=random.nextInt(54)+1;int b=random.nextInt(54)+1;Card k=card[a];card[a]=card[b];card[b]=k;}//开始发牌for(int i=0;i<3;i++)playerList[i]=new ArrayList<Card>(); //玩家牌lordList=new ArrayList<Card>();//地主牌三张int t=0;for(int i=1;i<=54;i++){if(i>=52)//地主牌{Common.move(card[i], card[i].getLocation(),new Point(300+(i-52)*80,10)); lordList.add(card[i]);continue;}switch ((t++)%3) {case0://左边玩家Common.move(card[i], card[i].getLocation(),new Point(50,60+i*5));playerList[0].add(card[i]);break;case1://我Common.move(card[i], card[i].getLocation(),new Point(180+i*7,450));playerList[1].add(card[i]);card[i].turnFront(); //显⽰正⾯break;case2://右边玩家Common.move(card[i], card[i].getLocation(),new Point(700,60+i*5));playerList[2].add(card[i]);break;}//card[i].turnFront(); //显⽰正⾯container.setComponentZOrder(card[i], 0);}//发完牌排序,从⼤到⼩for(int i=0;i<3;i++){Common.order(playerList[i]);Common.rePosition(this,playerList[i],i);//重新定位}dizhu=new JLabel(new ImageIcon("images/dizhu.gif"));dizhu.setVisible(false);dizhu.setSize(40, 40);container.add(dizhu);}// 初始化窗体public void Init() {this.setTitle("java单机⽃地主");this.setSize(830, 620);setResizable(false);setLocationRelativeTo(getOwner()); // 屏幕居中container = this.getContentPane();container.setLayout(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);container.setBackground(new Color(0, 112, 26)); // 背景为绿⾊}// 创建菜单功能按钮public void SetMenu() {JMenuBar jMenuBar = new JMenuBar();JMenu game = new JMenu("游戏");JMenu help = new JMenu("帮助");start = new JMenuItem("新游戏");exit = new JMenuItem("退出");about = new JMenuItem("关于");start.addActionListener(this);exit.addActionListener(this);about.addActionListener(this);game.add(start);game.add(exit);help.add(about);jMenuBar.add(game);jMenuBar.add(help);this.setJMenuBar(jMenuBar);landlord[0]=new JButton("抢地主");landlord[1]=new JButton("不抢");publishCard[0]= new JButton("出牌");publishCard[1]= new JButton("不要");for(int i=0;i<2;i++){publishCard[i].setBounds(320+i*100, 400, 60, 20);landlord[i].setBounds(320+i*100, 400,75,20);container.add(landlord[i]);landlord[i].addActionListener(this);landlord[i].setVisible(false);container.add(publishCard[i]);publishCard[i].setVisible(false);publishCard[i].addActionListener(this);}for(int i=0;i<3;i++){time[i]=new JTextField("倒计时:");time[i].setVisible(false);container.add(time[i]);}time[0].setBounds(140, 230, 60, 20);time[1].setBounds(374, 360, 60, 20);time[2].setBounds(620, 230, 60, 20);for(int i=0;i<3;i++){currentList[i]=new ArrayList<Card>();}}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource() == exit) {this.dispose();}if (e.getSource() == about) {JOptionPane.showMessageDialog(this, "哈哈");}if (e.getSource() == start) {// this.restart();}if(e.getSource()==landlord[0]){time[1].setText("抢地主");t.isRun=false; //时钟终结}if(e.getSource()==landlord[1]){time[1].setText("不抢");t.isRun=false; //时钟终结}//如果是不要if(e.getSource()==publishCard[1]){this.nextPlayer=true;currentList[1].clear();time[1].setText("不要");}//如果是出牌按钮if(e.getSource()==publishCard[0]){List<Card> c=new ArrayList<Card>();//点选出牌for(int i=0;i<playerList[1].size();i++){Card card=playerList[1].get(i);if(card.clicked){c.add(card);}}int flag=0;//如果我主动出牌if(time[0].getText().equals("不要")&&time[2].getText().equals("不要")) {if(Common.jugdeType(c)!=CardType.c0)flag=1;//表⽰可以出牌}//如果我跟牌else{flag=Common.checkCards(c,currentList);}//判断是否符合出牌if(flag==1){currentList[1]=c;playerList[1].removeAll(currentList[1]);//移除⾛的牌 //定位出牌Point point=new Point();point.x=(770/2)-(currentList[1].size()+1)*15/2;;point.y=300;for(int i=0,len=currentList[1].size();i<len;i++){Card card=currentList[1].get(i);Common.move(card, card.getLocation(), point); point.x+=15;}//抽完牌后重新整理牌Common.rePosition(this, playerList[1], 1);time[1].setVisible(false);this.nextPlayer=true;}}}public static void main(String args[]) {new Main();}}class NewTimer implements Runnable{Main main;int i;public NewTimer(Main m,int i){this.main=m;this.i=i;}@Overridepublic void run() {// TODO Auto-generated method stubmain.t=new Time(main,10);//从10开始倒计时main.t.start();}}效果图<ignore_js_op><ignore_js_op><ignore_js_op><ignore_js_op>详细说明:。
java实现⽃地主发牌功能本⽂实例为⼤家分享了java实现⽃地主发牌的具体代码,供⼤家参考,具体内容如下参考⽃地主的游戏规则,完成⼀个发牌的功能(54张牌,考虑点数,花⾊;三名玩家,其中地主⽐其他玩家多3张牌)代码如下:牌类import java.util.Objects;/*** 3-10 J Q K A 2 King Queen 牌类** @author Administrator**/public class Card {/** 牌⾯值 */private String name;/** 花⾊ */private String flower;/** ⼤⼩点数 */private int num;public Card() {super();}public Card(String name, String flower, int num) {super(); = name;this.flower = flower;this.num = num;}public String getName() {return name;}public void setName(String name) { = name;}public String getFlower() {return flower;}public void setFlower(String flower) {this.flower = flower;}public int getNum() {return num;}public void setNum(int num) {this.num = num;}@Overridepublic String toString() {if(Objects.nonNull(flower)) {return name + "-" + flower;}return name;}}玩家类public class Player {/**玩家ID*/private int id;/**玩家姓名*/private String name;/**是否是地主*/private boolean boss;/**牌集合*/private ArrayList<Card> cards = new ArrayList<Card>();public Player(int id, String name, boolean boss, ArrayList<Card> cards) {super();this.id = id; = name;this.boss = boss;this.cards = cards;}public Player() {super();}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) { = name;}public boolean isBoss() {return boss;}public void setBoss(boolean boss) {this.boss = boss;}public ArrayList<Card> getCards() {return cards;}public void setCards(ArrayList<Card> cards) {this.cards = cards;}@Overridepublic String toString() {return name +(boss? "(地主):":"(农名):")+ cards;}}管理类public class GameManage {private static Random randomGen = new Random();/** 声明所有牌的集合 */private static ArrayList<Card> all = new ArrayList<Card>();/** ⽤于⽣成牌的牌⾯值 */private static String[] names = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "⼩王","⼤王" }; /** ⽤于⽣成牌的花⾊ */private static String[] flowers = { "红桃", "⽅块", "梅花", "⿊桃" };private ArrayList<Player> players = new ArrayList<Player>();static {int i = 0;for (; i < names.length - 2; i++) {for (int j = 0; j < flowers.length; j++) {Card c = new Card(names[i], flowers[j], i);all.add(c);}}// 将⼤⼩王加⼊all.add(new Card(names[names.length - 2], null, i++)); all.add(new Card(names[names.length - 1], null, i++)); }/*** 加⼊玩家*/private void addPlayer() {Scanner sc = new Scanner(System.in);System.out.println("请输⼊玩家1名称:");String name1 = sc.nextLine();System.out.println("请输⼊玩家2名称:");String name2 = sc.nextLine();System.out.println("请输⼊玩家3名称:");String name3 = sc.nextLine();Player p1 = new Player();p1.setId(1);p1.setName(name1);Player p2 = new Player();p1.setId(2);p2.setName(name2);Player p3 = new Player();p1.setId(3);p3.setName(name3);// 将三名玩家加⼊集合players.add(p1);players.add(p2);players.add(p3);}/*** 随机地主*/private void randomBoss() {// 添加玩家addPlayer();// 随机地主索引int i = randomGen.nextInt(players.size());// 设置指定位置的玩家为地主players.get(i).setBoss(true);}public ArrayList<Player> sendCard() {randomBoss();// 对每⼀名玩家遍历for (Player p : players) {// 先为每⼀位玩家随机发17张牌for (int i = 0; i < 17; i++) {// 随机⼀张牌的索引int cardIndex = randomGen.nextInt(all.size());// 获取随机索引位置的牌Card card = all.get(cardIndex);// 将随机的牌加⼊当前遍历玩家的集合p.getCards().add(card);// 从源集合中移除这张牌all.remove(card);}}// 最后三张牌给地主for (Player p : players) {if (p.isBoss()) {// 将all集合中的所有元素加⼊地主的集合p.getCards().addAll(all);}}return players;}}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
Java集合案例之⽃地主游戏本⽂实例为⼤家分享了Java集合案例之⽃地主游戏的具体代码,供⼤家参考,具体内容如下题⽬要求:通过⾃制54张扑克牌,发给3⼈,留下3张底牌,分别显⽰不同⼈的⼿牌与底牌达到⽃地主的游戏需求算法思想:1、4种花⾊,每种13张牌,使⽤for嵌套循环,产⽣52张牌再加⼊⼤⼩王创建牌与花⾊:String[] hs = {"♠", "♥", "♣", "♦"};String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};2、为了⽅便表⽰与操作每⼀张牌,可以⽤1--54的数字代替54种牌,通过此思路:可以使⽤HashMap类,使得牌与数字⼀⼀对应。
Map<Integer, String> pokers = new HashMap<>(); //双列表实现数字与牌相对应List<Integer> list = new ArrayList<>(); //单表存数字int n = 0;//⽤来计算3、考虑当分到牌后使其排列⽅便,可在设置数字对应时,进⾏特殊操作:使得花⾊作为内循环,数字作为内循环这样:在显⽰牌⾯时,更符合⽤户需求for (String s : number) {for (String h : hs) {String poker = h + s; //组合得到52张牌num++; //计数pokers.put(num, poker); //双列表,实现⼤⼩与数组对应list.add(num); //单列表,⽅便操作}}注:通过增强for循环来进⾏遍历num++;pokers.put(num, "⼩王"); //添加⼩王list.add(num);num++;pokers.put(num, "⼤王"); //添加⼤王list.add(num);4、调⽤Collections.shuffle(list)⽅法,使单列表打乱顺序,使⽤ int i 进⾏遍历,留下最后三张作为底牌,再将剩余的51张牌分给三⼈。
斗地主洗牌课课程设计JAVA一、教学目标本课程旨在通过斗地主洗牌程序的设计与实现,让学生掌握JAVA编程的基本语法、流程控制、数组和面向对象编程等知识,培养学生解决实际问题的能力,提高学生的编程兴趣和信息素养。
具体目标如下:1.理解JAVA编程语言的基本语法。
2.掌握JAVA中的流程控制语句,包括条件语句、循环语句等。
3.熟悉JAVA数组的使用方法。
4.理解面向对象编程的基本概念,包括类、对象、封装、继承等。
5.能够运用JAVA编程语言编写简单的程序。
6.能够运用面向对象编程思想设计和实现程序。
7.能够分析问题,编写解决问题的JAVA程序。
情感态度价值观目标:1.培养学生对编程的兴趣,提高信息素养。
2.培养学生团队合作、自主学习的能力。
3.培养学生面对问题,解决问题的决心和毅力。
二、教学内容本课程的教学内容主要包括JAVA编程语言的基本语法、流程控制、数组和面向对象编程等。
1.JAVA基本语法:JAVA的数据类型、变量、运算符、方法等。
2.流程控制:条件语句、循环语句等。
3.数组:一维数组、多维数组的使用和操作。
4.面向对象编程:类、对象、封装、继承等。
三、教学方法本课程采用讲授法、案例分析法、实验法等教学方法,以激发学生的学习兴趣和主动性。
1.讲授法:用于讲解JAVA的基本语法、流程控制、数组和面向对象编程等理论知识。
2.案例分析法:通过分析实际案例,让学生理解和掌握JAVA编程的方法。
3.实验法:通过编写和运行JAVA程序,让学生实践和巩固所学知识。
四、教学资源本课程的教学资源包括教材、多媒体资料和实验设备等。
1.教材:选用《JAVA编程思想》等权威教材,为学生提供系统的学习资料。
2.多媒体资料:制作课件、演示视频等,丰富教学手段,提高学生的学习兴趣。
3.实验设备:为学生提供电脑、网络等实验环境,方便学生进行编程实践。
五、教学评估本课程的教学评估主要包括平时表现、作业和考试三个部分,以全面、客观、公正地评估学生的学习成果。
java课程设计斗地主一、教学目标本章节的教学目标旨在让学生掌握Java编程基础,能够运用Java编写简单的斗地主游戏。
具体目标如下:1.理解Java编程语言的基本语法和结构。
2.掌握面向对象编程的思想,了解类、对象、继承、多态等概念。
3.学习Java集合框架,了解List、Set、Map等接口及其实现类。
4.熟悉Java异常处理机制。
5.能够使用Java开发工具,如Eclipse、IntelliJ IDEA等。
6.能够编写简单的Java程序,实现输入输出、数据计算等功能。
7.能够运用Java编写斗地主游戏的界面和逻辑。
情感态度价值观目标:1.培养学生的编程兴趣,提高学生主动学习的积极性。
2.培养学生团队协作的能力,学会与他人共同解决问题。
3.培养学生勇于创新的精神,敢于挑战自己。
二、教学内容本章节的教学内容主要包括以下几个部分:1.Java编程基础:介绍Java语言的基本语法、数据类型、运算符、控制结构等。
2.面向对象编程:讲解类、对象、继承、多态等概念,并通过实例让学生理解并掌握这些概念。
3.Java集合框架:学习List、Set、Map等接口及其实现类,了解常用的数据结构及其应用场景。
4.异常处理:介绍Java异常处理机制,让学生学会处理程序中可能出现的错误和异常。
5.斗地主游戏开发:引导学生运用所学知识,编写斗地主游戏的界面和逻辑。
三、教学方法本章节的教学方法采用讲授法、案例分析法和实验法相结合的方式,具体如下:1.讲授法:教师讲解Java编程基础、面向对象编程、集合框架、异常处理等内容,引导学生理解并掌握相关概念。
2.案例分析法:通过分析具体的斗地主游戏案例,让学生将所学知识运用到实际项目中,提高学生的编程能力。
3.实验法:安排实验室实践环节,让学生动手编写斗地主游戏,培养学生的实际操作能力。
四、教学资源本章节的教学资源包括以下几部分:1.教材:《Java编程基础》等相关教材,为学生提供理论知识的学习依据。
java斗地主小游戏课程设计一、课程目标知识目标:1. 让学生掌握Java语言的基本语法和编程结构;2. 让学生了解斗地主游戏的规则和逻辑;3. 让学生学会运用面向对象编程思想设计游戏类和对象;4. 让学生掌握数组、集合、异常处理等在游戏编程中的应用。
技能目标:1. 培养学生运用Java语言编写简单游戏的能力;2. 培养学生分析问题、解决问题的能力;3. 培养学生团队协作和沟通表达能力;4. 提高学生的逻辑思维和编程实践能力。
情感态度价值观目标:1. 激发学生对编程和游戏的兴趣,培养其探索精神;2. 培养学生面对挑战和困难时保持积极的态度,勇于尝试和改进;3. 引导学生正确认识游戏,合理安排学习和娱乐时间,形成良好的生活习惯;4. 培养学生的合作精神,使其懂得分享和互助。
课程性质:本课程为实践性较强的Java编程课程,以斗地主小游戏为载体,结合面向对象编程思想,培养学生的编程能力和逻辑思维能力。
学生特点:学生已具备一定的Java语言基础,对游戏有较高的兴趣,但编程实践经验和团队协作能力有待提高。
教学要求:注重理论与实践相结合,引导学生主动探究和解决问题,强调团队协作和沟通表达能力的培养。
将课程目标分解为具体的学习成果,以便于教学设计和评估。
二、教学内容1. Java基础语法复习:变量、数据类型、运算符、控制结构等;2. 面向对象编程:类与对象、构造方法、继承与多态、接口等;3. 游戏规则与逻辑:斗地主游戏规则介绍、牌类设计、出牌逻辑、计分系统等;4. 编程实践:- 牌类设计与实现:Card类、Poker类;- 游戏界面设计:命令行界面设计、用户交互;- 游戏逻辑实现:发牌、出牌、跟牌、提示等功能;- 异常处理:输入异常、游戏逻辑异常处理;- 游戏测试与优化:测试用例设计、性能优化。
5. 团队协作与沟通:项目分组、任务分配、进度跟踪、成果展示。
教学内容安排与进度:第一周:Java基础语法复习、面向对象编程;第二周:斗地主游戏规则介绍、牌类设计与实现;第三周:游戏界面设计、游戏逻辑实现(发牌、出牌);第四周:游戏逻辑实现(跟牌、提示)、异常处理;第五周:游戏测试与优化、团队协作与沟通。
斗地主洗牌发牌【案例介绍】1.任务描述扑克牌游戏“斗地主”,相信许多人都会玩,本案例要求编写一个斗地主的洗牌发牌程序,要求按照斗地主的规则完成洗牌发牌的过程。
一副扑克总共有54张牌,牌面由花色和数字组成(包括J、Q、K、A字母)组成,花色有♠、♥、♦、♣ 四种,分别表示黑桃、红桃、方块、梅花,小☺、大☻分别表示小王和大王。
斗地主游戏共有3位玩家参与,首先将这54张牌的顺序打乱每人轮流摸一次牌,剩余3张留作底牌,然后在控制台打印3位玩家的牌和3张底牌。
2.运行结果任务运行结果如图6-1所示:图6-1 运行结果图【任务介绍】●学会分析“斗地主之洗牌发牌”任务的实现思路。
●根据思路独立完成“斗地主之洗牌发牌”任务的源代码编写、编译及运行。
●掌握List集合和Map集合特点及常用方法的使用。
●掌握集合遍历的方式。
【实现思路】(1)要实现纸牌程序,首先需要完成纸牌的组装。
牌面是由花色(包括♠、♥、♦、♣花色)和数字(包括J、Q、K、A字母)两部分组成,可以创建两个ArrayList集合作为花色集合与数字集合,存储时需要注意。
比10大的牌的数字用J、Q、K表示,1用A表示。
(2)将花色集合与数字集合这两个循环进行嵌套循环,将花色与数字组合,形成52章牌,并赋予其编号。
将组合后的牌存放到一个HashMap集合中,集合的Key值是编号,value值是组装完成的纸牌。
还有两张牌是大小王(小☺表示小王、大☻表示大王)。
由于组装规则不一致,需单独使用add()方法将这两张牌加入到HashMap集合中。
(3)创建一个数字集合,用这个数字集合代替纸牌完成洗牌和发牌操作。
由于纸牌的数量是54张,所以创建集合范围是0~53。
(4)可以使用Collection类的shuffle()方法完成打乱数字集合的操作,实现洗牌效果。
由于只有3个人,所以可以使用for循环,通过将数字与3取余的方法,将代表不同纸牌的数字分配给不同人与底牌,实现发牌效果。
package poker;/*** <p>Title: 斗地主</p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2004</p>* <p>Company: </p>* author 艳生* version 1.0*/import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.util.*;public class CallPokerDialog extends JDialog{JButton btnOne = new JButton();JButton btnTwo = new JButton();JButton btnThree = new JButton();JButton btnFour = new JButton();int score = PokerKernal.score;public CallPokerDialog() {try {jbInit();}catch(Exception e) {e.printStackTrace();}}private void jbInit() throws Exception {this.setSize(new Dimension(330, 80));//居中显示Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation((screenSize.width - 330)/2,(screenSize.height - 80)/2);this.setModal(true);this.setResizable(false);this.setTitle("请叫牌");if(score==1){btnOne.setBackground(Color.pink);}else if(score==2){btnOne.setBackground(Color.pink);btnTwo.setBackground(Color.pink);}btnOne.setBounds(new Rectangle(11, 16, 67, 25));btnOne.setText("1分");btnOne.addActionListener(newCallPokerDialog_btnOne_actionAdapter(this));this.getContentPane().setLayout(null);btnTwo.setBounds(new Rectangle(82, 17, 73, 25));btnTwo.setText("2分");btnTwo.addActionListener(newCallPokerDialog_btnTwo_actionAdapter(this));btnThree.setBounds(new Rectangle(161, 17, 73, 25));btnThree.setText("3分");btnThree.addActionListener(newCallPokerDialog_btnThree_actionAdapter(this));btnFour.setBounds(new Rectangle(240, 16, 73, 25));btnFour.setSelected(false);btnFour.setText("不要");btnFour.addActionListener(newCallPokerDialog_btnFour_actionAdapter(this));this.getContentPane().add(btnOne, null);this.getContentPane().add(btnTwo, null);this.getContentPane().add(btnThree, null);this.getContentPane().add(btnFour, null);}void btnOne_actionPerformed(ActionEvent e) {if(score<1){PokerKernal.score = 1;PokerKernal.two.call = 1;this.dispose();}}void btnTwo_actionPerformed(ActionEvent e) {if(score<2){PokerKernal.two.call = 2;PokerKernal.score = 2;this.dispose();}}void btnThree_actionPerformed(ActionEvent e) {if(score<3){PokerKernal.two.call = 3;PokerKernal.score = 3;this.dispose();}}void btnFour_actionPerformed(ActionEvent e) {this.dispose();}}class CallPokerDialog_btnOne_actionAdapter implements java.awt.event.ActionListener {CallPokerDialog adaptee;CallPokerDialog_btnOne_actionAdapter(CallPokerDialog adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.btnOne_actionPerformed(e);}}class CallPokerDialog_btnTwo_actionAdapter implements java.awt.event.ActionListener {CallPokerDialog adaptee;CallPokerDialog_btnTwo_actionAdapter(CallPokerDialog adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.btnTwo_actionPerformed(e);}}class CallPokerDialog_btnThree_actionAdapter implements java.awt.event.ActionListener {CallPokerDialog adaptee;CallPokerDialog_btnThree_actionAdapter(CallPokerDialog adaptee) {this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.btnThree_actionPerformed(e);}}class CallPokerDialog_btnFour_actionAdapter implements java.awt.event.ActionListener {CallPokerDialog adaptee;CallPokerDialog_btnFour_actionAdapter(CallPokerDialog adaptee) { this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {adaptee.btnFour_actionPerformed(e);}}package poker;/*** <p>Title: 斗地主</p>* <p>Description: 牌类</p>* <p>Copyright: Copyright (c) 2004</p>* <p>Company: </p>* author 艳生* version 1.0*/import java.awt.*;import java.awt.image.*;public class Card {//牌名称private String name;//牌点数private int dot;//牌图片private Image img;public Card() {name = "";dot = 0;img = null;}public Card(String name, int dot, Image img) { = name;this.dot = dot;this.img = img;}public int getDot() {return dot;}public Image getImg() {return img;}public String getName() {return name;}public void setName(String name) { = name;}public void setImg(Image img) { this.img = img;}public void setDot(int dot) { this.dot = dot;}}package poker;/*** <p>Title: 斗地主</p>* <p>Description: 牌操作</p>* <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p>* author 艳生* version 1.0*/import java.awt.*;import java.awt.Graphics2D;import java.util.*;import java.awt.event.*;import javax.swing.*;import .URL;import .URLClassLoader;public class CardOperation {//所有牌对象集public static Vector cards = new Vector();public CardOperation() {}/**加载扑克图片*/public static void loadCards(Component cmp){//s--黑桃(spade) h--红桃(hearts) c--梅花(club) d--方块(diamond)String name[] = {"s","h","c","d"};String dot[] = {"3","4","5","6","7","8","9","10","j","q","k","a","2"};//权值int power[] = {3,4,5,6,7,8,9,10,11,12,13,14,15};URLClassLoader urlLoader = (URLClassLoader)cmp.getClass().getClassLoader();URL fileLoc = null;Card card = null;//先读52牌for(int i=0; i<4;i++){for(int j=0;j<13;j++){fileLoc = urlLoader.findResource("cards/"+name[i]+dot[j]+".jpg");card = new Card(name[i]+dot[j], power[j], cmp.getToolkit().createImage(fileLoc));cards.addElement(card);}}//再读大小王fileLoc = urlLoader.findResource("cards/b.jpg");card = new Card("b",200,cmp.getToolkit().createImage(fileLoc));cards.addElement(card);fileLoc = urlLoader.findResource("cards/s.jpg");card = new Card("s",100,cmp.getToolkit().createImage(fileLoc));cards.addElement(card);//牌背景fileLoc = urlLoader.findResource("cards/bg.jpg");card = new Card("bg",0,cmp.getToolkit().createImage(fileLoc));cards.addElement(card);//初始化Card c = new Card();for(int i=0;i<54;i++){PokerKernal.postCards.addElement(c);}for(int i=0;i<20;i++){PokerKernal.oneCards.addElement(c);PokerKernal.twoCards.addElement(c);PokerKernal.threeCards.addElement(c);PokerKernal.selectCards.addElement(c);}PokerKernal.master = "one";}package poker;import javax.swing.*;import java.awt.*;import java.awt.event.*;/*** <p>Title: 斗地主</p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2004</p>* <p>Company: </p>* author 艳生* version 1.0*/public class HelpDialog extends JDialog {JTextArea txtHelp = new JTextArea();JButton btnOK = new JButton();public HelpDialog() throws HeadlessException {try {jbInit();}catch(Exception e) {e.printStackTrace();}}private void jbInit() throws Exception {//居中显示Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocation((screenSize.width - 450)/2,(screenSize.height - 350)/2);this.setSize(new Dimension(450, 350));this.setModal(true);this.setResizable(false);this.setTitle("游戏规则");txtHelp.setBackground(Color.black);txtHelp.setForeground(Color.green);txtHelp.setText("该游戏由三人玩一副牌,地主为一方,其余两家为一方,\n"+"双方对战,先出完的一方为胜。