-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinate.java
More file actions
103 lines (93 loc) · 2.29 KB
/
Coordinate.java
File metadata and controls
103 lines (93 loc) · 2.29 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
/**
* Violet Monserate
* 10/11/2023
* CSE 123
* Section 0 Creative Project: Abstract Strategy Game
* TA: Hawa
*/
/**
* Helper class to represent the position of any counter on the board.
*/
public class Coordinate
{
private int xCoord;
private int yCoord;
/**
* Creates a new coordinate with the given x and y coordinates.
*
* @param x the value we want to set the x coordinate to
* @param y the value we want to set the y coordinate to
*/
public Coordinate(int x, int y)
{
this.xCoord = x;
this.yCoord = y;
}
/**
* Sets both the x and y coodinate of this object.
*
* @param x the value we want to set the x coordinate to
* @param y the value we want to set the y coordinate to
*/
public void setCoordinate(int x, int y)
{
setX(x);
setY(y);
}
/**
* Sets the x coordinate.
*
* @param x the value we want to set the x coordinate to
*/
public void setX(int x)
{
this.xCoord = x;
}
/**
* Sets the y coordinate.
*
* @param y the value we want to set the x coordinate to
*/
public void setY(int y)
{
this.yCoord = y;
}
/**
* Gets the x coordinate (integer).
*
* @return the current x coordinate value
*/
public int getX()
{
return xCoord;
}
/**
* Gets the y coordinate (integer).
*
* @return the current y coordinate value
*/
public int getY()
{
return yCoord;
}
/**
* Checks whether this coordinate is contained within the 1st quadrant, with a top bound.
*
* @param topBound The largest number we can use, EXCLUSIVE
* @return whether the number is within the grid or not
*/
public boolean isValid(int topBound)
{
return xCoord >= 0 && xCoord < topBound && yCoord >= 0 && yCoord < topBound;
}
/**
* Compares two coodinates and sees if they have the same x and y (same point on grid).
*
* @param otherPoint the other point we are checking against
* @return whether it is on top of the other point or not!
*/
public boolean isEqualTo(Coordinate otherPoint)
{
return xCoord == otherPoint.getX() && yCoord == otherPoint.getY();
}
}