下载资源后端资源详情
poker.zip
大小:27.59KB
价格:20积分
下载量:0
评分:
5.0
上传者:m0_73282111
更新日期:2025-09-22

Java练习-扑克牌小游戏-不断升级中~~~

资源文件列表(大概)

文件名
大小
poker/.idea/
-
poker/.idea/.gitignore
50B
poker/.idea/codeStyles/
-
poker/.idea/codeStyles/codeStyleConfig.xml
153B
poker/.idea/codeStyles/Project.xml
269B
poker/.idea/misc.xml
278B
poker/.idea/modules.xml
257B
poker/.idea/workspace.xml
5.95KB
poker/excerise/
-
poker/excerise/.idea/
-
poker/excerise/.idea/.gitignore
50B
poker/excerise/.idea/misc.xml
276B
poker/excerise/.idea/modules.xml
263B
poker/excerise/.idea/workspace.xml
3.98KB
poker/excerise/excerise.iml
433B
poker/excerise/out/
-
poker/excerise/out/production/
-
poker/excerise/out/production/excerise/
-
poker/excerise/out/production/excerise/day0717/
-
poker/excerise/out/production/excerise/day0717/Card.class
1.2KB
poker/excerise/out/production/excerise/day0717/Circle.class
656B
poker/excerise/out/production/excerise/day0717/Main.class
1.1KB
poker/excerise/out/production/excerise/day0717/Point.class
575B
poker/excerise/out/production/excerise/day0717/Poker.class
4.77KB
poker/excerise/out/production/excerise/day0717/PokerGame.class
3.7KB
poker/excerise/out/production/excerise/GuessWord.class
2.18KB
poker/excerise/out/production/excerise/Main.class
516B
poker/excerise/src/
-
poker/excerise/src/poker/
-
poker/excerise/src/poker/Card.java
866B
poker/excerise/src/poker/Poker.java
3.51KB
poker/excerise/src/poker/PokerGame.java
2.29KB
poker/out/
-
poker/out/production/
-
poker/out/production/poker/
-
poker/out/production/poker/poker/
-
poker/out/production/poker/poker/Card.class
886B
poker/out/production/poker/poker/Poker.class
4.57KB
poker/out/production/poker/poker/PokerGame.class
3.5KB
poker/poker.iml
433B
poker/src/
-
poker/src/poker/
-
poker/src/poker/Card.java
864B
poker/src/poker/Poker.java
3.51KB
poker/src/poker/PokerGame.java
2.43KB

资源内容介绍

Java练习-扑克牌小游戏-不断升级中~~~
package day0717;import java.util.*;public class Poker { Card[] cards = new Card[20]; String[] suits = {"黑桃","红心","方片","草花"}; public Poker(){ int index = 0; for (int i = 0;i < suits.length;i ++){ for (int j = 10;j <= 14;j ++){ Card card = new Card(suits[i],j); cards[index] = card; index ++; } } } public void out(){ int index = 0; for (int i = 0;i < suits.length;i ++) { for (int j = 10; j <= 14; j++) { System.out.print(cards[index]+" "); index ++; } System.out.println(); } } public void shuffle(){ Random random = new Random(); for (int i = 0; i < 20;i ++){ int index = random.nextInt(20); Card temp = cards[i]; cards[i] = cards[index]; cards[index] = temp; } } public List<Card> getOneCards(){ this.shuffle(); ArrayList<Card> list = new ArrayList<>(); for (int i = 0;i < 5;i ++){ list.add(cards[i]); } return list; } public String getType(List<Card> card){ List<Integer> rankList = new ArrayList<>(); Set<String> suitSet = new HashSet<>(); HashSet<Integer> rankSet = new HashSet<>(); Map<Integer, Integer> map = new HashMap<>(); for (Card card1 : card){ suitSet.add(card1.suit); rankSet.add(card1.rank); rankList.add(card1.rank); if (map.containsKey(card1.rank)){ int count = map.get(card1.rank); count ++; map.put(card1.rank,count); }else { map.put(card1.rank,1); } } Collections.sort(rankList); boolean isSameColor = false; boolean isShunzi = false; if (rankList.get(4)-rankList.get(0) == 4 && rankSet.size() == 5){ isShunzi = true; } if (suitSet.size()==1){ isSameColor = true; } if(isShunzi && isSameColor){ return "同花顺"; } if (isShunzi){ return "顺子"; } if (isSameColor){ return "同花"; } if (rankSet.size() == 2){ if (map.containsValue(4)){ return "四条"; }else { return "满堂红"; } } if (rankSet.size() == 3){ if (map.containsValue(3)){ return "311"; }else { return "221"; } } if (rankSet.size() == 4){ return "一对"; } return "不知道"; } public Card getCard(int index){ return cards[index]; } public static void main(String[] args) { Poker poker = new Poker(); //poker.out(); //System.out.println("-------------"); //poker.shuffle(); //poker.out(); //System.out.println("-------------"); List<Card> card = poker.getOneCards(); poker.out(); System.out.println("-------------"); for(Card card1 : card){ System.out.print(card1+" "); } System.out.println("\n\n判断牌型"); String type = poker.getType(card); System.out.println(type); }}

用户评论 (0)

发表评论

captcha