-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.java
65 lines (46 loc) · 1.21 KB
/
Point.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
import java.util.concurrent.ThreadLocalRandom;
enum Direction { HORIZONTAL, VERTICAL };
class Point
{
public int x_coord;
public int y_coord;
// default const.
public Point() //Initialize (x,y) for Point object
{
this.x_coord = 0;
this.y_coord = 0;
}
// parameterized const.
public Point(int x_coord, int y_coord)
{
this.x_coord = x_coord;
this.y_coord = y_coord;
}
// getter methods
public int getcordX()
{
return this.x_coord;
}
public int getcordY()
{
return this.y_coord;
}
// method to check tht givn point is valid on the board or not
boolean isValidPoint()
{
if((this.x_coord >= 0 && this.x_coord <= 9 ) && (this.y_coord >= 0 && this.y_coord <= 9)) return true;
else return false;
}
// create a Point object and call below method to generate a random pointer
public Point GenerateRandomPoint()
{
int randomNum,randomNum2;
randomNum = ThreadLocalRandom.current().nextInt(0, 9 + 1);
//System.out.println(randomNum);
randomNum2 = ThreadLocalRandom.current().nextInt(0, 9 + 1);
//System.out.println(randomNum2);
this.x_coord = randomNum;
this.y_coord = randomNum2;
return this;
}
}