[ all classes ]
[ it.polimi.ingsw.model ]
Coverage Summary for Class: GodMedusa (it.polimi.ingsw.model)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
GodMedusa | 100% (1/ 1) | 100% (3/ 3) | 100% (25/ 25) |
1 package it.polimi.ingsw.model;
2
3 class GodMedusa extends GodDecorator {
4
5 /**
6 * God Medusa's class
7 * @param godPower God's power
8 */
9 public GodMedusa(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 if (events[0].equals(Event.BUILD) && godPower.getName().equals(godPower.getCurrentPlayer())) {
22 int[] position = godPower.getPositionWorker();
23 setAction(map, position);
24 for (int i = 0; i < 25; i++) {
25 if ((map[i / 5][i % 5].getBlock().getTypeBlock().equals(TypeBlock.WORKER)
26 && map[i / 5][i % 5].getBlock().getOwner().equals(godPower.getCurrentPlayer()))
27 && (i / 5 != godPower.getPositionWorker()[0] || i % 5 != godPower.getPositionWorker()[1])) {
28 setAction(map, new int[] { i / 5, i % 5 });
29 }
30 }
31
32 }
33 }
34
35 /**
36 * Set god's special move/build action (God Power) if possible
37 * @param map Current board
38 * @param position workers'positions
39 */
40 private void setAction(Cell[][] map, int[] position) {
41 for (int i = Math.max(position[0] - 1, 0); i <= Math.min(position[0] + 1, 4); i++) {
42 for (int j = Math.max(position[1] - 1, 0); j <= Math.min(position[1] + 1, 4); j++) {
43 if (map[i][j].getBlock().getTypeBlock().equals(TypeBlock.WORKER)
44 && !map[i][j].getBlock().getOwner().equals(godPower.getName())
45 && map[i][j].getSize() < map[position[0]][position[1]].getSize()) {
46 map[i][j].popBlock();
47 switch (map[i][j].getSize()) {
48 case 0:
49 map[i][j].addBlock(new Block(TypeBlock.LEVEL1));
50 break;
51 case 1:
52 map[i][j].addBlock(new Block(TypeBlock.LEVEL2));
53 break;
54 case 2:
55 map[i][j].addBlock(new Block(TypeBlock.LEVEL3));
56 break;
57 default:
58 break;
59 }
60 }
61 }
62 }
63 }
64 }