-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.java
80 lines (69 loc) · 2.06 KB
/
Field.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
import java.util.ArrayList;
public class Field {
//set these to protected so the classes in the package can
//access them without the hassle of getter methods
protected int x;
protected int y;
protected FieldType type;
protected char value;
protected boolean visited;
protected int costToGetHere;
protected int costToGetToGoal;
protected Field parent;
protected ArrayList<Integer> goalDistance;
/**
* Constructor to create a new Field, setting the location and the value.
* Depending on the value, it also sets a type for the field.
*/
public Field(int xValue, int yValue, char character) {
this.x = xValue;
this.y = yValue;
this.value = character;
costToGetHere = 0;
costToGetToGoal = 0;
goalDistance = new ArrayList<>();
parent = null;
switch (character){
case 'x':
this.type = FieldType.BORDER;
break;
case ' ':
this.type = FieldType.NORMAL;
break;
case 's':
this.type = FieldType.START;
this.visited = true;
break;
case 'g':
this.type = FieldType. GOAL;
break;
//more than five types of portals seem unlikely
case '1':
this.type = FieldType.PORTAL1;
break;
case '2':
this.type = FieldType.PORTAL2;
break;
case '3':
this.type = FieldType.PORTAL3;
break;
case '4':
this.type = FieldType.PORTAL4;
break;
case '5':
this.type = FieldType.PORTAL5;
break;
default:
break;
}
}
public String toString(){
return "(" + x + "," + y + ")";
}
public boolean isGoal(){
return this.type == FieldType.GOAL;
}
public FieldType getFieldType(){
return type;
}
}