5 import static ru.bosony.model.cellscontents.CellContent.Empty; |
5 import static ru.bosony.model.cellscontents.CellContent.Empty; |
6 import static ru.bosony.model.cellscontents.CellContent.Lambda; |
6 import static ru.bosony.model.cellscontents.CellContent.Lambda; |
7 import static ru.bosony.model.cellscontents.CellContent.MiningRobot; |
7 import static ru.bosony.model.cellscontents.CellContent.MiningRobot; |
8 import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift; |
8 import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift; |
9 import static ru.bosony.model.cellscontents.CellContent.Rock; |
9 import static ru.bosony.model.cellscontents.CellContent.Rock; |
|
10 import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor; |
|
11 import static ru.bosony.model.cellscontents.CellContent.WadlersBeard; |
10 |
12 |
11 import java.util.ArrayList; |
13 import java.util.ArrayList; |
12 import java.util.List; |
14 import java.util.List; |
13 |
15 |
14 import ru.bosony.model.cellscontents.CellContent; |
16 import ru.bosony.model.cellscontents.CellContent; |
64 // Score |
66 // Score |
65 int prevScore = score; |
67 int prevScore = score; |
66 |
68 |
67 // Moving and scoring |
69 // Moving and scoring |
68 route.add(mov); |
70 route.add(mov); |
69 Coordinate robotCoord = mine.getRobotCell().getCoordinate(); |
71 Cell robotCell = mine.getRobotCell(); |
|
72 Coordinate robotCoord = robotCell.getCoordinate(); |
70 Coordinate nextRobotCoord = null; |
73 Coordinate nextRobotCoord = null; |
71 switch (mov) { |
74 switch (mov) { |
72 case ABORT: |
75 case ABORT: |
73 score += 25 * lambdaCollectedCount; |
76 score += 25 * lambdaCollectedCount; |
74 |
77 |
75 lastScoreChange = score - prevScore; |
78 lastScoreChange = score - prevScore; |
76 state = GameState.Abort; |
79 state = GameState.Abort; |
77 return state; |
80 return state; |
78 case WAIT: |
81 case WAIT: |
79 break; |
82 break; |
|
83 case RAZOR: |
|
84 if (mine.getRazorsCount() > 0) { |
|
85 for (Cell cell : mine.getNeighboringCells(robotCell)) { |
|
86 if (cell.getContent() == WadlersBeard) { |
|
87 cell.setContent(Empty); |
|
88 } |
|
89 } |
|
90 mine.setRazorsCount(mine.getRazorsCount() - 1); |
|
91 } |
|
92 break; |
80 case LEFT: |
93 case LEFT: |
81 nextRobotCoord = robotCoord.left(); |
94 nextRobotCoord = robotCoord.left(); |
82 break; |
95 break; |
83 case UP: |
96 case UP: |
84 nextRobotCoord = robotCoord.up(); |
97 nextRobotCoord = robotCoord.up(); |
104 score += 50 * lambdaCollectedCount; |
117 score += 50 * lambdaCollectedCount; |
105 |
118 |
106 lastScoreChange = score - prevScore; |
119 lastScoreChange = score - prevScore; |
107 state = GameState.Win; |
120 state = GameState.Win; |
108 return state; |
121 return state; |
|
122 } else if (nextRobotCellContent == HuttonsRazor) { |
|
123 moveRobot(nextRobotCell); |
|
124 mine.setRazorsCount(mine.getRazorsCount() + 1); |
109 } else if (robotCoord.right().equals(nextRobotCoord) && nextRobotCellContent == Rock |
125 } else if (robotCoord.right().equals(nextRobotCoord) && nextRobotCellContent == Rock |
110 && getContent(mine.getCell(nextRobotCoord.right())) == Empty) { |
126 && getContent(mine.getCell(nextRobotCoord.right())) == Empty) { |
111 moveRobot(nextRobotCell); |
127 moveRobot(nextRobotCell); |
112 mine.getCell(nextRobotCoord.right()).setContent(Rock); |
128 mine.getCell(nextRobotCoord.right()).setContent(Rock); |
113 } else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == Rock |
129 } else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == Rock |
171 && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { |
187 && getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) { |
172 getCell(curCoord, newCells).setContent(Empty); |
188 getCell(curCoord, newCells).setContent(Empty); |
173 getCell(rightAndDownCoord, newCells).setContent(Rock); |
189 getCell(rightAndDownCoord, newCells).setContent(Rock); |
174 } else if (getContent(curCell) == ClosedLambdaLift && mine.findCells(Lambda).size() == 0) { |
190 } else if (getContent(curCell) == ClosedLambdaLift && mine.findCells(Lambda).size() == 0) { |
175 getCell(curCoord, newCells).setContent(OpenLambdaLift); |
191 getCell(curCoord, newCells).setContent(OpenLambdaLift); |
|
192 } else if (getContent(curCell) == WadlersBeard && mine.getGrowth() > 0 |
|
193 && route.size() % mine.getGrowth() == 0) { |
|
194 if (getContent(leftCell) == Empty) |
|
195 getCell(leftCoord, newCells).setContent(WadlersBeard); |
|
196 if (getContent(upCell) == Empty) |
|
197 getCell(upCoord, newCells).setContent(WadlersBeard); |
|
198 if (getContent(rightCell) == Empty) |
|
199 getCell(rightCoord, newCells).setContent(WadlersBeard); |
|
200 if (getContent(downCell) == Empty) |
|
201 getCell(downCoord, newCells).setContent(WadlersBeard); |
|
202 if (getContent(leftAndUpCell) == Empty) |
|
203 getCell(leftAndUpCoord, newCells).setContent(WadlersBeard); |
|
204 if (getContent(rightAndUpCell) == Empty) |
|
205 getCell(rightAndUpCoord, newCells).setContent(WadlersBeard); |
|
206 if (getContent(leftAndDownCell) == Empty) |
|
207 getCell(leftAndDownCoord, newCells).setContent(WadlersBeard); |
|
208 if (getContent(rightAndDownCell) == Empty) |
|
209 getCell(rightAndDownCoord, newCells).setContent(WadlersBeard); |
176 } |
210 } |
177 } |
211 } |
178 } |
212 } |
179 |
213 |
180 // Other ending conditions |
214 // Other ending conditions |