forked from CSC207-2022F-UofT/course-project-monopolymen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TurnController.java
202 lines (167 loc) · 8.19 KB
/
TurnController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package turn_interface_adapters;
import game.GameState;
import game_entities.Board;
import game_entities.Player;
import game_entities.tiles.ColorPropertyTile;
import game_entities.tiles.Property;
import turn_use_cases.build_use_case.BuildBuildingInputBoundary;
import turn_use_cases.end_turn_use_case.EndTurnInputBoundary;
import turn_use_cases.liquidate_assets_use_case.LiquidateAssetsInputBoundary;
import turn_use_cases.liquidate_assets_use_case.LiquiditySituation;
import turn_use_cases.mortgage_use_case.MortgagePropertyInputBoundary;
import turn_use_cases.move_player_use_case.MovePlayerInputBoundary;
import turn_use_cases.trade_use_case.TradeInputBoundary;
import turn_use_cases.trade_use_case.TradeOffer;
import turn_use_cases.try_to_get_out_of_jail_use_case.TryToGetOutOfJailInputBoundary;
import turn_use_cases.view_inventory.ViewInventoryInputBoundary;
import java.util.List;
/**
* Interacts with each Turn use case as appropriate through the use case's
* InputBoundary interface.
* The Turn Controller is responsible for formatting the input data (if applicable) to the
* InputBoundary's specification.
* The Turn Controller also performs delegation to the simpler use case methods.
*/
public class TurnController {
private GameState gameState;
private BuildBuildingInputBoundary buildBuilding;
private MortgagePropertyInputBoundary mortgageProperty;
private MovePlayerInputBoundary movePlayer;
private TradeInputBoundary trade;
private TryToGetOutOfJailInputBoundary getOutOfJail;
private ViewInventoryInputBoundary viewInventory;
private LiquidateAssetsInputBoundary liquidateAssets;
private EndTurnInputBoundary endTurn;
/**
* Construct the TurnController object. Before use, the {@link #initializeAttributes(GameState, BuildBuildingInputBoundary, MortgagePropertyInputBoundary, MovePlayerInputBoundary, TradeInputBoundary, TryToGetOutOfJailInputBoundary, ViewInventoryInputBoundary, LiquidateAssetsInputBoundary, EndTurnInputBoundary)}
* method must be called to specify the input boundaries.
*/
public TurnController() {
this.buildBuilding = null;
this.mortgageProperty = null;
this.movePlayer = null;
this.trade = null;
this.getOutOfJail = null;
this.viewInventory = null;
this.liquidateAssets = null;
this.endTurn = null;
this.gameState = null;
}
/**
* Set the input boundaries to use in this controller. Must be called before other methods are called.
* The reason this order occurs is that each of the inputBoundaries and gameStates have presenters which need
* to refer to this turnController.
*/
public void initializeAttributes(GameState gameState,
BuildBuildingInputBoundary buildBuilding,
MortgagePropertyInputBoundary mortgageProperty,
MovePlayerInputBoundary movePlayer,
TradeInputBoundary trade,
TryToGetOutOfJailInputBoundary getOutOfJail,
ViewInventoryInputBoundary viewInventory,
LiquidateAssetsInputBoundary liquidateAssets,
EndTurnInputBoundary endTurn) {
this.buildBuilding = buildBuilding;
this.mortgageProperty = mortgageProperty;
this.movePlayer = movePlayer;
this.trade = trade;
this.getOutOfJail = getOutOfJail;
this.viewInventory = viewInventory;
this.liquidateAssets = liquidateAssets;
this.endTurn = endTurn;
this.gameState = gameState;
}
/**
* Signifies the end of a use case. Shows the player the turn actions.
*/
public void endUseCase() {
gameState.showTurnActions();
}
public void endTurn() {
endTurn.endTurn(gameState.currentPlayer());
}
public void forceEndTurn() {
endTurn.forceEndTurn(gameState.currentPlayer());
}
/* Move Player/RollDice use case related methods */
public void rollDice() {
movePlayer.startAction(gameState.currentPlayer(), true);
}
public void endRollDice(boolean rollAgain) {
if (!rollAgain) {
gameState.playerRolledToMove();
}
endUseCase();
}
public void buyProperty(Property property) {
gameState.currentPlayer().addProperty(property);
gameState.currentPlayer().subtractMoney(property.getPurchasePrice());
}
/* TryToGetOutOfJail use case related methods */
public void attemptLeaveJail() {
// Show the player their options for getting out of jail
getOutOfJail.getPlayerOptions(gameState.currentPlayer());
}
public void leaveJailWithChoice(String playerChoice) {
// Leave jail with the appropriate option.
getOutOfJail.startAction(playerChoice, gameState.currentPlayer());
gameState.playerAttemptedLeaveJail();
}
/* Mortgage property related methods */
public void showMortgageableProperties() { mortgageProperty.showMortgageOption(gameState.currentPlayer()); }
public void mortgageProperty(Property property) {
mortgageProperty.mortgage(gameState.currentPlayer(), property);
}
public void showUnmortgageableProperties() { mortgageProperty.showUnmortgageOption(gameState.currentPlayer()); }
public void unmortgageProperty(Property property) {
mortgageProperty.unmortgage(gameState.currentPlayer(), property);
}
/* BuildBuilding Related Methods */
public void showBuildableProperties() { buildBuilding.showBuildOption(gameState.currentPlayer()); }
public void buildHouse(ColorPropertyTile property) {
buildBuilding.buildHouse(gameState.currentPlayer(), property);
}
public void buildHotel(ColorPropertyTile property) {
buildBuilding.buildHotel(gameState.currentPlayer(), property);
}
public void showBuiltOnProperties() { buildBuilding.showSellOption(gameState.currentPlayer()); }
public void sellHouse(ColorPropertyTile property) {
buildBuilding.sellHouse(gameState.currentPlayer(), property);
}
public void sellHotel(ColorPropertyTile property) {
buildBuilding.sellHotel(gameState.currentPlayer(), property);
}
/* Trade Related Methods */
public void showTradablePlayers() {
trade.choosePlayer(gameState.getActivePlayers(), gameState.currentPlayer());
}
public void startTrade(Player proposing, Player receiving) {
trade.getTradeOptions(proposing, receiving);
}
public void makeOffer(Player offering, Player receiving, TradeOffer player1Offer) {
trade.makeOffer(player1Offer, offering, receiving);
}
public void acceptTradeOffer(Player offering, Player receiving, TradeOffer tradeOffer) {
trade.getResultOfTradeOffer(1, offering, receiving, tradeOffer);
}
public void declineTradeOffer(Player offering, Player receiving, TradeOffer tradeOffer) {
trade.getResultOfTradeOffer(3, offering, receiving, tradeOffer);
}
public void counterOffer(Player offering, Player receiving, TradeOffer tradeOffer) {
// The receiving player is now making the offer
trade.getResultOfTradeOffer(2, offering, receiving, tradeOffer);
}
/* LiquidityUseCase related methods*/
public void getPlayerOptions(LiquiditySituation situation) { liquidateAssets.getPlayerOptions(situation); }
public void getPlayerOptions(Player affectedPlayer, Player owedPlayer, int owedMoney, GameState gameState, Board board) {
LiquiditySituation situation = new LiquiditySituation(affectedPlayer, owedPlayer, owedMoney, gameState, board);
liquidateAssets.getPlayerOptions(situation);
}
public void getMortgageableProperties(LiquiditySituation situation) {liquidateAssets.getMortgageableProperties(situation);}
public void getPropertiesWithHouses(LiquiditySituation situation) { liquidateAssets.getPropertiesWithHouses(situation); }
public void bankruptcy(LiquiditySituation situation) { liquidateAssets.bankruptcy(situation); }
/* ViewInventory Related Methods */
public void showInventory(Player player, List<Player> playerList) {
viewInventory.displayInfo(player, playerList);
}
}