-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
190 lines (166 loc) · 5.08 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
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
import java.util.*;
public class Player extends Monster {
//////////////////////////////////////////////////////////////////////////////////////////////////
// attributes
//////////////////////////////////////////////////////////////////////////////////////////////////
private ArrayList<Item> pack = new ArrayList<Item>(0);
private int exp;
private int playerx;
private int playery;
//////////////////////////////////////////////////////////////////////////////////////////////////
// default Constructor hp/atk/def/spd
//////////////////////////////////////////////////////////////////////////////////////////////////
public Player(String n, int hp, int atk, int def, int spd) {
super(n, hp, atk, def, spd);
exp = 0;
pack = new ArrayList<Item>(0);
playerx = 0;
playery = 0;
exp = 0;
}
public String taunt() {
return "";
}
public String talkTo() {
return "";
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// getters and setters
//////////////////////////////////////////////////////////////////////////////////////////////////
public ArrayList<Item> getItems() {
return pack;
}
public int getXp() {
return exp;
}
public int getX() {
return playerx;
}
public int getY() {
return playery;
}
public boolean levelup() {
if (exp >= 100)
return true;
return false;
}
public void setXY(int x, int y) {
playerx = x;
playery = y;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// print items and add items
//////////////////////////////////////////////////////////////////////////////////////////////////
public void getPack() {
for (int i = 0; i < pack.size(); i++) {
System.out.println(pack.get(i).getItem());
}
}
public void additem(int id) {
pack.add(new Item(id));
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// add xp
//////////////////////////////////////////////////////////////////////////////////////////////////
public void addXp(int xp) {
exp = exp + xp;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// level up
//////////////////////////////////////////////////////////////////////////////////////////////////
public void levelAtk() {
exp -= 100;
super.atkInc(5);
}
public void levelDef() {
exp -= 100;
super.defInc(5);
}
public void levelSpd() {
exp -= 100;
super.defInc(5);
}
public void levelHp() {
exp -= 100;
super.healthInc(10);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// inspect self
//////////////////////////////////////////////////////////////////////////////////////////////////
public String inspect() {
return ("You are an explorer named " + super.getName() + ". You have " + super.getAtk() + " attack, "
+ super.getDef() + " defense, and " + super.getSpd() + " Speed. \n You have " + super.getHp()
+ " Health remaining out of " + super.getMHp());
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// using an item, input an id to decide
//////////////////////////////////////////////////////////////////////////////////////////////////
public void useItem(int i) {
int itemid = -1;
for (int x = 0; x < pack.size(); x++) {
if (pack.get(x).equals(i)) {
itemid = x;
break;
}
}
if (itemid == -1) {
System.out.println("You dont have that item.");
} else {
if (i == 0) {
System.out.println("You gain ten health!");
super.healthInc(10);
} else if (i == 1) {
System.out.println("You gain five speed!");
super.spdInc(5);
} else if (i == 2) {
System.out.println("You gaina five defense!");
super.defInc(5);
} else if (i == 3) {
System.out.println("You gain five attack!");
super.atkInc(5);
}
pack.remove(i);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// testing if the player has an item
//////////////////////////////////////////////////////////////////////////////////////////////////
public boolean hasItem() {
return (pack.size() >= 1);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// moving directions on the map
//////////////////////////////////////////////////////////////////////////////////////////////////
public String goNorth(Map M)// north
{
if (playerx > 0) {
playerx--;
return "You move north.";
} else
return "You cannot move any further north!";
}
public String goSouth(Map M)// south
{
if (playerx < M.getLength()) {
playerx++;
return "you move south.";
} else
return "you cannot move any further south!";
}
public String goEast(Map M)// east
{
if (playery < M.getLength()) {
playery++;
return "you move east.";
} else
return "you cannot move any further east!";
}
public String goWest(Map M)// west
{
if (playery > 0) {
playery--;
return "You move west.";
} else
return "you cannot move any further west!";
}
}