-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColoredObject.java
161 lines (133 loc) · 2.56 KB
/
ColoredObject.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
/**
* ColoredObject.java
* The parent class of any object in Cloney Circle that has a color
*
* @author Kyle Mitard
*
* 23 March 2019
*/
package cloney_circle;
import java.awt.Color;
import java.awt.Graphics;
public abstract class ColoredObject
{
//INSTANCE VARIABLES-----------------------------------------------------------------
/**
* the current coordinates of the object
*/
private int x, y;
/**
* the coordinates of the object when it was last drawn
*/
private int oldX, oldY;
/**
* the object's color
*/
private Color color;
//METHODS----------------------------------------------------------------------------
/**
* Constructor
*
* @param xCoord the ColoredObject's initial x coordinate
* @param yCoord the ColoredObject's initial y coordinate
* @param c the ColoredObject's initial color
*/
public ColoredObject(int xCoord, int yCoord, Color c)
{
x = xCoord;
y = yCoord;
color = c;
setOldCoords();
}
/**
* Checks the colors of two ColoredObjects
*
* @param co another ColoredObject
*
* @return true if the two colored objects are the same color
*/
public boolean equals(ColoredObject co)
{
return color.equals(co.getColor());
}
/**
* returns the y-coordinate
*
* @return the object's y-coordinate
*/
public int getY()
{
return y;
}
/**
* returns the x-coordinate
*
* @return the object's x-coordinate
*/
public int getX()
{
return x;
}
/**
* returns the object's color
*
* @return the object's color
*/
public Color getColor()
{
return color;
}
/**
* changes the object's color
*
* @param newColor the new color
*/
public void setColor(Color newColor)
{
color = newColor;
}
/**
* moves a ColoredObject
*
* @param newX the new x-coordinate
* @param newY the new y-coordinate
*/
public void move(int newX, int newY)
{
x = newX;
y = newY;
}
/**
* sets the coordinates of where the ColoredObject was last drawn to the current coordinates.
* @see the draw() methods in subclasses
*/
public void setOldCoords()
{
oldX = x;
oldY = y;
}
/**
* gets the old x-coordinate
*
* @return the x-coordinate of the object when it was last drawn
*/
public int getOldX()
{
return oldX;
}
/**
* gets the old y-coordinate
*
* @return the y-coordinate of the object when it was last drawn
*/
public int getOldY()
{
return oldY;
}
/**
* draws the ColoredObject
*
* @param g the Graphics object the ColoredObject will be drawn on
*/
public abstract void draw(Graphics g);
}