首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

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

后端 27.59KB 30 需要积分: 1
立即下载

资源介绍:

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 getOneCards(){ this.shuffle(); ArrayList list = new ArrayList<>(); for (int i = 0;i < 5;i ++){ list.add(cards[i]); } return list; } public String getType(List card){ List rankList = new ArrayList<>(); Set suitSet = new HashSet<>(); HashSet rankSet = new HashSet<>(); Map 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 = 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); } }

资源文件列表:

poker.zip 大约有45个文件
  1. poker/.idea/
  2. poker/.idea/.gitignore 50B
  3. poker/.idea/codeStyles/
  4. poker/.idea/codeStyles/codeStyleConfig.xml 153B
  5. poker/.idea/codeStyles/Project.xml 269B
  6. poker/.idea/misc.xml 278B
  7. poker/.idea/modules.xml 257B
  8. poker/.idea/workspace.xml 5.95KB
  9. poker/excerise/
  10. poker/excerise/.idea/
  11. poker/excerise/.idea/.gitignore 50B
  12. poker/excerise/.idea/misc.xml 276B
  13. poker/excerise/.idea/modules.xml 263B
  14. poker/excerise/.idea/workspace.xml 3.98KB
  15. poker/excerise/excerise.iml 433B
  16. poker/excerise/out/
  17. poker/excerise/out/production/
  18. poker/excerise/out/production/excerise/
  19. poker/excerise/out/production/excerise/day0717/
  20. poker/excerise/out/production/excerise/day0717/Card.class 1.2KB
  21. poker/excerise/out/production/excerise/day0717/Circle.class 656B
  22. poker/excerise/out/production/excerise/day0717/Main.class 1.1KB
  23. poker/excerise/out/production/excerise/day0717/Point.class 575B
  24. poker/excerise/out/production/excerise/day0717/Poker.class 4.77KB
  25. poker/excerise/out/production/excerise/day0717/PokerGame.class 3.7KB
  26. poker/excerise/out/production/excerise/GuessWord.class 2.18KB
  27. poker/excerise/out/production/excerise/Main.class 516B
  28. poker/excerise/src/
  29. poker/excerise/src/poker/
  30. poker/excerise/src/poker/Card.java 866B
  31. poker/excerise/src/poker/Poker.java 3.51KB
  32. poker/excerise/src/poker/PokerGame.java 2.29KB
  33. poker/out/
  34. poker/out/production/
  35. poker/out/production/poker/
  36. poker/out/production/poker/poker/
  37. poker/out/production/poker/poker/Card.class 886B
  38. poker/out/production/poker/poker/Poker.class 4.57KB
  39. poker/out/production/poker/poker/PokerGame.class 3.5KB
  40. poker/poker.iml 433B
  41. poker/src/
  42. poker/src/poker/
  43. poker/src/poker/Card.java 864B
  44. poker/src/poker/Poker.java 3.51KB
  45. poker/src/poker/PokerGame.java 2.43KB
0评论
提交 加载更多评论
其他资源 EmuCheat2014_downcc.zip
EmuCheat2014_downcc.zip
网页滚动导航:一键跳转的实现
网页滚动导航:一键跳转的实现
网页滚动导航:一键跳转的实现 网页滚动导航:一键跳转的实现 网页滚动导航:一键跳转的实现
c语言自创推箱子游戏改版.zip
c语言自创推箱子游戏改版.zip
c语言自创军旗游戏源码.zip
c语言自创军旗游戏源码.zip
Redis5.0 Common+Interfaces+Redis+Text
解决C#调用redis超出一定数量不能用的问题,版本为5.0.0,包括ServiceStack.Common.dll,ServiceStack.Interfaces.dll,ServiceStack.Redis.dll,ServiceStack.Text.dll四个dll文件。 ServiceStack.Redis 的 ASP.NET Core 扩展库,它是基于 ServiceStack.Redis.Core 开发的。 简单易用,开源免费,使用ASP.NET Core自身提供的DI容器来实现针对服务的注册和消费。直接在程序启动时注册到服务中即可完成全部配置,对于小白用户也可快速上手Redis缓存和Redis分布式缓存。
Aspose.Cells
Aspose.Cells.dll,C# 操作excel导出、读取等操作。Aspose是.NET和Java开发组件以及为Microsoft SQL Server Reporting Services和JasperReports等平台提供渲染扩展的领先供应商。它的核心重点是提供最完整和最强大的文件管理产品。Aspose产品支持一些商业上最流行的文件格式,包括:Word文档、Excel电子表格、PowerPoint演示文稿、PDF文档、Flash演示文稿和项目文件。
rax3000m刷机固件
rax3000m刷机固件
Navicat软件zip压缩包
Navicat软件zip压缩包