Java2024/src/chapter6/demo64/Player.java

38 lines
689 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;
// Player.java - 玩家类
public class Player {
private String name;
private ArrayList<Card> hand = new ArrayList<>();
public Player(String name) {
this.name = name;
}
/**
* 接收一张牌
* @param card 收到的牌
*/
public void receiveCard(Card card) {
hand.add(card);
}
/**
* 整理手牌
*/
public void sortHand() {
Collections.sort(hand);
}
/**
* 显示手牌
* @return 手牌的字符串表示
*/
public String showHand() {
return name + "" + hand.toString();
}
}