Skip to content

Package: C4Direction$6

C4Direction$6

nameinstructionbranchcomplexitylinemethod
getInverse()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
stepFromColumn(int, int)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
stepFromRow(int, int)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
{...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package de.fhdw.gaming.ipspiel23.c4.domain;
2:
3: import de.fhdw.gaming.ipspiel23.c4.domain.impl.C4Position;
4:
5: /**
6: * Represents a direction on the connect four board relative to a {@link C4Position}.
7: */
8: public enum C4Direction {
9: /**
10: * The direction to the top.
11: */
12: NORTH {
13: @Override
14: public int stepFromColumn(final int column, final int stepCount) {
15: return column;
16: }
17:
18: @Override
19: public int stepFromRow(final int row, final int stepCount) {
20: return row - stepCount;
21: }
22:
23: @Override
24: public C4Direction getInverse() {
25: return SOUTH;
26: }
27: },
28: /**
29: * The direction to the top right.
30: */
31: NORTH_EAST {
32: @Override
33: public int stepFromColumn(final int column, final int stepCount) {
34: return column + stepCount;
35: }
36:
37: @Override
38: public int stepFromRow(final int row, final int stepCount) {
39: return row - stepCount;
40: }
41:
42: @Override
43: public C4Direction getInverse() {
44: return SOUTH_WEST;
45: }
46: },
47: /**
48: * The direction to the right.
49: */
50: EAST {
51: @Override
52: public int stepFromColumn(final int column, final int stepCount) {
53: return column + stepCount;
54: }
55:
56: @Override
57: public int stepFromRow(final int row, final int stepCount) {
58: return row;
59: }
60:
61: @Override
62: public C4Direction getInverse() {
63: return WEST;
64: }
65: },
66: /**
67: * The direction to the bottom right.
68: */
69: SOUTH_EAST {
70: @Override
71: public int stepFromColumn(final int column, final int stepCount) {
72: return column + stepCount;
73: }
74:
75: @Override
76: public int stepFromRow(final int row, final int stepCount) {
77: return row + stepCount;
78: }
79:
80: @Override
81: public C4Direction getInverse() {
82: return NORTH_WEST;
83: }
84: },
85: /**
86: * The direction to the bottom.
87: */
88: SOUTH {
89: @Override
90: public int stepFromColumn(final int column, final int stepCount) {
91: return column;
92: }
93:
94: @Override
95: public int stepFromRow(final int row, final int stepCount) {
96: return this.getInverse().stepFromRow(row, -stepCount);
97: }
98:
99: @Override
100: public C4Direction getInverse() {
101: return NORTH;
102: }
103: },
104: /**
105: * The direction to the bottom left.
106: */
107: SOUTH_WEST {
108: @Override
109: public int stepFromColumn(final int column, final int stepCount) {
110: return this.getInverse().stepFromColumn(column, -stepCount);
111: }
112:
113: @Override
114: public int stepFromRow(final int row, final int stepCount) {
115: return this.getInverse().stepFromRow(row, -stepCount);
116: }
117:
118: @Override
119: public C4Direction getInverse() {
120: return NORTH_EAST;
121: }
122: },
123: /**
124: * The direction to the left.
125: */
126: WEST {
127: @Override
128: public int stepFromColumn(final int column, final int stepCount) {
129: return this.getInverse().stepFromColumn(column, -stepCount);
130: }
131:
132: @Override
133: public int stepFromRow(final int row, final int stepCount) {
134: return row;
135: }
136:
137: @Override
138: public C4Direction getInverse() {
139: return EAST;
140: }
141: },
142: /**
143: * The direction to the top left.
144: */
145: NORTH_WEST {
146: @Override
147: public int stepFromColumn(final int column, final int stepCount) {
148: return this.getInverse().stepFromColumn(column, -stepCount);
149: }
150:
151: @Override
152: public int stepFromRow(final int row, final int stepCount) {
153: return this.getInverse().stepFromRow(row, -stepCount);
154: }
155:
156: @Override
157: public C4Direction getInverse() {
158: return SOUTH_EAST;
159: }
160: };
161:
162: /**
163: * Steps the specified number of fields from the specified column in this direction.
164: * @param column The column index to step from.
165: * @param stepCount The number of fields to step.
166: * @return The resulting column index.
167: */
168: public abstract int stepFromColumn(int column, int stepCount);
169:
170: /**
171: * Steps the specified number of fields from the specified row in this direction.
172: * @param row The row index to step from.
173: * @param stepCount The number of fields to step.
174: * @return The resulting row index.
175: */
176: public abstract int stepFromRow(int row, int stepCount);
177:
178: /**
179: * Steps the specified number of fields from the specified position in this direction.
180: * @param position The position to step from.
181: * @param stepCount The number of fields to step.
182: * @return The resulting position.
183: */
184: public IC4Position stepFrom(final IC4Position position, final int stepCount) {
185: final int resultRow = stepFromRow(position.getRow(), stepCount);
186: final int resultColumn = stepFromColumn(position.getColumn(), stepCount);
187: return new C4Position(resultRow, resultColumn);
188: }
189:
190: /**
191: * Gets the inverse direction of this direction.
192: * @return The inverse direction.
193: */
194: public abstract C4Direction getInverse();
195: }