- a client state machine consits out of a 'ClientState' (every state of the machine) and a 'ClientStateMachine' (every state, which consists out of states), the machine starts with the ClientAutomaton - analog for server - started to implement logic for the server, transition from 'Lobby' to 'GameState'
92 lines
2.1 KiB
Java
92 lines
2.1 KiB
Java
package pp.mdga.game;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* This class will be used to handle general PlayerData
|
|
*/
|
|
public class Player {
|
|
|
|
private String name;
|
|
private Statistic playerStatistic;
|
|
private ArrayList<BonusCard> handCards;
|
|
private final int id;
|
|
|
|
/**
|
|
* This constructor constructs a new Player object
|
|
*/
|
|
public Player(int id) {
|
|
this.id = id;
|
|
playerStatistic = new Statistic();
|
|
handCards = new ArrayList<>();
|
|
}
|
|
|
|
/**
|
|
* This method returns the give name of the Player
|
|
*
|
|
* @return the name of the player as a String
|
|
*/
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* This method sets the name of the player
|
|
*
|
|
* @param name the new name of the player
|
|
*/
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
/**
|
|
* This methode returns the statistics of the player
|
|
*
|
|
* @return the statistics of the player
|
|
*/
|
|
public Statistic getPlayerStatistic() {
|
|
return playerStatistic;
|
|
}
|
|
|
|
/**
|
|
* This method returns the current handCards of the player
|
|
*
|
|
* @return the handCards of the player
|
|
*/
|
|
public ArrayList<BonusCard> getHandCards() {
|
|
return handCards;
|
|
}
|
|
|
|
/**
|
|
* This method adds a new handCard to the player
|
|
*
|
|
* @param card the card to be added to the players hand
|
|
*/
|
|
public void addHandCards(BonusCard card){
|
|
handCards.add(card);
|
|
}
|
|
|
|
/**
|
|
* This method returns a BonusCard to be removed from the players hand.
|
|
*
|
|
* @param card the cards type to be removed
|
|
* @return the removed card or null if there is none of that card type
|
|
*/
|
|
public BonusCard removeHandCard(BonusCard card) {
|
|
BonusCard cardToRemove = handCards.stream().filter(c -> c.equals(card)).findFirst().orElse(null);
|
|
if (cardToRemove != null) {
|
|
handCards.remove(cardToRemove);
|
|
}
|
|
return cardToRemove;
|
|
}
|
|
|
|
/**
|
|
* Returns the id of the connection to the client represented by this player.
|
|
*
|
|
* @return the id
|
|
*/
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
}
|