5
5
import javafx .application .Platform ;
6
6
import javafx .scene .Cursor ;
7
7
import javafx .scene .Scene ;
8
+ import javafx .scene .input .KeyCode ;
8
9
import javafx .stage .Screen ;
9
10
import javafx .stage .Stage ;
10
11
@@ -42,17 +43,42 @@ public void start(Stage primaryStage) {
42
43
root = new GamePane ();
43
44
44
45
var scene = new Scene (root );
45
- scene .getStylesheets ().add (Game2048 . class .getResource ("game.css" ).toExternalForm ());
46
+ scene .getStylesheets ().add (getClass () .getResource ("game.css" ).toExternalForm ());
46
47
47
- if (isARMDevice ()) {
48
+ setGameBounds (primaryStage , scene );
49
+ setEnhancedDeviceSettings (primaryStage , scene );
50
+ setQuitListener (primaryStage );
51
+
52
+ primaryStage .show ();
53
+ root .requestFocus ();
54
+ }
55
+
56
+ private void setQuitListener (Stage primaryStage ) {
57
+ primaryStage .setOnCloseRequest (t -> {
58
+ t .consume ();
59
+ root .getGameManager ().quitGame ();
60
+ });
61
+ }
62
+
63
+ private void setEnhancedDeviceSettings (Stage primaryStage , Scene scene ) {
64
+ var isARM = System .getProperty ("os.arch" ).toUpperCase ().contains ("ARM" );
65
+ if (isARM ) {
48
66
primaryStage .setFullScreen (true );
49
67
primaryStage .setFullScreenExitHint ("" );
68
+ } else {
69
+ root .setOnKeyPressed (ke -> {
70
+ if (ke .getCode ().equals (KeyCode .F )) {
71
+ primaryStage .setFullScreen (true );
72
+ }
73
+ });
50
74
}
51
75
52
76
if (Platform .isSupported (ConditionalFeature .INPUT_TOUCH )) {
53
77
scene .setCursor (Cursor .NONE );
54
78
}
79
+ }
55
80
81
+ private void setGameBounds (Stage primaryStage , Scene scene ) {
56
82
var gameBounds = root .getGameManager ().getLayoutBounds ();
57
83
int MARGIN = GamePane .getMargin ();
58
84
var visualBounds = Screen .getPrimary ().getVisualBounds ();
@@ -62,20 +88,8 @@ public void start(Stage primaryStage) {
62
88
primaryStage .setScene (scene );
63
89
primaryStage .setMinWidth (gameBounds .getWidth () / 2d );
64
90
primaryStage .setMinHeight (gameBounds .getHeight () / 2d );
65
- primaryStage .setWidth ((gameBounds .getWidth () + MARGIN ) * factor );
66
- primaryStage .setHeight ((gameBounds .getHeight () + MARGIN ) * factor );
67
-
68
- primaryStage .setOnCloseRequest (t -> {
69
- t .consume ();
70
- root .getGameManager ().quitGame ();
71
- });
72
- primaryStage .show ();
73
-
74
- root .requestFocus ();
75
- }
76
-
77
- private boolean isARMDevice () {
78
- return System .getProperty ("os.arch" ).toUpperCase ().contains ("ARM" );
91
+ primaryStage .setWidth (((gameBounds .getWidth () + MARGIN ) * factor ) / 1.5d );
92
+ primaryStage .setHeight (((gameBounds .getHeight () + MARGIN ) * factor ) / 1.5d );
79
93
}
80
94
81
95
@ Override
0 commit comments