-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.java
153 lines (115 loc) · 2.79 KB
/
Player.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.ArrayList;
/**
* This class repersent a player int Run class
* it holds the player score, password and player cards
*
* its extends from the person class
*
*
*
* @author Mohammad Mahdi Malmasi
* @version 0.2.0
*
* @see Person
*/
public class Player extends Person
{
/* Feilds */
// the score of the player
protected int score;
// the password of the player in the game
private String playerPass;
// a list of player cards
private ArrayList<Card> playerCards;
/* Constructor */
/**
* Create a new Pleyer with given name and password
*
* @param firstName : name of the player
* @param playerPass : password of player
*/
public Player(String firstName, String playerPass)
{
// set the super class
super(firstName, "nevermind", 0, "nevermind");
this.score = 0;
this.playerPass = playerPass;
playerCards = new ArrayList<>();
}
/* Methods */
// * getter methods *
/**
* @return : the score of the player
*/
public int getScore()
{
return score;
}
/**
* @return : the password of the player
*/
public String getPlayerPass()
{
return playerPass;
}
/**
* @return the player Cards
*/
public ArrayList<Card> getPlayerCards()
{
return playerCards;
}
/**
* @return the number of the player cards
*/
public int getNumberOfPlayerCards()
{
return playerCards.size();
}
/**
* Add a new card to player cards
*
* @param cardToAdd : new card to add
*/
public void addCard(Card cardToAdd)
{
score += cardToAdd.getCardScore();
playerCards.add(cardToAdd);
}
/**
* Remove a card from player cards
*
* @param cardCodeToRemove
* @return the removed Card
*/
public Card removeCard(int cardCodeToRemove)
{
Card cardToRemove = null;
for (Card card: playerCards)
{
if (card.getCardCode() == cardCodeToRemove)
{
cardToRemove = card;
break;
}
}
score -= cardToRemove.getCardScore();
playerCards.remove(cardToRemove);
return cardToRemove;
}
/**
* This method check that the player have a card with given code number or not
*
* @param cardCode : the code of card that you want to check
* @return {@code true} if player have card with given code number
*/
public boolean haveCard(int cardCode)
{
for (Card card: playerCards)
{
if (card.getCardCode() == cardCode)
return true;
}
return false;
}
}