-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.java
210 lines (183 loc) · 5.06 KB
/
Controller.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
203
204
205
206
207
208
209
210
import java.util.ArrayList;
//manages communication between the view and the model components
//(not REALLY needed, but could be helpful)
public class Controller implements ViewGUIToController{
private ControllerToViewGUI myView;
private ControllerToModel myModel;
public Controller()
{
myModel = new Model();
myView = new ViewGUI(this);
if(myModel==null || myView==null)
System.exit(NULL_EXIT_CODE);
}
//start the game
public void go()
{
if(myModel==null || myView==null)
System.exit(NULL_EXIT_CODE);
myView.go(myModel.getDifficulties());
}
//have the model set the game difficulty to the given value
public void setDifficulty(String difficulty)
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.setDifficulty(difficulty);
}
//return the preset difficulty list from the model
public ArrayList<String> getDifficulties()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getDifficulties();
}
//return the string representation for a mine tile
//in the game from the model
public String getMineString()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.MINE;
}
//the game has started
//tell the model that the game started and return the success code
public boolean startGame()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.startGame();
}
//return the number of mines from the model
public int getNumMines()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getNumMines();
}
//return the string representation for the game grid from the model
public String[][] getGrid()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getGrid();
}
public void tilePressed(int row, int col, long currentTime)
{
if(myModel==null || myView==null)
System.exit(NULL_EXIT_CODE);
myView.refresh(myModel.tilePressed(row,col, currentTime), myModel.EMPTY);
}
//if flagged==true, flag has been placed at [row,col]
//if flagged==false, unflagged [row,col]
//tell the model that this has occurred
public void placeFlag(boolean flagged,int row, int col)
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.tileFlagged(flagged,row, col);
}
//return true if player lost or false if player has not lost
//as determined by the model
public boolean playerLost()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.playerLost();
}
//return true if player won or false if player has not won
//as determined by the model
public boolean playerWon()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.playerWon();
}
//tell model to reset the game
public void reset()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.resetGame();
}
//return the int representation of the tile last
//pressed as determined by the model
public int[] getLastPressed()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getLastPressed();
}
//make the model set the extra lives to the given value
public void setExtraLives(int lives)
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.setExtraLives(lives);
}
//return the number of extra lives left
//as determined by the model
public int getExtraLivesLeft()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getExtraLivesLeft();
}
//get the String representation for an empty tile from model
public String getEmptyTileString()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.EMPTY;
}
//set the number of rows for the custom setting to given value in model
public void setCustomRows(int rows)
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.setCustomRows(rows);
}
//set the number of cols for the custom setting to given value in model
public void setCustomColumns(int cols)
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.setCustomColumns(cols);
}
//set the number of mines for the custom setting to given value in model
public void setCustomMines(int mines)
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
myModel.setCustomMines(mines);
}
//return number of total games won as determined by model
public long getTotalGamesWon()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getTotalGamesWon();
}
//return number of total games played as determined by model
public long getTotalGamesPlayed()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getTotalGamesPlayed();
}
//return the string representations of the best times for the games
//as determined by the model
public String getBestTime()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.getBestTimes();
}
//get the rules for the game from the model and return
public String getRules()
{
if(myModel==null)
System.exit(NULL_EXIT_CODE);
return myModel.RULES;
}
}