package doudizhu;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Rules {
public static final String[] str={"3","4","5","6","7","8","9","10","J","Q","K","A"};
public static final String[] AllStr={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
public static CardType cardType=new CardType();
/**
* 第一步出牌规范检验
* 出牌符合规则返回true,不符合规则返回false
*/
public static boolean check(List
list) {
//把所有的检验方法用来检验一遍,只有遇到一个true,就马上返回,如果到最后没有遇到true,就返回false表示出牌不符合规范
//这里是用java反射的机制写的!
//当然这个过程还有一个功能没写就是要携带一个CardType,就是牌型,方便后面的提示!
return checkAll(list);
}
public static boolean checkAll(List list) {
boolean flag=false;
try {
@SuppressWarnings("unchecked")
Class set=(Class) Class.forName("doudizhu.Rules");
Object obj=set.newInstance();
Method[] methods=set.getMethods();
Method[] method=pickMethod(methods);
int index=0;
while(!flag&&index<=method.length-1){
flag=(boolean) method[index].invoke(obj,list);
index++;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return flag;
}
/**
* 单张检验
*/
public static boolean checkSingle(List list) {
if(list.size()==1) {
cardType.setAllCard(list);
cardType.setCardType(Constant.SINGLE);
cardType.setMainPartCard(list);
return true;
}
return false;
}
/**
* 这里是为了筛选方法,因为用反射的getMethods方法
* 返回的不只是在本类中写的方法,因为还是涉及
* 到父类的方法,所以有很多的其他,而且还是随机的排列
* 顺序,所以我这里要对得到的方法做一个处理
* 保证后面调方法的时候不会出现NoClassFoundDefError这个错误
* @param method
* @return
*/
public static Method[] pickMethod(Method[] method) {
Method[] methods={};
for(int i=0;i String str=method[i].getName();
if(str.equals("checkSingle")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkArray")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkArraysubmit")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkArrays")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkThree")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkThreeGetOne")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkAirplane")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkBoom")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}else if(str.equals("checkFourGetTwo")) {
methods=Arrays.copyOf(methods,methods.length+1);
methods[methods.length-1]=method[i];
}
}
return methods;
}
/**
* 顺子校验
*/
public static boolean checkArray(List list) {
if(list.size()>=5) {
String point=list.get(0).getPoints();
int index=0;
for(int i=0;i if(point.equals(str[i])) {
index=i;
}
}
if(index+list.size()<=str.length) {
String lastPoint=str[index+list.size()-1];
if(lastPoint.equals(list.get(list.size()-1).getPoints())) {
cardType.setAllCard(list);
cardType.setCardType(Constant.STRAIGHT);
cardType.setMainPartCard(list);
return true;
}
}
}
return false;
}
/**
* 对子检验
*/
public static boolean checkArraysubmit(List list) {
if(list.size()==2) {
String firstPoint=list.get(0).getPoints();
String lastPoint=list.get(1).getPoints();
for(int i=0;i if(firstPoint.equals(AllStr[i])&&lastPoint.equals(AllStr[i])) {
cardType.setAllCard(list);
cardType.setCardType(Constant.DOUBLE);
cardType.setMainPartCard(list);
return true;
}
}
}
return false;
}
/**
* 连对校验
*/
public static boolean checkArrays(List list) {
if(list.size()%2==0&&list.size()>=6) {
String firstPoint1=list.get(0).getPoints();
String firstPoint2=list.get(1).getPoints();
int index=0;
for(int i=0;i if(firstPoint1.equals(str[i])&&firstPoint2.equals(str[i])) {
index=i;
break;
}
}
if(index+list.size()/2-1 int account=1;
boolean flag=true;
for(int i=index+1;i<=index+list.size()/2-1;i++) {
for(int j=0;j<2;j++) {
account++;
flag=str[i].equals(list.get(account).getPoints());
}
if(!flag) {
break;
}
}
if(flag) {
cardType.setAllCard(list);
cardType.setCardType(Constant.LINEDOUBLE);
cardType.setMainPartCard(list);
return true;
}
}
}
return false;
}
/**
* 三不带检验
*/
public static boolean checkThree(List list) {
if(list.size()==3) {
String pointOne=list.get(0).getPoints();
String pointTwo=list.get(1).getPoints();
String pointThree=list.get(2).getPoints();
boolean flag=pointOne.equals(pointTwo)&&pointOne.equals(pointThree);
if(flag) {
cardType.setAllCard(list);
cardType.setCardType(Constant.THREE);
cardType.setMainPartCard(list);
return true;
}
}
return false;
}
/**
* 三代一检验
*/
public static boolean checkThreeGetOne(List list) {
if(list.size()==4) {
String pointOne=list.get(0).getPoints();
String pointTwo=list.get(1).getPoints();
String pointThree=list.get(2).getPoints();
List mainPart=new ArrayList();
mainPart.add(list.get(0));
mainPart.add(list.get(1));
mainPart.add(list.get(2));
String pointFour=list.get(3).getPoints();
boolean flag=pointOne.equals(pointTwo)&&pointOne.equals(pointThree)&&!pointOne.equals(pointFour);
if(flag) {
cardType.setAllCard(list);
cardType.setCardType(Constant.THREEFORONE);
cardType.setMainPartCard(mainPart);
return true;
}
}
return false;
}
/**
* 飞机校验
*/
public static boolean checkAirplane(List list) {
if(list.size()%3==0&&list.size()%4==0) {
String firstPoint1=list.get(0).getPoints();
String firstPoint2=list.get(1).getPoints();
String firstPoint3=list.get(2).getPoints();
int index=0;
boolean flag1=firstPoint1.equals(firstPoint2)&&firstPoint1.equals(firstPoint3);
for(int i=0;i boolean flag2=str[i].equals(firstPoint1);
if(flag1&&flag2) {
index=i;
break;
}
}
/**
* 这里判断是为了不出现KA2的飞机
*/
if(index+3 String lastPoint1=list.get(6).getPoints();
String lastPoint2=list.get(7).getPoints();
String lastPoint3=list.get(8).getPoints();
String lastPoint4=list.get(9).getPoints();
String lastPoint5=list.get(10).getPoints();
String lastPoint6=list.get(11).getPoints();
boolean flag3=lastPoint1.equals(lastPoint2)&&lastPoint1.equals(lastPoint3);
boolean flag4=lastPoint4.equals(lastPoint5)&&lastPoint4.equals(lastPoint6);
String point1=str[index+2];
String point2=str[index+3];
boolean flag5=lastPoint1.equals(point1);
boolean flag6=lastPoint4.equals(point2);
List mainPart=new ArrayList();
for(int i=0;i<=8;i++) {
mainPart.add(list.get(i));
}
if(flag5&&flag3&&!flag6) {
cardType.setAllCard(list);
cardType.setMainPartCard(mainPart);
cardType.setCardType(Constant.AIRPLANEWING);
return true;
}else if(flag5&&flag3&&flag4&&flag6) {
cardType.setAllCard(list);
cardType.setCardType(Constant.AIRPLANE);
cardType.setMainPartCard(list);
return true;
}
}
}else if(list.size()%3==0&&list.size()>=6) {
//这里情况并不是那么复杂,只要求看首位三个是否相等
//然后根据已知常量,还有list的长度来判断最后三位是什么就行,看符合不!
//这里是飞机不带零件
String pointOne=list.get(0).getPoints();
String pointTwo=list.get(1).getPoints();
String pointThree=list.get(2).getPoints();
boolean flag1=pointOne.equals(pointTwo)&&pointOne.equals(pointThree);
int index=0;
for(int i=0;i if(flag1&&str[i].equals(pointOne)) {
index=i;
break;
}
}
if(index+list.size()/3-1 String last1=list.get(list.size()-1).getPoints();
String last2=list.get(list.size()-2).getPoints();
String last3=list.get(list.size()-3).getPoints();
String point=str[index+list.size()/3-1];
boolean flag2=last1.equals(last2)&&last1.equals(last3)&&last1.equals(point);
if(flag2) {
cardType.setCardType(Constant.AIRPLANE);
cardType.setAllCard(list);
cardType.setMainPartCard(list);
return true;
}
}
}else if(list.size()%4==0&&list.size()>=8) {
//这里比较复杂,从二飞到地主可以极限五飞,但是要去掉三飞就行,这里三种情况一一写出来就行
int a=list.size()/4;
String pointOne=list.get(0).getPoints();
String pointTwo=list.get(1).getPoints();
String pointThree=list.get(2).getPoints();
int index=0;
boolean flag1=pointOne.equals(pointTwo)&&pointOne.equals(pointThree);
for(int i=0;i if(flag1&&pointOne.equals(str[i])) {
index=i;
break;
}
}
if(index+a<=str.length) {
int b=list.size()-a-1;
String last1=list.get(b).getPoints();
String last2=list.get(b-1).getPoints();
String last3=list.get(b-2).getPoints();
String point=str[index+a-1];
boolean flag2=last1.equals(last2)&&last1.equals(last3)&&last1.equals(point);
if(flag2) {
List mainPart=new ArrayList();
for(int i=0;i<3*a;i++) {
mainPart.add(list.get(i));
}
cardType.setAllCard(list);
cardType.setCardType(Constant.AIRPLANEWING);
cardType.setMainPartCard(mainPart);
return true;
}
}
}
return false;
}
/**
* 炸弹校验
*/
public static boolean checkBoom(List list) {
if(list.size()==2) {
String firstPoint=list.get(0).getPoints();
String lastPoint=list.get(1).getPoints();
if(firstPoint.equals("King")&&lastPoint.equals("King")) {
return true;
}
}else if(list.size()==4) {
String pointOne=list.get(0).getPoints();
String pointTwo=list.get(1).getPoints();
String pointThree=list.get(2).getPoints();
String pointFour=list.get(3).getPoints();
for(int i=0;i if(pointOne.equals(AllStr[i])) {
boolean flag=pointTwo.equals(AllStr[i])&&pointThree.equals(AllStr[i])&&pointFour.equals(AllStr[i]);
if(flag) {
cardType.setAllCard(list);
cardType.setCardType(Constant.BOOM);
cardType.setMainPartCard(list);
return true;
}
break;
}
}
}
return false;
}
/**
* 四代二校验
*/
public static boolean checkFourGetTwo(List list) {
if(list.size()==6) {
String pointOne=list.get(0).getPoints();
String pointTwo=list.get(1).getPoints();
String pointThree=list.get(2).getPoints();
String pointFour=list.get(3).getPoints();
List mainPart=new ArrayList();
mainPart.add(list.get(0));
mainPart.add(list.get(1));
mainPart.add(list.get(2));
mainPart.add(list.get(3));
boolean flag=pointOne.equals(pointTwo)&&pointOne.equals(pointThree)&&pointOne.equals(pointFour);
if(flag) {
cardType.setAllCard(list);
cardType.setCardType(Constant.FOURFORTWO);
cardType.setMainPartCard(mainPart);
return true;
}
}
return false;
}
}
package doudizhu;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
* 洗牌
* 随机打乱牌序
*/
public class WashCard{
public static List
listCard=new ArrayList();
public static void randomDisorder() {
random();
if(listCard.size()!=0) {
listCard=new ArrayList();
}
for(int i=0;i int index=arraysInt[i];
listCard.add(Cards.cards.get(index));
}
}
/**
* 产生0-53不重复的随机数
*/
private static int[] arraysInt={};
private static void random() {
Random r=new Random();
int account=0;
while(account!=54) {
int a=r.nextInt(54);
if(arraysInt.length==0) {
arraysInt=Arrays.copyOf(arraysInt, arraysInt.length+1);
arraysInt[arraysInt.length-1]=a;
account++;
}else {
boolean flag=true;
for(int i=0;i if(arraysInt[i]==a) {
flag=false;
break;
}
}
if(flag) {
arraysInt=Arrays.copyOf(arraysInt, arraysInt.length+1);
arraysInt[arraysInt.length-1]=a;
account++;
}
}
}
}
}
package doudizhu;
import java.util.ArrayList;
import java.util.List;
public class SendCard {
/**
* 发牌
*/
public static List list=new ArrayList();
public static String status="3";
public static List overPlus; //地主发牌后会有剩余牌,而四人游戏没有剩余牌
static {
if(status.equals("3")) {
CardPlayers play1=new CardPlayers();
CardPlayers play2=new CardPlayers();
CardPlayers play3=new CardPlayers();
list.add(play1);
list.add(play2);
list.add(play3);
overPlus=new ArrayList();
}else {
CardPlayers play1=new CardPlayers();
CardPlayers play2=new CardPlayers();
CardPlayers play3=new CardPlayers();
CardPlayers play4=new CardPlayers();
list.add(play1);
list.add(play2);
list.add(play3);
list.add(play4);
}
}
public static void sendCard() {
if(status.equals("3")) {
int change=0;
for(int i=0;i if(i list.get(change).getListCards().add(WashCard.listCard.get(i));
change++;
if(change==2) {
change=0;
}
}else {
overPlus.add(WashCard.listCard.get(i));
}
}
}else {
int change=0;
for(int i=0;i list.get(change).getListCards().add(WashCard.listCard.get(i));
change++;
if(change==3) {
change=0;
}
}
}
}
}
package doudizhu;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class ArrangeCard {
public static final String[] ALLRIGHT={"3","4","5","6","7","8","9","10","J","Q","K","A","2","King"};
public static Map map=new HashMap();
static {
init();
}
/**
* 初始化一副牌,以便后面实现记牌器功能
* 记牌器有两种想法,一种是打出去的牌,才算消失的牌,剩余的牌包括本玩家手中的牌
* 一种是不包括本玩家手里的牌
*/
/**
* 记牌器的实现还是挺简单的,先检测玩家手中有那些牌
* 然后用总牌数去掉这些牌就可以实现!然后就是实时的打牌过程去掉牌
*/
public static void cardHolder(List list){
for(int i=0;i Set> set=map.entrySet();
for(Entry e:set) {
if(e.getKey().equals(list.get(i).getPoints())) {
map.put(e.getKey(),e.getValue()-1);
break;
}
}
}
}
public static void init() {
map.put("3",4);
map.put("4",4);
map.put("5",4);
map.put("6",4);
map.put("7",4);
map.put("8",4);
map.put("9",4);
map.put("10",4);
map.put("J",4);
map.put("Q",4);
map.put("K",4);
map.put("A",4);
map.put("2",4);
map.put("King",2);
}
/**
* 发牌完过后的排序
* 也可用于实时排序
* @param 发到玩家手中的牌
* @return 排序过后的牌
*/
public static List arrange(List list){
for(int i=0;i for(int j=0;j int a=list.get(j).compareTo(list.get(j+1));
if(a>0) {
Card card=list.get(j);
list.set(j, list.get(j+1));
list.set(j+1,card);
}
}
}
return list;
}
/**
* 把牌提起来的然后在规则检查之前排序,方便后面的牌型判断
*/
public static List arrangePlay(List list){
List arrayList=new ArrayList();
if(list.size()!=1) {
String[] index=MapToString(listToMap(list));
for(int i=0;i for(int j=0;j if(index[i].equals(list.get(j).getPoints())) {
arrayList.add(list.get(j));
list.remove(j);
break;
}
}
}
}
return arrayList;
}
public static Map listToMap(List list){
Map map=new HashMap();
for(int i=0;i if(!map.containsKey(list.get(i).getPoints())) {
map.put(list.get(i).getPoints(),1);
}else {
map.put(list.get(i).getPoints(),map.get(list.get(i).getPoints())+1);
}
}
return map;
}
/**
* 在map中存有每个牌的张数
* 但是现在没有按照我理想中的顺序排序
* @param map
* @return
*/
public static String[] MapToString(Map map) {
String[] index={};
String[] quiet={};
int[] sol= {};
Set> set=map.entrySet();
for(Entry e:set) {
quiet=Arrays.copyOf(quiet,quiet.length+1);
sol=Arrays.copyOf(sol, sol.length+1);
quiet[quiet.length-1]=e.getKey();
sol[sol.length-1]=e.getValue();
}
for(int i=0;i for(int j=0;j if(sol[j] String cos=quiet[j];
quiet[j]=quiet[j+1];
quiet[j+1]=cos;
int a=sol[j];
sol[j]=sol[j+1];
sol[j+1]=a;
}else if(sol[j]==sol[j+1]) {
if(into(quiet[j])>into(quiet[j+1])) {
String cos=quiet[j];
quiet[j]=quiet[j+1];
quiet[j+1]=cos;
int a=sol[j];
sol[j]=sol[j+1];
sol[j+1]=a;
}
}
}
}
for(int i=0;i for(int j=1;j<=sol[i];j++) {
index=Arrays.copyOf(index,index.length+1);
index[index.length-1]=quiet[i];
}
}
return index;
}
public static int into(String str) {
if(str.equals("J")) {
return 11;
}else if(str.equals("Q")) {
return 12;
}else if(str.equals("K")) {
return 13;
}else if(str.equals("A")) {
return 14;
}else if(str.equals("2")) {
return 15;
}else if(str.equals("King")) {
return 16;
}else {
return Integer.parseInt(str);
}
}
}
package doudizhu;
public class Card implements Comparable{
public String toString() {
return "Card [sizes=" + sizes + ", points=" + points + "]";
}
/**
* 1表示黑色 11表示梅花 12表示黑桃
* 2表示红色 21表示红桃 22表示方片
*/
private String sizes; //花色
public Card() {
}
public Card(String sizes, String points) {
super();
this.sizes = sizes;
this.points = points;
}
private String points; //点数
public String getSizes() {
return sizes;
}
public void setSizes(String sizes) {
this.sizes = sizes;
}
public String getPoints() {
return points;
}
public void setPoints(String points) {
this.points = points;
}
public static int change(String str) {
String index=changeStep(str);
return Integer.parseInt(index);
}
public static String changeStep(String str) {
if(str.equals("J")) {
return "11";
}else if(str.equals("Q")) {
return "12";
}else if(str.equals("K")) {
return "13";
}else if(str.equals("A")) {
return "14";
}else if(str.equals("2")) {
return "15";
}else if(str.equals("King")) {
return "16";
}
else {
return str;
}
}
public boolean equals(Card card) {
return this.getPoints().equals(card.getPoints())&&this.getSizes().equals(card.getSizes());
}
public int compareTo(Card card) {
int thisSum=change(this.getPoints());
int cardSum=change(card.getPoints());
return thisSum-cardSum;
}
}
package doudizhu;
import java.util.ArrayList;
import java.util.List;
public class CardPlayers {
private List listCards=new ArrayList();
/**
* 这里还涉及到一个问题就是在Rules的检测中CardType是静态变量
* 存在这么一个情况,就是同一个人出牌了,其他人都没出牌了,这时应该把
* cardType初始化,变成一个全新的对象!
*/
public void play() {
List list =new ArrayList(); //自己要打的牌
checkMe(Rules.cardType, list); //这个值是true,表示出牌成功
playOne(Rules.cardType); //自己手中剩余的牌
ArrangeCard.cardHolder(Rules.cardType.getAllCard()); //记牌器的功能
}
/**
* 根据打出的牌看现在手里还有什么牌,方便提示打牌的时候用
* @param cardType
*/
public void playOne(CardType cardType) {
List list=cardType.getAllCard();
for(int i=0;i for(int j=0;j if(list.get(i).equals(listCards.get(j))) {
listCards.remove(j);
break;
}
}
}
}
/**
* 根据别人打过来的牌型,系统会判断玩家手中有没有比该牌更大的牌
* 没有的话,牌不能出,自己上方的有个按钮就是过
* 但是这里我并不是很想写,有很多种情况!不写提示功能
* 这里我这么来写打牌过程!
* 有两种状态,自己出牌参数CardType为null,自己出牌符合Rules规范就行!
* 别人出的牌就不为null,按照CardType里面的checkMore方法来规范就行
* @return
*/
public boolean checkMe(CardType cardType,List list) {
if(cardType.getCardType()==0) {
return Rules.check(list);
}else {
boolean flag=Rules.check(list);
if(flag) {
CardType type=Rules.cardType;
if(!type.checkMore(cardType)) {
return true;
}
}
return false;
}
}
public List getListCards() {
return listCards;
}
public void setListCards(List listCards) {
this.listCards = listCards;
}
}
package doudizhu;
import java.util.ArrayList;
import java.util.List;
/**
* 一副牌的数量
* @author dell
*
*/
public class Cards {
public static List cards=new ArrayList();
public static String[] listPoint={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
public static String[] listSizes={"11","12","21","22"};
static {
/**
* 大小王
*/
cards.add(new Card("1","King"));
cards.add(new Card("2","King"));
/**
* 52张牌
*/
for(int i=0;i String point=listPoint[i];
for(int j=0;j String sizes=listSizes[j];
Card card=new Card(sizes,point);
cards.add(card);
}
}
}
}
package doudizhu;
import java.util.List;
/**
* 牌型
* @author dell
*主体的定义
*/
public class CardType{
/**
* 比较牌的大小,看牌型和主体牌就行了
* 还要注意一点,就是牌的长度应该一样,但是还是除了BOOM牌型以外
* 但是BOOM牌型本身也是遵循这个规律,但是BOOM
* 牌型里面最大的是长度为2的王炸
*/
private List mainPartCard;
/**
* 为什么定义所有牌,因为要传递,方便记牌器的功能
*/
private List allCard;
private int cardType;
/**
* 牌型的大小
* 如果牌型相同,比较牌的主体的大小
* 当然有个特例,那就是BOOM牌型可以大于其他牌型
* 这一点在比较的过程中要注意,还有就是提示打牌的时候
* @return
*/
public List getMainPartCard() {
return mainPartCard;
}
public void setMainPartCard(List mainPartCard) {
this.mainPartCard = mainPartCard;
}
public List getAllCard() {
return allCard;
}
public void setAllCard(List allCard) {
this.allCard = allCard;
}
public int getCardType() {
return cardType;
}
public void setCardType(int cardType) {
this.cardType = cardType;
}
/**
*
* @param cardType
* @return 返回true表示牌型小于或则相等,返回false表示大于该牌
*/
public boolean checkMore(CardType cardType) {
if(this.getCardType()==cardType.getCardType()) {
Card thisCard=pickMax(this.getMainPartCard());
Card card=pickMax(cardType.getMainPartCard());
boolean flag=thisCard.compareTo(card)>0&&this.getAllCard().size()==cardType.getAllCard().size();
if(flag) {
return false;
}else {
return true;
}
}else {
if(this.getCardType()==Constant.BOOM) {
return false;
}else {
return true;
}
}
}
/**
* 在一堆牌中找到最大的那张牌,也可以是最小的牌
* 因为要找的是主体牌,不用担心有什么奇怪的事情出现
* 因为在斗地主的过程中判断牌的大小是看主体牌的大小,这里有时候主体牌和
* 所有的牌相同,有时候不同
*/
public static Card pickMax(List list) {
Card card=null;
for(int i=0;i if(i==0) {
card=list.get(i);
}else {
int a=card.compareTo(list.get(i));
if(a<0) {
card=list.get(i);
}
}
}
return card;
}
}
package doudizhu;
public interface Constant{
/**
* 牌型
* 为了方便提示出牌的!
* 只有比它打的牌型会有提示出牌的机会,否则只能选择要不起
* 在没有其他人压制自己牌或者自己是一个结算的结算终方,那么就不会提示出牌
*/
public static final int SINGLE=1; //单张
public static final int DOUBLE=2; //对子
public static final int STRAIGHT=3; //顺子
public static final int LINEDOUBLE=4; //连对
public static final int THREE=5; //三不带
public static final int THREEFORONE=6; //三带一
public static final int AIRPLANE=7; //飞机
public static final int AIRPLANEWING=8; //飞机加翅膀
public static final int BOOM=9; //炸弹
public static final int FOURFORTWO=10; //四带二
}
package doudizhu;
import java.util.ArrayList;
import java.util.List;
/**这个也是能够写前端的,用户把牌点起来是一个事件
* 点完了之后,有个确认按钮,这个会做以下几个事情
* 按照我的Java类写的先排序,然后进行规则验证
* 如果返回的是true,才能发出去,不然自己点的牌还是
* 会被放下来,如果是一般的斗地主软件,那么在玩家进入到
* 一个房间过后,你的地址和端口号固定了,每次你要往外面发的数据,也是固定了
* 这样就方便了数据的传输,我想应该是基于cs的连接,不知道是直接按照它的规则是
* 玩家之间传输数据的,还是要走它的服务器!当然我觉得向斗地主这样的游戏,直接玩家直连就行了
* 在我这里Rules检验通过过后,会传递一个CardType类!
*
* @author dell
*
*/
public class PlayGame {
public static void allStep(){
//第一步 洗牌
//WashCard.randomDisorder();
//第二步 发牌
//SendCard.sendCard();
//List list=SendCard.list;
//第三步 整理牌
//for(int i=0;i // ArrangeCard.arrange(list.get(i).getListCards());
//}
//第四步 叫地主实时插入牌
//某一个玩家叫上地主过后把这个牌加入到他的手牌里面!
//List overPlus=SendCard.overPlus;
//list.get(0).getListCards().addAll(overPlus);
//list.get(0).setListCards(ArrangeCard.arrange(list.get(0).getListCards()));
//第五步 记牌器加载,实时根据自己的牌和其他玩家出掉的牌,统计剩余的牌
//第六步 打牌 首先是提起了排序,如果不符合打牌规范则返回false
List list=new ArrayList();
Card card1=new Card("11","3");
Card card2=new Card("12","3");
Card card3=new Card("21","3");
Card card4=new Card("11","4");
Card card5=new Card("12","4");
Card card6=new Card("21","4");
Card card7=new Card("11","6");
Card card8=new Card("12","6");
list.add(card1);
list.add(card2);
list.add(card3);
list.add(card4);
list.add(card5);
list.add(card6);
list.add(card7);
list.add(card8);
List card=ArrangeCard.arrangePlay(list);
//第七步 打牌的时候,符合要求的牌会记录牌型和主体牌和副题牌,还有就是那些牌,以便提示下一位玩家出牌和记牌器的工作
Rules.check(card);
CardType cardType=Rules.cardType;
System.out.println(cardType.getCardType());
}
/**
* 当然也可以设计一下打牌的过程
* 每个人的记牌器是一个独立的线程,对于其他的东西没有任何的影响
* 但是每个人的出牌都是有限制的!
* 第一你发起进攻,必须有牌型的限制
* 你是接受进攻的,你的出牌要大于当前牌还有就是顺时针玩家转的依次出牌
* @param args
*/
public static void main(String[] args) {
allStep();
}
}