斗地主特殊牌型定义
2018-06-18 03:40:36来源:未知 阅读 ()
游戏内一些牌型的定义,不做过多解释代码很详细,哪有不懂可以留言询问
public enum DDZPaiType {
HuoJian("火箭",30,"HuoJian"),
ZhaDan("炸弹",20,"ZhaDan"),
DanPai("单牌",10,"DanPai"),
DuiPai("对牌",10,"DuiPai"),
SanZhangPai("三张牌",10,"SanZhangPai"),
SanDaiYi("三带一",10,"SanDaiYi"),
SanDaiEr("三带二",10,"SanDaiEr"),
DanShun("单顺",10,"DanShun"),
ShuangShun("双顺",10,"ShuangShun"),
SanShun("三顺",10,"SanShun"),
FeiJiDaiDanPai("飞机带两单",10,"FeiJiDaiDanPai"),
FeiJiDaiDuiZi("飞机带两对",10,"FeiJiDaiDuiZi"),
SiDaiLiangDan("四带两单",10,"SiDaiLiangDan"),
SiDaiLiangDui("四带两对",10,"SiDaiLiangDui");
private String name;
private String nickName;
private int weight;
private int size;
DDZPaiType(String name, int weight,String nickName) {
this.name = name;
this.weight = weight;
this.nickName = nickName;
}
@Override
public String toString() {
return name;
}
public String getName() {
return name;
}
public int getWeight() {
return weight;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
/**
* 获取牌的类型
*@param pokers
*@return
*@return
* 2018年1月27日
* @throws ZJHPokerException
*/
public static DDZPaiType getPaiType(DDZPai ddzPai) throws DDZPokerException{
List<DDZPoker> pokers = ddzPai.getDdzPokers();
Collections.sort(pokers);
//Collections.sort(pokers);
if(isHuoJian(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return HuoJian;
}
if(isZhaDan(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return ZhaDan;
}
if(isDanPai(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return DanPai;
}
if(isDuiZi(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return DuiPai;
}
if(isSanZhangPai(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return SanZhangPai;
}
if(isSanDaiYi(pokers,ddzPai)){
return SanDaiYi;
}
if(isSanDaiEr(pokers,ddzPai)){
return SanDaiEr;
}
if(isDanShun(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return DanShun;
}
if(isShuangShun(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return ShuangShun;
}
if(isSanShun(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return SanShun;
}
if(isFeiJiDaiLiangDan(pokers,ddzPai)){
return FeiJiDaiDanPai;
}
if(isFeiJiDaiLiangDui(pokers, ddzPai)){
return FeiJiDaiDuiZi;
}
if(isSiDaiLiangDan(pokers, ddzPai)){
return SiDaiLiangDan;
}
if(isSiDaiLiangDui(pokers, ddzPai)){
return SiDaiLiangDui;
}
return null;
}
//单顺
private static boolean isDanShun(List<DDZPoker> pokers) {
if(pokers.size()>=5){
if(pokers.get(0).getSize()>=15){
return false;
}
for (int i =0;i<pokers.size();i++) {
if(i<pokers.size()-1&&pokers.get(i).getSize()-pokers.get(i+1).getSize()!=1){
return false;
}
}
return true;
}
return false;
}
//四带两对
private static boolean isSiDaiLiangDui(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==8){
int count1 = 0;
int count2 = 0;
DDZPoker ddzPoker = new DDZPoker();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==4){
ddzPoker = pokers.get(i);
count1++;
}
if(num==2){
count2++;
}
}
if(count1==4 && count2==4){
ddzPai.setDdzPoker(ddzPoker);
return true;
}
}
return false;
}
//四带两单
private static boolean isSiDaiLiangDan(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==6){
int count1 = 0;
DDZPoker ddzPoker = new DDZPoker();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==4){
ddzPoker = pokers.get(i);
count1++;
}
}
if(count1==4){
ddzPai.setDdzPoker(ddzPoker);
return true;
}
}
return false;
}
//飞机带对子
private static boolean isFeiJiDaiLiangDui(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()>=10&&pokers.size()%5==0){
int count1 = 0;
int count2 = 0;
List<DDZPoker> ddzPokers = new ArrayList<DDZPoker>();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==3){
count1++;
ddzPokers.add(pokers.get(i));
}
if(num==2){
count2++;
}
}
Collections.sort(ddzPokers);
if(count1==(pokers.size()/5)*3 && count2==(pokers.size()/5)*2
&&ddzPokers.get(0).getSize()<15 &&
ddzPokers.get(0).getSize()-ddzPokers.get(ddzPokers.size()-1).getSize()
== (pokers.size()/5)-1){
ddzPai.setDdzPoker(ddzPokers.get(0));
return true;
}
}
return false;
}
//飞机带单牌
private static boolean isFeiJiDaiLiangDan(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()>=8&&pokers.size()%4==0){
int count = 0;
List<DDZPoker> ddzPokers = new ArrayList<DDZPoker>();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==3){
count++;
ddzPokers.add(pokers.get(i));
}
}
//四带两对的判定
if(ddzPokers.size() > 0 &&ddzPokers.get(0).getSize()<15){
if(count==(pokers.size()/4)*3){
Collections.sort(ddzPokers);
if(ddzPokers.get(0).getSize()-ddzPokers.get(ddzPokers.size()-1).getSize()==(pokers.size()/4-1)){
ddzPai.setDdzPoker(ddzPokers.get(0));
return true;
}else{
return false;
}
}
}
}
return false;
}
//三顺
private static boolean isSanShun(List<DDZPoker> pokers) {
if(pokers.size()%3==0&&pokers.size()>=6){
for (int i =0;i<pokers.size();i=i+3) {
if(pokers.get(i).getPokerNum()!=pokers.get(i+2).getPokerNum()){
return false;
}
}
if(pokers.get(0).getSize()>=15){
return false;
}else{
if(pokers.get(0).getSize()-pokers.get(pokers.size()-1).getSize()==(pokers.size()/3)-1){
return true;
}
}
}
return false;
}
//双顺
private static boolean isShuangShun(List<DDZPoker> pokers) {
if(pokers.size()%2==0&&pokers.size()>=6){
for (int i =0;i<pokers.size();i=i+2) {
if(pokers.get(i).getPokerNum()!=pokers.get(i+1).getPokerNum()){
return false;
}
}
if(pokers.get(0).getSize()>=15){
return false;
}else{
if(pokers.get(0).getSize()-pokers.get(pokers.size()-1).getSize()==(pokers.size()/2)-1){
return true;
}
}
}
return false;
}
//三带二
private static boolean isSanDaiEr(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==5&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-3)).getPokerNum()&&
pokers.get(3).getPokerNum() ==pokers.get((4)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(0));
return true;
}
if(pokers.size()==5&&pokers.get(2).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum()&&
pokers.get(0).getPokerNum() ==pokers.get((1)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(2));
return true;
}
return false;
}
//三带一
private static boolean isSanDaiYi(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==4&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-2)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(0));
return true;
}
if(pokers.size()==4&&pokers.get(1).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(1));
return true;
}
return false;
}
//三张牌
private static boolean isSanZhangPai(List<DDZPoker> pokers) {
if(pokers.size()==3&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum() ){
return true;
}
return false;
}
//对子
private static boolean isDuiZi(List<DDZPoker> pokers) {
if(pokers.size()==2&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum() ){
return true;
}
return false;
}
//单牌
private static boolean isDanPai(List<DDZPoker> pokers) {
if(pokers.size()==1){
return true;
}
return false;
}
//炸弹
private static boolean isZhaDan(List<DDZPoker> pokers) {
if(pokers.size()==4&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum() ){
return true;
}
return false;
}
//王炸
private static boolean isHuoJian(List<DDZPoker> pokers) {
if(pokers.size()==2&&pokers.get(0).getPokerNum() ==PokerNum.P_DAWANG &&pokers.get(pokers.size() - 1).getPokerNum() ==PokerNum.P_XIAOWANG ){
return true;
}
return false;
}
//测试方法
public static void main(String [] args ){
List<DDZPoker> pokers = new ArrayList<DDZPoker>();
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_J)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_Q)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_10)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_A)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_K)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.WANG, PokerNum.P_DAWANG)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.WANG, PokerNum.P_XIAOWANG)));
pokers.add(new DDZPoker(new Poker(PokerColorType.MEI_HUA, PokerNum.P_4)));
pokers.add(new DDZPoker(new Poker(PokerColorType.MEI_HUA, PokerNum.P_5)));
pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_6)));
pokers.add(new DDZPoker(new Poker(PokerColorType.MEI_HUA, PokerNum.P_7)));
pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_8)));
Collections.sort(pokers);
DDZPai ddzPai = new DDZPai();
boolean flage = isDanShun(pokers);
System.out.println(ddzPai.toString());
for(int i = 0 ; i < pokers.size(); i++){
DDZPoker poker = pokers.get(i);
System.out.println(poker.getSize());
}
System.out.println(flage);
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 用斗地主的实例学会使用java Collections工具类 2020-06-05
- Spring Boot加密配置文件特殊内容 2020-05-29
- 特殊的赋值运算符 2020-05-09
- Spring2——特殊值的注入问题、自动装配、使用注解定义bean 2020-04-09
- Java基础语法(5)-特殊流程控制语句 2020-03-30
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash