-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.java
120 lines (106 loc) · 2.34 KB
/
Item.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
public class Item {
private int colorNo;
private int point;
public Item(int colorNo){
this.setColorNo(colorNo);
this.setPoint(0);
}
public int getPoint() {
return point;
}
public void setPoint(int point) {
this.point = point;
}
public int getColorNo() {
return colorNo;
}
public void setColorNo(int colorNo) {
this.colorNo = colorNo;
}
public boolean isMovingStraight(int fromX, int fromY, int toX, int toY, Item[][] Taslar){
int smallerVal;
int largerVal;
if (fromX == toX){
if (fromY > toY){
smallerVal = toY;
largerVal = fromY;
}
else if (toY > fromY){
smallerVal = fromY;
largerVal = toY;
}
else return false;
smallerVal++;
for(; smallerVal < largerVal; smallerVal++){
if (Taslar[fromX][smallerVal] != null ){
return false;
}
}
return true;
}
if (fromY == toY){
if (fromX > toX){
smallerVal = toX;
largerVal = fromX;
}
else if (toX > fromX){
smallerVal = fromX;
largerVal = toX;
}
else return false;
smallerVal++;
for(; smallerVal < largerVal; smallerVal++){
if (Taslar[smallerVal][fromY] != null){
return false;
}
}
return true;
}
return false;
}
public boolean isMovingDiagonal(int fromX, int fromY, int toX, int toY, Item[][] Taslar){
int xStart = 0;
int yStart = 0;
int xFinish = 1;
//int yFinish = 1;
//Check if movement is diagonal
int xTotal = Math.abs(toX - fromX);
int yTotal = Math.abs(toY - fromY);
if (xTotal == yTotal){
if (toX < fromX){
xStart = toX;
xFinish = fromX;
}
else if (toX > fromX){
xStart = fromX;
xFinish = toX;
}
else
return false;
if (toY < fromY){
yStart = toY;
//yFinish = this.getYLocation();
}
else if (toY > fromY){
yStart = fromY;
//yFinish = yPosition;
}
else
return false;
xStart++;
yStart++;
// Loop to see if any piece is in between
//Taslar[xStart][yStart] != null
for(;xStart < xFinish; xStart++, yStart++){
if (Taslar[xStart][yStart] != null){
return false;
}
}
return true;
}
return false;
}
public boolean isPlayable(int fromX, int fromY, int toX, int toY, Item[][] Taslar){
return false;
}
}