-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
71 lines (59 loc) · 1.78 KB
/
Copy pathTile.java
File metadata and controls
71 lines (59 loc) · 1.78 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
// CSE 143, Homework 1, Tiles
// A Tile object represents a 2D rectangular tile with a
// top-left x/y coordinate, width, height, and fill color.
import java.awt.Color;
import java.awt.Graphics;
public class Tile {
private int x; // top-left x/y
private int y;
private int width;
private int height;
private Color color; // fill color
// Constructs a new tile with the given coordinates, size, and color.
public Tile(int x, int y, int w, int h, Color c) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
this.color = c;
}
// Draws this tile using the given graphics pen.
public void draw(Graphics g) {
g.setColor(color);
g.fillRect(x, y, width, height);
g.setColor(Color.BLACK);
g.drawRect(x, y, width, height);
}
// Returns this tile's leftmost x coordinate.
public int getX() {
return x;
}
// Returns this tile's topmost y coordinate.
public int getY() {
return y;
}
// Returns this tile's width.
public int getWidth() {
return width;
}
// Returns this tile's height.
public int getHeight() {
return height;
}
// Returns this tile's color.
public Color getColor() {
return color;
}
// Sets this tile's leftmost x-coordinate to be the given value.
public void setX(int x) {
this.x = x;
}
// Sets this tile's topmost y-coordinate to be the given value.
public void setY(int y) {
this.y = y;
}
// Returns a text representation of this tile, such as "(x=57,y=148,w=26,h=53)".
public String toString() {
return "(x=" + x + ",y=" + y + "),w=" + width + ",h=" + height + ")";
}
}