其实还是有一些错误的,很多功能懒得实现了,顺子方面我实现不来,好吧主要还是偷懒,仅供参考,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