[ all classes ]
[ it.polimi.ingsw.model ]
Coverage Summary for Class: Build (it.polimi.ingsw.model)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
Build | 100% (1/ 1) | 100% (10/ 10) | 100% (30/ 30) |
1 package it.polimi.ingsw.model;
2
3 /**
4 * Implements the Action -- BUILD
5 */
6
7 class Build implements Action {
8
9 /**
10 * Type of the block
11 */
12 private TypeBlock block;
13
14 /**
15 * Position
16 */
17 private int[] position = new int[2];// useless
18
19 /**
20 * status
21 */
22 private boolean status;
23
24 /**
25 * if blocked
26 */
27 private boolean blocked;
28
29 /**
30 * Type of Action
31 */
32 private final String typeAction;
33
34 /**
35 * God
36 */
37 private God god;
38
39 /**
40 * Set type of Action
41 */
42 public Build() {
43 typeAction = "Build";
44 }
45
46 /**
47 * Get type of the action
48 *
49 * @return type of the action
50 */
51 @Override
52 public String getTypeAction() {
53 return typeAction;
54 }
55
56 /**
57 * Set action status
58 *
59 * @param status status to set
60 */
61 @Override
62 public void set(boolean status) {
63 if (!blocked) {
64 this.status = status;
65 }
66 }
67
68 /**
69 * Put the block on the board
70 *
71 * @param status status
72 * @param block block
73 * @param position position
74 */
75 public void set(boolean status, TypeBlock block, int[] position) {
76 this.block = block;
77 this.position[0] = position[0];
78 this.position[1] = position[1];
79 if (!blocked) {
80 this.status = status;
81 }
82 }
83
84
85 /**
86 * Get the status
87 *
88 * @return the status
89 */
90 @Override
91 public boolean getStatus() {
92 return status && !blocked;
93 }
94
95 /**
96 * @param map where to apply the action effects
97 * @return result event of the action(Event.Four means that execution fails)
98 */
99 @Override
100 public Event[] execute(Cell[][] map) {
101 Event[] events = new Event[1];
102 events[0] = Event.FOUR;
103 if (getStatus()) {
104 Block newBlock = new Block(block);
105 map[position[0]][position[1]].addBlock(newBlock);
106 events[0] = Event.BUILD;
107 }
108 return events;
109 }
110
111 /**
112 * Set the last god that changed this action
113 *
114 * @param god god to set as last god that changed this action
115 */
116 @Override
117 public void setGod(God god) {
118 this.god = god;
119 }
120
121 /**
122 * Get the last god that changed this action
123 *
124 * @return last god that changed this action
125 */
126 @Override
127 public God getGod() {
128 return god;
129 }
130
131 /**
132 * Disable any further changes on this action
133 *
134 * @param blocked disable this action from further changes
135 */
136 @Override
137 public void setBlocked(boolean blocked) {
138 this.blocked = blocked;
139 }
140
141
142 /**
143 * Clone the action
144 *
145 * @return cloned action
146 */
147 @Override
148 public Action clone() {
149 Build build = new Build();
150 build.set(this.getStatus(), block, position);
151 return build;
152 }
153
154
155 }