-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNPC.java
More file actions
150 lines (130 loc) · 4.26 KB
/
NPC.java
File metadata and controls
150 lines (130 loc) · 4.26 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
// this class contains the code for the NPC class
// these import the libraries to draw the npc
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
public class NPC {
// these are the npc's instance variables
private int x;
private int y;
private int startX;
private int startY;
private int wantedStateIndex;
private Image npc;
private Image npc2;
private Image npc3;
private boolean inRange;
private boolean alreadyTalkedTo;
private String preMessage;
private String textMessage;
private String endMessage;
private String preMessage2;
private String textMessage2;
private String wantedState;
private String name;
private Item linkedItem;
// this constructs the npc with passed in x, y, index, item, and state values
public NPC(int x, int y, int wantedIndex, Item item, String state) {
startX = x;
startY = y;
wantedStateIndex = wantedIndex;
this.x = startX;
this.y = startX;
npc = Toolkit.getDefaultToolkit().createImage("npcImage.gif");
npc2 = Toolkit.getDefaultToolkit().createImage("npcImage2.gif");
npc3 = Toolkit.getDefaultToolkit().createImage("npcImage3.gif");
inRange = false;
alreadyTalkedTo = false;
if (item.getName().equals("Coin")) {
preMessage = "";
textMessage = "Hello! To get the "+item.getName()+",";
textMessage2 = "look around and find it you lazy bum";
endMessage = "Thanks for finding the "+item.getName()+". Talk to the weaponsmith for the next quest.";
name = "Farmer";
} else if (item.getName().equals("Sword")) {
preMessage = "Sorry, I am a little bit preoccupied with my work.";
preMessage2 = "Talk to me after you finish the farmer's quest.";
textMessage = "I seem to have misplaced my sword somewhere.";
textMessage2 = "Can you find it for me?";
endMessage = "Thanks for finding the "+item.getName()+". Talk to the mage for the next quest.";
name = "Weaponsmith";
} else {
preMessage = "Sorry, I am busy brewing potions. Talk to me after you";
preMessage2 = "finish the farmer's and the weaponsmith's quest.";
textMessage = "I was brewing some potions but I may have";
textMessage2 = "dropped one on the floor. Can you find it?";
endMessage = "Thanks for finding the "+item.getName();
name = "Mage";
}
linkedItem = item;
wantedState = state;
}
// this draws the npc
public void draw(Graphics g, int xDiff, int yDiff) {
if (linkedItem.getName().equals("Coin")) {
g.drawImage(npc, x+xDiff, y+yDiff, 64, 64, null);
} else if (linkedItem.getName().equals("Sword")) {
g.drawImage(npc2, x+xDiff, y+yDiff, 64, 64, null);
} else {
g.drawImage(npc3, x+xDiff, y+yDiff, 64, 64, null);
}
}
// these methods are methods used to either change or return the npc's instance variables
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getStartX() {
return startX;
}
public int getStartY() {
return startY;
}
public int getWantedIndex() {
return wantedStateIndex;
}
public void changeX(int x) {
this.x = x;
}
public void changeY(int y) {
this.y = y;
}
public boolean getInRange() {
return inRange;
}
public boolean getTalkedTo() {
return alreadyTalkedTo;
}
public String getPreMessage() {
return preMessage;
}
public String getMessage() {
return textMessage;
}
public String getEndMessage() {
return endMessage;
}
public String getPreMessage2() {
return preMessage2;
}
public String getMessage2() {
return textMessage2;
}
public String getPromptedState() {
return wantedState;
}
public String getName() {
return name;
}
public void changeRange(boolean inRange) {
this.inRange = inRange;
}
public void changeTalkedTo(boolean talked) {
alreadyTalkedTo = talked;
}
public Item getRelatedItem() {
return linkedItem;
}
}