Java2024/src/chapter6/demo64/Player.java
2024-12-05 09:38:36 +08:00

37 lines
752 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chapter6.demo64;
import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeSet;
// Player.java - 玩家类
public class Player {
private String name;
// Card类已经实现Comparable接口可以使用TreeSet自动排序
private TreeSet<Card> hand = new TreeSet<>();
/**
* 构造函数
* @param name 玩家名称
*/
public Player(String name) {
this.name = name;
}
/**
* 接收一张牌
* @param card 收到的牌
*/
public void receiveCard(Card card) {
hand.add(card);
}
/**
* 显示手牌
* @return 手牌的字符串表示
*/
public String showHand() {
return name + "" + hand.toString();
}
}