[ all classes ]
[ it.polimi.ingsw.model ]
Coverage Summary for Class: GodMinotaur (it.polimi.ingsw.model)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
GodMinotaur | 100% (1/ 1) | 100% (3/ 3) | 100% (35/ 35) |
1 package it.polimi.ingsw.model;
2
3 class GodMinotaur extends GodDecorator {
4
5 /**
6 * God Minotaur's class
7 * @param godPower God's power
8 */
9 public GodMinotaur(GodInterface godPower) {
10 super(godPower);
11 }
12
13 /**
14 * Get event
15 * @param events event to be updated
16 * @param map board situation at the moment
17 * @param actions action of the event
18 */
19 @Override
20 public void getEvent(Event[] events, Cell[][] map, Action[][][] actions) {
21 String namePlayer = godPower.getCurrentPlayer();
22 if (events[0] == Event.ZERO && namePlayer.equals(godPower.getName())) {
23 godPower.activate(true);
24 setAction(map, actions);
25 godPower.activate(false);
26 }
27 }
28
29 /**
30 * Set god's special move/build action (God Power) if possible
31 * @param map Current board
32 * @param actions List of possible actions
33 */
34 private void setAction(Cell[][] map, Action[][][] actions) {
35 int[] position = godPower.getPositionWorker();
36 String name = godPower.getName();
37 Block block = null;
38 int[] destination = new int[2];
39 for (int i = Math.max(0, position[0] - 1); (i <= Math.min(4, position[0] + 1)); i++) {
40
41 for (int j = Math.max(0, position[1] - 1); j <= Math.min(4, position[1] + 1); j++) {
42 block = map[i][j].getBlock(map[i][j].getSize());
43 if (block.getTypeBlock().equals(TypeBlock.WORKER)
44 && map[i][j].getSize() <= map[position[0]][position[1]].getSize() + 1
45 && !block.getOwner().equals(name)) {
46 if (position[0] > i) {
47 destination[0] = i - 1;
48 } else if (position[0] < i) {
49 destination[0] = i + 1;
50 } else {
51 destination[0] = i;
52 }
53 if (position[1] > j) {
54 destination[1] = j - 1;
55 } else if (position[1] < j) {
56 destination[1] = j + 1;
57 } else {
58 destination[1] = j;
59 }
60 if ((destination[0] >= 0 && destination[0] <= 4 && destination[1] >= 0 && destination[1] <= 4)
61 && (!map[destination[0]][destination[1]]
62 .getBlock(map[destination[0]][destination[1]].getSize()).getTypeBlock()
63 .equals(TypeBlock.DOME)
64 && !map[destination[0]][destination[1]]
65 .getBlock(map[destination[0]][destination[1]].getSize()).getTypeBlock()
66 .equals(TypeBlock.WORKER))) {
67 ((Swap) actions[i][j][0]).set(position, new int[] { i, j }, new int[] { i, j }, destination,
68 true);
69 }
70 }
71 }
72 }
73 }
74 }