其实还是有一些错误的,很多功能懒得实现了,顺子方面我实现不来,好吧主要还是偷懒,仅供参考,java做扑克的视频b站有,不过具体实现要靠自己完成,上面只有怎么把符号和点数组合成一张牌package Game; public class Card implements Comparable{ //花色 private int suit; //点数 private int rank; public Card() { super(); } public Card(int suit, int rank) { super(); this.suit = suit; this.rank = rank; } public int getSuit() { return suit; } public void setSuit(int suit) { this.suit = suit; } public int getRank() { return rank; } public void setRank(int rank) { this.rank = rank; } public String toString() { return App.SUITS[suit]+""+App.RANKS[rank]; } public int compareTo(Object otherCard) { Card other = (Card)otherCard; return this.rank-other.getRank(); } }
package Game; //工具类 public class App { //存放花色 public static final String[] SUITS= {"♠","♥","♣","♦"}; public static final String[] RANKS= {"2","3","4","5","6","7","8","9","10", "J","Q","K","A"}; //红桃 public static final int HEART = 0; //黑桃 public static final int SPADE = 1; //梅花 public static final int CLUB = 2; //方块 public static final int DIAMOND = 3; //点数 public static final int TWO = 0; public static final int THREE = 1; public static final int FOUR = 2; public static final int FIVE = 3; public static final int SIX = 4; public static final int SEVEN = 5; public static final int EIGHT = 6; public static final int NINE = 7; public static final int TEN = 8; public static final int JACK = 9; public static final int QUEEN = 10; public static final int KING = 11; public static final int ACE = 12; }
package Game; import java.util.List; import java.util.ArrayList; /* * 玩家类 * */ public class Player { //名字 private String name; //手牌,不清楚数量,用集合 private List<Card> cards = new ArrayList<Card>(); public Player(String name) { super(); this.name = name; } public Player() { super(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<Card> getCards() { return cards; } public void setCards(List<Card> cards) { this.cards = cards; } @Override public String toString() { return name+":"+cards; } }
package Game; import java.util.*; import java.io.*; import java.net.*; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; public class MainTest { //扑克牌放集合中 static List<Card> poker; //玩家集合 static List<Player>players; static int money1=100,money2=100;//筹码,也可用线程,这里嫌麻烦没用 static int max_suit1=1,max_rank1=1,max_suit2=1,max_rank2=1,max_data1=1,max_data2=1;//分别设值,求相同花色的最大值(同一颜色最多有几张)和相同大小的最多有几张 static int summary_suit=1,summary_rank=1;//设中间值,和最大值比较并更新 public MainTest()throws Exception{ User u =new User(); u.setVisible(true); } class User extends JFrame{ JButton btn1,btn2,btn3;//开始、下注、弃牌 JTextField text1,text2,text_user,text_show; JLabel lbl1,lbl2,lbl_user,lbl_show,lbl; int Jackpot;//奖池 public User() { this.setTitle("胖虎和小夫的德州扑克"); this.setBounds(200,200,600,700); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new GridLayout(6,1)); lbl = new JLabel("每次20筹码,弃牌10筹码,加注可加一次,10筹码"); lbl1 = new JLabel("卢本伟的筹码"); lbl2 = new JLabel("PDD的筹码"); lbl_user = new JLabel("卢本伟的底牌:"); lbl_show = new JLabel("公牌:"); text1 = new JTextField(""+money1); text2 = new JTextField(""+money2); text_user = new JTextField(""); text_show = new JTextField(""); btn1 = new JButton("开始"); btn2 = new JButton("比牌"); btn3 = new JButton("弃牌"); btn1.addActionListener(new ActionListener(){ //添加监听器,单击开始按钮后产生事件,洗牌并发牌,理牌 public void actionPerformed(ActionEvent e){ //清零 text_show.setText(""); text_user.setText(""); //初始化玩家 initPlayer(); //生成扑克牌 poker = createPoker(); //洗牌,shuffle函数打乱集合的顺序 Collections.shuffle(poker); //发牌 deal(); //理牌 sort(); // for(Player p:players) { // System.out.println(p); // } text_show.setText(""+poker.get(0)+poker.get(1)+poker.get(2)+poker.get(3)+poker.get(4)); Player p = players.get(0); text_user.setText(""+p); } }); btn2.addActionListener(new ActionListener(){ //添加监听器,进行比较大小,并相应加减筹码 public void actionPerformed(ActionEvent e){ //先把5张底牌加到每个人的牌底下,让每个人有7张牌,然后排序,最后通过比较确定大小 summary(); sort(); if(compare() == 1) { money1+=20; money2-=20; text1.setText(""+money1); text2.setText(""+money2); } else { money1-=20; money2+=20; text1.setText(""+money1); text2.setText(""+money2); } if(money1 <= 0) { JOptionPane.showMessageDialog(null, "光屁股了,别玩了, 回家做作业去吧!", null, JOptionPane.PLAIN_MESSAGE); System.exit(0); } else if(money2 <= 0) { JOptionPane.showMessageDialog(null, "你们可能不知道只用20万赢到578万是什么概念rn" + "rn" + "我们一般只会用两个字来形容这种人:土块!!", null, JOptionPane.PLAIN_MESSAGE); System.exit(0); } } }); btn3.addActionListener(new ActionListener(){ //添加监听器,直接弃牌认输,少扣筹码 public void actionPerformed(ActionEvent e){ money1-=10; money2+=10; text1.setText(""+money1); text2.setText(""+money2); if(money1 == 0) { JOptionPane.showMessageDialog(null, "光屁股了,别玩了, 回家做作业去吧!", null, JOptionPane.PLAIN_MESSAGE); System.exit(0); } } }); add(lbl1); add(text1); add(lbl2); add(text2); add(lbl_show); add(text_show); add(lbl_user); add(text_user); add(btn1); add(btn2); add(btn3); add(lbl); } } public static void main(String [] args) throws Exception { //System.out.println(poker); //展示手牌 //show(); MainTest test=new MainTest(); } //把底牌也放进人物的牌组中 private static void summary() { int i; Player lbw = players.get(0); Player pdd = players.get(1); List<Card> cards1 = lbw.getCards(); List<Card> cards2 = pdd.getCards(); for(i=0; i<5; i++) { cards1.add(poker.get(i)); cards2.add(poker.get(i)); } } //进行比较并输出结果 private int compare() { Player lbw = players.get(0); Player pdd = players.get(1); List<Card> cards1 = lbw.getCards(); List<Card> cards2 = pdd.getCards(); max_suit1=1; max_rank1=1;//分别设值,求相同花色的最大值(同一颜色最多有几张)和相同大小的最多有几张 summary_suit=1; summary_rank=1;//设中间值,和最大值比较并更新 max_data1=1;max_data2=1;//记录相同情况下谁更大 //审阅检查cards1 for(int i=0; i<cards1.size()-1; i++) { if(cards1.get(i).getSuit() == cards1.get(i+1).getSuit()) { summary_suit+=1; } else { if(summary_suit > max_suit1) { max_suit1 = summary_suit; } } if(cards1.get(i).getRank() == cards1.get(i+1).getRank()) { summary_rank+=1; } else { if(summary_rank > max_rank1) { max_rank1 = summary_rank; max_data1 = cards1.get(i+1).getRank(); } } } summary_suit=1; summary_rank=1;//设中间值值,和最大值比较并更新 //审阅检查cards2 for(int i=0; i<cards2.size()-1; i++) { if(cards2.get(i).getSuit() == cards2.get(i+1).getSuit()) { summary_suit+=1; } else { if(summary_suit > max_suit2) { max_suit2 = summary_suit; } } if(cards2.get(i).getRank() == cards2.get(i+1).getRank()) { summary_rank+=1; } else { if(summary_rank >= max_rank2) { max_rank2 = summary_rank; max_data2 = cards2.get(i+1).getRank(); } } } //大小规则:皇家同花顺>同花顺>炸弹>俘虏(3+2)>同花>顺子>三条>一对>高牌 if(max_rank1 == 4){ JOptionPane.showMessageDialog(null, "卢本伟牛逼!", null, JOptionPane.PLAIN_MESSAGE); return 1; } else if(max_rank2 == 4) { JOptionPane.showMessageDialog(null, "干尼玛的杀破狼!干尼玛超人战士!日尼玛威猛先生!", null, JOptionPane.PLAIN_MESSAGE); return 2; } else if(max_suit1>=5) { JOptionPane.showMessageDialog(null, "从现在开始这里叫卢本伟广场!", null, JOptionPane.PLAIN_MESSAGE); return 1; } else if(max_suit2>=5) { JOptionPane.showMessageDialog(null, "跟我刘某玩操作!!", null, JOptionPane.PLAIN_MESSAGE); return 2; } else if(max_rank1 == 3 && max_rank2<3) { JOptionPane.showMessageDialog(null, "当年,陈刀仔用20块赢到3700万,我卢本伟用20万赢到500万不是问题!", null, JOptionPane.PLAIN_MESSAGE); return 1; } else if(max_rank2 == 3 && max_rank1<3) { JOptionPane.showMessageDialog(null, "皮皮虾,我们走~!", null, JOptionPane.PLAIN_MESSAGE); return 2; } else if(max_rank1 == 2 && max_rank2<2) { JOptionPane.showMessageDialog(null, "给阿姨倒一杯卡布奇诺~", null, JOptionPane.PLAIN_MESSAGE); return 1; } else if(max_rank2 == 2 && max_rank1<2) { JOptionPane.showMessageDialog(null, "好险好险,骚猪我依然发育起来了。", null, JOptionPane.PLAIN_MESSAGE); return 2; } else if(max_rank2 == max_rank1) { if(max_data1 >= max_data1) { JOptionPane.showMessageDialog(null, "2张牌你能秒我?你能秒杀我?2张牌你能秒杀我,我当场,把电脑屏幕吃掉!", null, JOptionPane.PLAIN_MESSAGE); return 1; } else { JOptionPane.showMessageDialog(null, "芽儿呦,差点裂开了,太瓦了!", null, JOptionPane.PLAIN_MESSAGE); return 2; } } return 1; } private static void sort() { for(Player p:players) { List<Card> cards = p.getCards(); Collections.sort(cards); } } private static void show() { for(Player p:players) { System.out.println(p); } } //发牌 private static void deal() { //3张公牌,令i=5就是从第6张牌开始发给玩家和NPC,前五张作为公牌 int i=5; for(int j=0; j<2; j++) { for(int k=0; k<players.size(); k++) { Player player = players.get(k); List<Card> cards = player.getCards(); cards.add(poker.get(i)); i++; } } } //初始化玩家 private static void initPlayer() { //创建 players = new ArrayList<Player>(); //添加玩家 players.add(new Player("卢本伟")); players.add(new Player("PDD")); } /**生成扑克牌 *public static final String[] SUITS= {"♠","♥","♣","♦"}; *public static final String[] RANKS= {"2","3","4","5","6","7","8","9","10", "J","Q","K","A"}; * @return */ private static List<Card> createPoker(){ List<Card> poker = new ArrayList<Card>(); for(int i=0; i<App.SUITS.length; i++) { for(int j=0; j<App.RANKS.length;j++) { //System.out.println(App.SUITS[i]+""+App.RANKS[j]); //根据花色点数创建扑克牌 Card card = new Card(i,j); poker.add(card); } } return poker; } }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算