[ all classes ]
[ it.polimi.ingsw.model ]
Coverage Summary for Class: GodDecorator (it.polimi.ingsw.model)
Class | Method, % | Line, % |
---|---|---|
GodDecorator | 100% (16/ 16) | 100% (60/ 60) |
GodDecorator$1 | 100% (1/ 1) | 100% (1/ 1) |
total | 100% (17/ 17) | 100% (61/ 61) |
1 package it.polimi.ingsw.model;
2
3 class GodDecorator implements GodInterface {
4 /**
5 * God Power
6 */
7 protected GodInterface godPower;
8
9 /**
10 * Set God Power
11 * @param godPower God Power to be set
12 */
13 public GodDecorator(GodInterface godPower) {
14 this.godPower = godPower;
15 }
16
17 /**
18 * Set player's username
19 * @param name player's username
20 */
21 @Override
22 public void setCurrentPlayer(String name) {
23 godPower.setCurrentPlayer(name);
24 }
25
26 /**
27 *Set the worker's position
28 * @param positionWorker worker's position
29 */
30 @Override
31 public void setWorker(int[] positionWorker) {
32 godPower.setWorker(positionWorker);
33 }
34 /**
35 * Activate God Power's status
36 * @param status God's status that needs to be activated
37 */
38 @Override
39 public void activate(boolean status) {
40 godPower.activate(status);
41 }
42
43 /**
44 * Get player's status
45 * @return player's status
46 */
47 @Override
48 public StatusPlayer getPlayerStatus() {
49 return godPower.getPlayerStatus();
50 }
51
52 /**
53 * Get event
54 * @param events event to be updated
55 * @param map board situation at the moment
56 * @param actions action of the event
57 */
58 @Override
59 public void getEvent(Event[] events, Cell[][] map, Action[][][] actions) {
60 godPower.getEvent(events, map, actions);
61 }
62
63 /**
64 * Set player's status
65 * @param statusPlayer player's status to be set
66 */
67 @Override
68 public void setStatusPlayer(StatusPlayer statusPlayer) {
69 godPower.setStatusPlayer(statusPlayer);
70 }
71
72 /**
73 * Get player's username
74 * @return player's username
75 */
76 @Override
77 public String getName() {
78 return godPower.getName();
79 }
80
81 /**
82 * Get god's status
83 * @return God's stauts
84 */
85 @Override
86 public boolean getStatus() {
87 return godPower.getStatus();
88 }
89
90 /**
91 * Get the worker's position
92 * @return worker's position
93 */
94 @Override
95 public int[] getPositionWorker() {
96 return godPower.getPositionWorker();
97 }
98
99 /**
100 * Get the last god that changed his own status
101 * @return last god that changed his own status
102 */
103 @Override
104 public God getLastGod() {
105 return godPower.getLastGod();
106 }
107
108 /**
109 * Set the last god that changed his own status
110 * @param lastGod last god that changed his own status
111 */
112 @Override
113 public void setLastGod(God lastGod) {
114 godPower.setLastGod(lastGod);
115 }
116
117 /**
118 * Add information to the current player
119 * @param currentPlayer Player that information needs to be updated
120 */
121 @Override
122 public void addInfo(CurrentPlayer currentPlayer) {
123 godPower.addInfo(currentPlayer);
124 }
125
126 /**
127 * Get the current player
128 * @return current player
129 */
130 @Override
131 public String getCurrentPlayer() {
132 return godPower.getCurrentPlayer();
133 }
134
135 /**
136 * The god changed possible move actions of the board at the current turn
137 * @param map Current board
138 * @param actions Possible move actions on the board
139 * @param position Chosen worker's position
140 */
141 public void move(Cell[][] map, Action[][][] actions, int[] position) {
142 int[] destination = new int[2];
143 for (int i = Math.max(0, position[0] - 1); (i <= Math.min(4, position[0] + 1)); i++) {
144 for (int j = Math.max(0, position[1] - 1); j <= Math.min(4, position[1] + 1); j++) {
145 if ((map[i][j].getSize() <= map[position[0]][position[1]].getSize())
146 && !map[i][j].getBlock(map[i][j].getSize() - 1).getTypeBlock().equals(TypeBlock.WORKER)
147 && !map[i][j].getBlock(map[i][j].getSize() - 1).getTypeBlock().equals(TypeBlock.DOME)) {
148 destination[0] = i;
149 destination[1] = j;
150 ((Swap) actions[i][j][0]).set(position, destination, destination, destination, true);
151 }
152 }
153 }
154 }
155
156 /**
157 * The god changed possible build actions of the board at the current turn
158 * @param map Current board
159 * @param actions Possible build actions on the board
160 * @param position Chosen worker's position
161 */
162 public void build(Cell[][] map, Action[][][] actions, int[] position ) {
163 int[] destination=new int[2];
164 TypeBlock typeBlock=null;
165 for (int i = Math.max(0, position[0] - 1); (i <= Math.min(4, position[0] + 1)); i++) {
166 for (int j = Math.max(0, position[1] - 1); j <= Math.min(4, position[1] + 1); j++) {
167 if (!map[i][j].getBlock(map[i][j].getSize() - 1).getTypeBlock().equals(TypeBlock.WORKER)
168 && !map[i][j].getBlock(map[i][j].getSize() - 1).getTypeBlock().equals(TypeBlock.DOME)) {
169 switch (map[i][j].getBlock(map[i][j].getSize() - 1).getTypeBlock()) {
170 case LEVEL1:
171 typeBlock = TypeBlock.LEVEL2;
172 destination[0] = i;
173 destination[1] = j;
174 ((Build) actions[i][j][1]).set(true, typeBlock, destination);
175 break;
176 case LEVEL2:
177 typeBlock = TypeBlock.LEVEL3;
178 destination[0] = i;
179 destination[1] = j;
180 ((Build) actions[i][j][1]).set(true, typeBlock, destination);
181 break;
182 case LEVEL3:
183 typeBlock = TypeBlock.DOME;
184 destination[0] = i;
185 destination[1] = j;
186 ((Build) actions[i][j][2]).set(true, typeBlock, destination);
187 break;
188 default:
189 typeBlock = TypeBlock.LEVEL1;
190 destination[0] = i;
191 destination[1] = j;
192 ((Build) actions[i][j][1]).set(true, typeBlock, destination);
193 }
194 }
195 }
196
197 }
198 }
199 }