-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightSource.java
More file actions
108 lines (94 loc) · 2.99 KB
/
LightSource.java
File metadata and controls
108 lines (94 loc) · 2.99 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
import java.awt.Color;
import java.awt.Graphics;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
* A simple "agent" that doesn't move or behave.
* The "light source" name reflects the fact that
* this agent shows up in a percept as being of
* category "light".
*
* @author Matthew Stone
* @version 1.0
*/
public class LightSource extends Agent {
/**
* Class information
*/
/** XML element tag */
static final String XML_NAME = "light";
/** Record that allows XML files to set light defaults */
static FixedAgentAttributes defaultFixedAgentAttributes =
new Agent.FixedAgentAttributes(10, 0, 0, 0, 0, 0, 0, HALF_CIRCLE, Color.YELLOW, false, false);
/** Record that allows XML files to set light defaults */
static DynamicAgentAttributes defaultDynamicAgentAttributes =
new Agent.DynamicAgentAttributes(250, 250, 0, 0);
/**
* Constructor: initialize general agent fields to describe
* agent that does not move.
*
* @param w world to which agent belongs
* @param id number to identify agent in its world
* @param x horizontal coordinate where agent appears
* @param y vertical coordinate where agent appears
*/
public LightSource(World w, int id, Attributes atts, Locator loc)
throws SAXException {
myWorld = w;
this.id = id;
form = new FixedAgentAttributes(atts, defaultFixedAgentAttributes, loc);
status = new DynamicAgentAttributes(atts, defaultDynamicAgentAttributes, loc);
}
/**
* Output an XML element describing the current state of
* this light source.
*
* @param out an open file to write to, wrapped in BufferedWriter
* convenience class
*/
@Override
public void log(BufferedWriter out)
throws IOException {
out.write(" <" + XML_NAME + " " + ID_PARAM + OPEN + Integer.toString(id) + CLOSE +
"\n ");
form.log(out);
out.write(" ");
status.log(out);
out.write(" />\n");
}
/**
* Draw a light source as a filled circle.
*
* @param g object to control drawing mechanism
*/
@Override
public void draw(Graphics g) {
g.setColor(form.color);
g.fillOval((int) Math.round(status.locX - form.size/2),
(int) Math.round(status.locY - form.size/2),
form.size, form.size);
}
/**
* describe the light source as other agents see it
*
* @return how the light source appears: as a light
*/
@Override
public Percept.ObjectCategory looksLike() {
return Percept.ObjectCategory.LIGHT;
}
/**
* Never do anything
*
* @param ps what the light source would "see"
*/
@Override
public void deliberate(List<Percept> ps) {
todo = new LinkedList<Intention>();
}
}