-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewGameBoard.java
More file actions
99 lines (88 loc) · 3.44 KB
/
ViewGameBoard.java
File metadata and controls
99 lines (88 loc) · 3.44 KB
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
package edu.sdccd.cisc191;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
* Presents the user with the game graphical user interface
*/
public class ViewGameBoard extends Application
{
private Canvas gameCanvas;
private ControllerGameBoard controller;
private GameBoardLabel fishRemaining;
private GameBoardLabel guessesRemaining;
private GameBoardLabel message;
public static void main(String[] args)
{
// TODO: launch the app
launch();
}
public void updateHeader() {
//TODO update labels
fishRemaining.setText ("Fish: " + controller.modelGameBoard.getFishRemaining());
//"Fish: " + controller.modelGameBoard.getFishRemaining()
guessesRemaining.setText ("Bait: " + controller.modelGameBoard.getGuessesRemaining());
//"Bait: " + controller.modelGameBoard.getGuessesRemaining()
if(controller.fishWin()) {
message.setText("Fishes win!");
//"Fishes win!"
} else if(controller.playerWins()) {
message.setText("You win!");
//"Fishes win!"
} else {
message.setText("Find the fish!");
//"Find the fish!"
}
}
@Override
public void start(Stage stage) throws Exception {
controller = new ControllerGameBoard();
// TODO initialize gameCanvas
Canvas gameCanvas = new Canvas();
fishRemaining = new GameBoardLabel();
guessesRemaining = new GameBoardLabel();
message = new GameBoardLabel();
// TODO display game there are infinite ways to do this, I used BorderPane with HBox and VBox.
BorderPane root = new BorderPane();
updateHeader();
VBox buttonColumns = new VBox(10);
buttonColumns.setAlignment(Pos.BOTTOM_CENTER);
for (int row=0; row < ModelGameBoard.DIMENSION; row++) {
// TODO: create row container
HBox buttonRows = new HBox(10);
for (int col=0; col < ModelGameBoard.DIMENSION; col++) {
GameBoardButton button = new GameBoardButton(row, col, controller.modelGameBoard.fishAt(row,col));
int finalRow = row;
int finalCol = col;
button.setOnAction(e -> {
controller.makeGuess(finalRow, finalCol);
if(!controller.isGameOver()) {
button.handleClick();
updateHeader();
}
});
// TODO: add button to row
buttonRows.getChildren().add(button);
}
// TODO: add row to column
buttonColumns.getChildren().add(row, buttonRows);
}
// TODO: create scene, stage, set title, and show
HBox Label = new HBox(60, fishRemaining, guessesRemaining, message);
root.setCenter(Label);
Label.setAlignment(Pos.CENTER);
root.setBottom(buttonColumns);
BorderPane.setMargin(Label, new Insets(25.0, 25.0, 25.0, 25.0));
BorderPane.setMargin(buttonColumns, new Insets(0.0, 45.0, 15.0, 45.0));
Scene scene = new Scene(root, 450, 300);
stage.setScene(scene);
stage.setTitle("Gone Fishing");
stage.show();
}
}