-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
77 lines (67 loc) · 2.05 KB
/
Point.java
File metadata and controls
77 lines (67 loc) · 2.05 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
package com.purdue.LawsonNavigator;
import java.io.*;
import java.util.*;
import java.io.Serializable;
public class Point implements Serializable{
private int x;
private int y;
public static void main(String[] args) {
int x = 0;
int y = 0;
int magic[] = {0,0,1,1,2,3,0,3};
ArrayList<Point> p = new ArrayList<Point>();
p = getTrigger(x,y,magic);
for(int i = 0; i < p.size(); i++){
int w = p.get(i).getx(); // first way to acess points in an array list
int u = p.get(i).gety();
Point c = p.get(i); // second way to aceess points in an array list.
System.out.print(c.getx() + " ");
System.out.println(c.gety());
}
}
public Point(int x, int y){
this.x = x;
this.y = y;
}
public int getx(){
return x;
}
public int gety(){
return y;
}
public static ArrayList<Point> getTrigger( int startx,int starty, int[] directions){
ArrayList<Point> trigger = new ArrayList<Point>();
Point temp = new Point(startx,starty);
for(int i = 0; i < directions.length -1; i++){
if(directions[i] == 0){ // increase y because the user is going up
starty--;
}
else if(directions[i] == 1){ //increase x because the user is going right
startx++;
}
else if(directions[i] == 2){ // decrease y because the user is going down
starty++;
}
else if(directions[i] == 3){ // decrease x because the user is going left
startx--;
}
if(directions[i] != directions[i+1]){ // if they are differnt then add a trigger point
trigger.add(new Point(startx,starty));
}
}
if(directions[directions.length-1] == 0){ // increase y because the user is going up
starty++;
}
else if(directions[directions.length-1] == 1){ //increase x because the user is going right
startx++;
}
else if(directions[directions.length-1] == 2){ // decrease y because the user is going down
starty--;
}
else if(directions[directions.length-1] == 3){ // decrease x because the user is going left
startx--;
}
trigger.add(new Point(startx,starty)); // add a trigger point to say you are at the end
return trigger;
}
}