Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. package gui;
  2.  
  3. import javafx.application.Application;
  4. import javafx.geometry.Insets;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.CheckBox;
  8. import javafx.scene.control.Label;
  9. import javafx.scene.control.TextField;
  10. import javafx.scene.layout.GridPane;
  11. import javafx.stage.Stage;
  12. import model.Yatzy;
  13.  
  14. public class MainApp extends Application {
  15. public static void main(String[] args) {
  16. Application.launch(args);
  17. }
  18.  
  19. @Override
  20. public void start(Stage stage) {
  21. stage.setTitle("Yatzy");
  22. GridPane pane = new GridPane();
  23. this.initContent(pane);
  24.  
  25. Scene scene = new Scene(pane);
  26. stage.setScene(scene);
  27. stage.setResizable(false);
  28. stage.show();
  29. }
  30.  
  31. // -------------------------------------------------------------------------
  32.  
  33. // Shows the face values of the 5 dice.
  34. private TextField[] txfValues;
  35. // Shows the hold status of the 5 dice.
  36. private CheckBox[] chbHolds;
  37. // Shows the results previously selected .
  38. // For free results (results not set yet), the results
  39. // corresponding to the actual face values of the 5 dice are shown.
  40. private TextField[] txfResults;
  41. // Shows points in sums, bonus and total.
  42. private TextField txfSumSame, txfBonus, txfSumOther, txfTotal;
  43. // Shows the number of times the dice has been rolled.
  44. private Label lblRolled;
  45.  
  46. private Button btnRoll;
  47.  
  48. private void initContent(GridPane pane) {
  49. pane.setGridLinesVisible(false);
  50. pane.setPadding(new Insets(10));
  51. pane.setHgap(10);
  52. pane.setVgap(10);
  53.  
  54. // ---------------------------------------------------------------------
  55.  
  56. GridPane dicePane = new GridPane();
  57. pane.add(dicePane, 0, 0, 40, 20);
  58. dicePane.setGridLinesVisible(false);
  59. dicePane.setPadding(new Insets(10));
  60. dicePane.setHgap(10);
  61. dicePane.setVgap(10);
  62. dicePane.setStyle("-fx-border-color: black");
  63.  
  64. // initialize txfValues, chbHolds, btnRoll and lblRolled
  65. // TODO
  66.  
  67. // ---------------------------------------------------------------------
  68.  
  69. GridPane scorePane = new GridPane();
  70. pane.add(scorePane, 0, 20, 40, 32);
  71. scorePane.setGridLinesVisible(false);
  72. scorePane.setPadding(new Insets(10));
  73. scorePane.setVgap(5);
  74. scorePane.setHgap(10);
  75. scorePane.setStyle("-fx-border-color: black");
  76. int w = 100; // width of the text fields
  77.  
  78. // Initialize labels for results, txfResults,
  79. // labels and text fields for sums, bonus and total.
  80. // TODO
  81.  
  82. txfValues = new TextField[5];
  83. for (int i = 0; i < txfValues.length; i++) {
  84. txfValues[i] = new TextField();
  85. dicePane.add(txfValues[i], i, 0, 1, 1);
  86. txfValues[i].setPrefHeight(100);
  87. txfValues[i].setPrefWidth(100);
  88. txfValues[i].setEditable(false);
  89.  
  90.  
  91. }
  92. chbHolds = new CheckBox[5];
  93. for (int i = 0; i < chbHolds.length; i++) {
  94. chbHolds[i] = new CheckBox("Hold");
  95. dicePane.add(chbHolds[i], i, 0, 1, 15);
  96.  
  97. }
  98.  
  99. txfResults = new TextField[15];
  100. for (int i = 0; i < txfResults.length; i++) {
  101. txfResults[i] = new TextField();
  102. scorePane.add(txfResults[i], 10, i, 10, 1);
  103. txfResults[i].setPrefWidth(w);
  104. txfResults[i].setEditable(false);
  105. }
  106.  
  107. Label[] lblResult = new Label[49];
  108. for (int i = 0; i < 6; i++) {
  109. lblResult[i] = new Label("" + (i + 1) + "-s");
  110. }
  111.  
  112. lblResult[1] = new Label("Rolled:");
  113. pane.add(lblResult[1], 35, 18);
  114.  
  115. lblResult[2] = new Label("1's:");
  116. pane.add(lblResult[2], 1, 21);
  117.  
  118. lblResult[3] = new Label("2's:");
  119. pane.add(lblResult[3], 1, 23);
  120.  
  121. lblResult[4] = new Label("3's:");
  122. pane.add(lblResult[4], 1, 25);
  123.  
  124. lblResult[5] = new Label("4's:");
  125. pane.add(lblResult[5], 1, 27);
  126.  
  127. lblResult[6] = new Label("5's:");
  128. pane.add(lblResult[6], 1, 29);
  129.  
  130. lblResult[7] = new Label("6's:");
  131. pane.add(lblResult[7], 1, 31);
  132.  
  133. // lblResult[8] = new Label("Sum:");
  134. // pane.add(lblResult[8], 10, 31);
  135. //
  136. // lblResult[9] = new Label("Bonus:");
  137. // pane.add(lblResult[9], 20, 31);
  138.  
  139. lblResult[8] = new Label("One Pair:");
  140. pane.add(lblResult[8], 1, 33);
  141.  
  142. lblResult[9] = new Label("Two Pair:");
  143. pane.add(lblResult[9], 1, 35);
  144.  
  145. lblResult[10] = new Label("Three Same:");
  146. pane.add(lblResult[10], 1, 37);
  147.  
  148. lblResult[11] = new Label("Four Same:");
  149. pane.add(lblResult[11], 1, 39);
  150.  
  151. lblResult[12] = new Label("Full House:");
  152. pane.add(lblResult[12], 1, 41);
  153.  
  154. lblResult[13] = new Label("Small Straight:");
  155. pane.add(lblResult[13], 1, 43);
  156.  
  157. lblResult[14] = new Label("Large Straight:");
  158. pane.add(lblResult[14], 1, 45);
  159.  
  160. lblResult[15] = new Label("Chance:");
  161. pane.add(lblResult[15], 1, 47);
  162.  
  163. lblResult[16] = new Label("Yatzy:");
  164. pane.add(lblResult[16], 1, 49);
  165.  
  166. // lblResult[19] = new Label("Sum:");
  167. // pane.add(lblResult[19], 10, 49);
  168. //
  169. // lblResult[20] = new Label("Total:");
  170. // pane.add(lblResult[20], 20, 49);
  171.  
  172. }
  173.  
  174. // -------------------------------------------------------------------------
  175.  
  176. private Yatzy dice = new Yatzy();
  177.  
  178. // Create a method for btnRoll's action.
  179. // Hint: Create small helper methods to be used in the action method.
  180. // TODO
  181.  
  182. // -------------------------------------------------------------------------
  183.  
  184. // Create a method for mouse click on one of the text fields in txfResults.
  185. // Hint: Create small helper methods to be used in the mouse click method.
  186. // TODO
  187.  
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement