Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. import model.GameSystem;
  2. import javafx.animation.KeyFrame;
  3. import javafx.animation.KeyValue;
  4.  
  5. import javafx.animation.Timeline;
  6. import javafx.event.ActionEvent;
  7. import javafx.fxml.Initializable;
  8.  
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.ProgressBar;
  11.  
  12. import javafx.scene.control.ToggleButton;
  13.  
  14.  
  15. import javafx.scene.input.MouseButton;
  16. import javafx.scene.input.MouseEvent;
  17. import javafx.scene.layout.GridPane;
  18.  
  19. import javafx.scene.media.MediaPlayer;
  20. import javafx.scene.shape.Circle;
  21.  
  22. import javafx.util.Duration;
  23. import model.CardPane;
  24.  
  25.  
  26. import javax.swing.text.html.ImageView;
  27. import java.net.URL;
  28.  
  29. import java.util.ArrayList;
  30. import java.util.ResourceBundle;
  31.  
  32.  
  33.  
  34. public class Controller implements Initializable {
  35. public Label scoreDisplay;
  36. private int cardPicks = 0;
  37. private GameSystem thisgame = new GameSystem();
  38. public Circle soundButton;
  39. public MediaPlayer player;
  40. public ToggleButton muteBt;
  41. public ProgressBar timeBar;
  42. public Label timeLabel;
  43. public GridPane boardOfCards;
  44.  
  45.  
  46.  
  47. private void loadRandomCard(){
  48. CardPane.setFlip(true);
  49.  
  50.  
  51.  
  52. ArrayList <Integer> listOfId = new ArrayList <Integer>();
  53.  
  54. for (int x = 0; x < 4; x++){
  55. for (int y = 0; y < 5; y++){
  56.  
  57. do{
  58. CardPane card = new CardPane();
  59.  
  60. int copies = 0;
  61. for (int i : listOfId){
  62. if ( card.getid() == i ){
  63. copies++;
  64. }
  65. }
  66. if (copies == 2) {
  67. CardPane.sizeDownPool(card.getid());
  68. }
  69. else if (copies < 2){
  70. boardOfCards.add(card, y, x);
  71. listOfId.add(card.getid());
  72. break;
  73. }
  74.  
  75.  
  76. } while (true);
  77.  
  78. }
  79. }
  80. }
  81.  
  82.  
  83.  
  84. private void countDown(){
  85. Timeline timeline = new Timeline(
  86. new KeyFrame(Duration.seconds(120),
  87. new KeyValue(timeBar.progressProperty(), 0)
  88. )
  89.  
  90. );
  91.  
  92. timeline.currentTimeProperty().addListener((observableValue, oldvalue, newvalue) ->{
  93.  
  94. timeLabel.setText(fomartTime(new Duration(120000-newvalue.toMillis())));
  95.  
  96.  
  97. });
  98. timeline.setDelay(Duration.seconds(3));
  99. timeline.play();
  100. }
  101. private String fomartTime (Duration t){
  102.  
  103. return String.format("0%d:%d:%d", (int)t.toMinutes(), (int)(t.toSeconds() % 60), (int)(t.toMillis() %100));
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. public void mute(ActionEvent mouseEvent) {
  112. if (player.getStatus() == MediaPlayer.Status.PLAYING){
  113. player.pause();
  114. muteBt.setText("Sound Off");
  115. }
  116. else {
  117. muteBt.setText("Sound On");
  118. player.play();
  119. }
  120.  
  121. }
  122.  
  123. @Override
  124. public void initialize(URL url, ResourceBundle resourceBundle) {
  125.  
  126. loadRandomCard();
  127. countDown();
  128.  
  129.  
  130.  
  131. }
  132.  
  133. public void cardClick(MouseEvent mouseEvent) {
  134.  
  135.  
  136. if (mouseEvent.getClickCount() == 1 || mouseEvent.getClickCount() == 2) {
  137.  
  138. if (++cardPicks == 2) {
  139. CardPane.setFlip(false);
  140. cardPicks = 0;
  141. } else {
  142. CardPane.setFlip(true);
  143.  
  144. }
  145. }
  146. scoreDisplay.setText(String.valueOf(thisgame.getScore()));
  147.  
  148.  
  149.  
  150.  
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement