-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorker.java
More file actions
128 lines (81 loc) · 3.96 KB
/
Worker.java
File metadata and controls
128 lines (81 loc) · 3.96 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
public class Worker {
private String name;
private int positionX;
private int positionY;
public Worker(String name){
this.name = name;
}
public void placeWorker(int x, int y){
positionX = x;
positionY = y;
}
public boolean move(int newPositionX, int newPositionY, SantoriniGame game, int w) {
if((newPositionX < 6 && newPositionX > 0)&&(newPositionY > 0 && newPositionY < 6)) {
if(game.getBoard()[newPositionX-1][newPositionY-1].indexOf("w") != -1){
System.err.println("THERE IS A PLAYER YOU CANNOT GO THERE!!");
return false;
}
if(!game.getBoard()[positionX-1][positionY-1].contains("B") && (game.getBoard()[newPositionX-1][newPositionY-1].equals("BB") || game.getBoard()[newPositionX-1][newPositionY-1].equals("BBB") || game.getBoard()[newPositionX-1][newPositionY-1].equals("BBBD"))) {
System.err.println("THERE IS A HIGHER BULDING YOU CANNOT GO THERE!!");
return false;
}
if(!game.getBoard()[positionX-1][positionY-1].substring(0,2).equals("BB") && game.getBoard()[newPositionX-1][newPositionY-1].equals("BBB")) {
System.err.println("THERE IS A BBB YOU CANNOT GO THERE!!");
return false;
}
if(game.getBoard()[positionX-1][positionY-1].substring(0,2).equals("BB") && game.getBoard()[newPositionX-1][newPositionY-1].equals("BBBD")) {
System.err.println("THERE IS A DOME YOU CANNOT GO THERE!!");
return false;
}
if((Math.abs(positionX - newPositionX) == 1 || Math.abs(positionX - newPositionX) == 0) &&
(Math.abs(positionY - newPositionY) == 1 || Math.abs(positionY - newPositionY) == 0)) {
game.movePlayer(newPositionX, newPositionY, w);
return true;
}else{
System.err.println("MOVEMENT OUT OF REACH!!");
return false;
}
}else {
System.err.println("OUT OF THE RANGE OF THE BOARD!!");
return false;
}
}
public boolean moveNoErrorMesseges(int newPositionX, int newPositionY, SantoriniGame game) {
if((newPositionX > 5 && newPositionX < 1)&&(newPositionY > 5 && newPositionY < 1)) {
return false;
}
if(game.getBoard()[newPositionX-1][newPositionY-1].indexOf("w") != -1){
return false;
}
if(!game.getBoard()[positionX-1][positionY-1].contains("B") && (game.getBoard()[newPositionX-1][newPositionY-1].equals("BB") || game.getBoard()[newPositionX-1][newPositionY-1].equals("BBB") || game.getBoard()[newPositionX-1][newPositionY-1].equals("BBBD"))) {
return false;
}
if(!game.getBoard()[positionX-1][positionY-1].substring(0,2).equals("BB") && game.getBoard()[newPositionX-1][newPositionY-1].equals("BBB")) {
return false;
}
if(game.getBoard()[positionX-1][positionY-1].substring(0,2).equals("BB") && game.getBoard()[newPositionX-1][newPositionY-1].equals("BBBD")) {
return false;
}
if((Math.abs(positionX - newPositionX) == 1 || Math.abs(positionX - newPositionX) == 0) &&
(Math.abs(positionY - newPositionY) == 1 || Math.abs(positionY - newPositionY) == 0)) {
return true;
}else{
return false;
}
}
public String getName() {
return name;
}
public int getPositionX() {
return positionX;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public int getPositionY() {
return positionY;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
}