This commit is contained in:
seahi 2024-12-05 08:54:54 +08:00
parent 8aa6947e2b
commit c99f6f67b2
3 changed files with 16 additions and 4 deletions

View File

@ -2,9 +2,9 @@ package chapter6.demo64;
// Card.java - 扑克牌类 // Card.java - 扑克牌类
public class Card implements Comparable<Card> { public class Card implements Comparable<Card> {
private String color; // 花色 private final String color; // 花色
private String point; // 点数 private final String point; // 点数
private int index; // 编号 private final int index; // 编号
/** /**
* 构造一张扑克牌 * 构造一张扑克牌
@ -25,6 +25,14 @@ public class Card implements Comparable<Card> {
@Override @Override
public int compareTo(Card other) { public int compareTo(Card other) {
// if (this.index == other.index) {
// return 0;
// } else if (this.index > other.index) {
// return 1;
// } else {
// return -1;
// }
// 谁的index小谁排在前面
return this.index - other.index; return this.index - other.index;
} }

View File

@ -38,7 +38,7 @@ public class Deck {
*/ */
public Card dealCard() { public Card dealCard() {
if (!cards.isEmpty()) { if (!cards.isEmpty()) {
return cards.remove(0); return cards.removeFirst();
} }
return null; return null;
} }

View File

@ -9,6 +9,10 @@ public class Player {
private String name; private String name;
private ArrayList<Card> hand = new ArrayList<>(); private ArrayList<Card> hand = new ArrayList<>();
/**
* 构造函数
* @param name 玩家名称
*/
public Player(String name) { public Player(String name) {
this.name = name; this.name = name;
} }