Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / client / RobotIcon.java @ 763

History | View | Annotate | Download (1.21 KB)

1 644 gtress
2
import javax.swing.*;
3
import javax.swing.event.*;
4
import javax.imageio.*;
5
import java.awt.*;
6
import java.awt.image.*;
7
import java.awt.event.*;
8
import java.net.*;
9
import java.io.*;
10
import java.util.*;
11
12
/**
13
*         RobotIcon class
14
*         Provides a means for graphically representing and keeping track of webcam bots.
15
*/
16
public class RobotIcon {
17
18
        public int x, y;
19
        public int destx, desty;
20
        public int id;
21
        public Color color;
22
        public int battery;
23
24
        public RobotIcon (int id, int x, int y) {
25
                this.color = Color.RED;
26
                this.x = x;
27
                this.y = y;
28
                this.id = id;
29
                this.destx = -1;
30
                this.desty = -1;
31
                this.battery = -1;
32
        }
33
34
        /**
35
        *         Relocates this RobotIcon to a new coordinate point.
36
        *
37
        */
38
        public void move (int newX, int newY) {
39
                this.x = newX;
40
                this.y = newY;
41
        }
42
43
        /**
44
        *         Determines whether a given point is within the rectangle that circumscribes the
45
        *         robot's circlular icon. Used for clicking on robots in webcam view.
46
        *
47
        */
48
        public boolean contains (int px, int py) {
49 701 gtress
        int radius = ColonetConstants.ROBOT_RADIUS;
50
                Rectangle rect = new Rectangle(x-radius, y-radius, 2*radius, 2*radius);
51 644 gtress
                return rect.contains(px, py);
52
        }
53
54
        public String toString () {
55
                String s = "RobotIcon at (" + x + "," + y + "), id " + id;
56
                return s;
57
        }
58
}