-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
277 lines (239 loc) · 8.53 KB
/
Player.java
File metadata and controls
277 lines (239 loc) · 8.53 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import java.util.*;
import java.io.*;
/**
* This class implements the behaviour expected from the CODE
* system as required for 5COM0087 Cwk 3 - Feb 2014
*
* @author A.A.Marczyk
* @version 02/02/14
*/
public class Player implements Game
{
private String name;
private int treasury;
private ArrayList<Champion> allChampions = new ArrayList<Champion>();
private ArrayList<Challenge> allChallenges = new ArrayList<Challenge>();
//**************** DiscEarth **************************
/** Constructor requires the name of the player
* @param player is the name of the player
*/
public Player(String player)
{
name = player;
treasury = 1000;
setupChampions();
setupChallenges();
}
/** Constructor requires the name of the player and the
* name of the file storing champions
* @param player is the name of the player
* @param filename name of file storing champions
*/
public Player(String player, String filename)
{
name = player;
treasury = 1000;
readChampions(filename); // read from text file
//comment for testing Task 5
setupChallenges();
// uncomment for testing Task 5
// readChallenges();
}
/**Returns the name of the player
* @return is the name of the player
**/
public String getName()
{
return name;
}
/**Returns a String representation of the state of the game,
* including the name of the player, state of the treasury,whether
* player has lost or is still OK, and the champions in the army
* (or, "No champions" if army is empty)
* @return a String representation of the state of the game,
* including the name of the player, state of the treasury, whether
* player has lost or is still OK, and the champions in the army
* (or, "No champions" if army is empty)
**/
public String toString()
{
String s = "\nPlayer: " + name ;
s = s + "\nTreasury: " + treasury;
if (hasLost())
{
s = s + "\nYou have lost \n" ;
}
else
{
s = s + "\nYou are still OK \n" ;
}
// add the army to this String, or "no Champions in the army"
return s;
}
/** returns the amount of money in the treasury
* @returns the amount of money in the treasury
*/
public int getMoney()
{
return treasury;
}
/** returns true if treasury <=0 and the army has no champions
* who can be dismissed.
* @returns true if treasury <=0 and the army has no champions
* who can be dismissed.
*/
public boolean hasLost()
{
return false;
}
// ***************** Army of Champions ************************
/**Returns a String representation of all champions available for hire
* @return a String representation of all champions available for hire
**/
public String getAllChampionsForHire()
{
return null;
}
/** Returns details of a champion with the given name
* @return details of a champion with the given name
**/
public String getChampion(String name)
{
return null;
}
// ***************** Army Champions ************************
/** Allows a champion to be hired for the army, if there
* is enough money in the treasury for their hire fee.The champion's
* state is set to "active"
* @param name is the name of the champion
* @return name and either "- not found" if champion not found,or "- cannot
* be hired" if champion is not for hire,already hired/dead, "- hired and
* avialable" if champion hired, "- not enough money" if not enough money
* in the treasury
**/
public String hireChampion(String name)
{
return null;
}
/**Returns a String representation of the champions in the player's army
* with an appropriate header, or the message "No champions hired"
* @return a String representation of the champions in the player's army
**/
public String getArmy()
{
return null;
}
/** Returns true if the champion with the name is in the player's army,
* false otherwise.
* @param name is the name of the champion
* @return true if the champion with the name is in the player's army,
* false otherwise.
**/
public boolean isInArmy(String name)
{
return false;
}
/** Dismisses a champion from the army and add half of their hire fee
* to the treasury.Champion must be active or resting.Champion should
* now be for hire.
* pre-condition: isInArmy(name)and is not dead
* @param name is the name of the champion
* @return true if dismissed, else false
**/
public boolean dismissChampion(String name)
{
return false;
}
/**Restores a champion to the army by setting their state to ACTIVE
* @param the name of the champion to be restored
* @return true if restored, else false
*/
public boolean restoreChampion(String name)
{
return false;
}
//**********************Challenges*************************
/** returns true if the number represents a challenge
* @param num is the reference number of the challenge
* @returns true if the reference number represents a challenge
**/
public boolean isChallenge(int num)
{
return false ;
}
/** Meets the challenge represented by the challenge number (or returns
* " - no such challenge").Find a champion from the army who can meet the
* challenge and return a result which is one of the following: “Challenge
* won by...“ – add reward to treasury, set the champion to restingand add
* the name of champion, “Challenge lost as no champion available” – deduct
* reward from treasury,“Challenge lost on skill level”- deduct reward from
* treasury, the champion is killed, so add "<champion name> is dead" to the
* return String. If the challenge is lost and there is no money left, add
* "You have NO money in the treasury".
* @param challNo is the reference number of the challenge
* @return a String showing the result of meeting the challenge
*/
public String meetChallenge(int challNo)
{
return null;
}
/** Provides a String representation of a challenge given by challenge number
* pre-condition isChallenge(num)
* @param num the number of the challenge
* @return returns a String representation of a challenge given by
* the challenge number
**/
public String getChallenge(int num)
{
return null;
}
/** Provides a String representation of all requests
* @return returns a String representation of of all requests
**/
public String getAllChallenges()
{
return null;
}
//*********************** Task 1 ***********************************************
private void setupChampions()
{
// depends on your collections
}
private void setupChallenges()
{
// depends on your collections
}
//*******************************************************************************
/************************ Task 5 ************************************************/
/** reads data about champions from a text file and stores in collection of
* champions.Data in the file is "comma separated" and so editable
* @param fileName name of the file to be read
*/
private void readChampions(String fileName)
{
}
//************************ Task 6 **********************************
/** reads data about challenges from an object file and stores in collection of
* champions.Data in the file is not editable
* @param fileName name of the file to be read
*/
private void readChallenges()
{
}
// ******************** Task 6 object write/read *********************
/**
* Saves the state of the game to the file with the given name
* @param filename the name of the file
*/
public void saveGame(String fname)
{ // uses object serialisation
}
/**
* Restores the game from the file with the given name
* @param filename the name of the file
*/
public Game restoreGame(String fname)
{ // uses object serialisation
return null;
}
}