Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import model.GameSystem;
- import javafx.animation.KeyFrame;
- import javafx.animation.KeyValue;
- import javafx.animation.Timeline;
- import javafx.event.ActionEvent;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Label;
- import javafx.scene.control.ProgressBar;
- import javafx.scene.control.ToggleButton;
- import javafx.scene.input.MouseButton;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.GridPane;
- import javafx.scene.media.MediaPlayer;
- import javafx.scene.shape.Circle;
- import javafx.util.Duration;
- import model.CardPane;
- import javax.swing.text.html.ImageView;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.ResourceBundle;
- public class Controller implements Initializable {
- public Label scoreDisplay;
- private int cardPicks = 0;
- private GameSystem thisgame = new GameSystem();
- public Circle soundButton;
- public MediaPlayer player;
- public ToggleButton muteBt;
- public ProgressBar timeBar;
- public Label timeLabel;
- public GridPane boardOfCards;
- private void loadRandomCard(){
- CardPane.setFlip(true);
- ArrayList <Integer> listOfId = new ArrayList <Integer>();
- for (int x = 0; x < 4; x++){
- for (int y = 0; y < 5; y++){
- do{
- CardPane card = new CardPane();
- int copies = 0;
- for (int i : listOfId){
- if ( card.getid() == i ){
- copies++;
- }
- }
- if (copies == 2) {
- CardPane.sizeDownPool(card.getid());
- }
- else if (copies < 2){
- boardOfCards.add(card, y, x);
- listOfId.add(card.getid());
- break;
- }
- } while (true);
- }
- }
- }
- private void countDown(){
- Timeline timeline = new Timeline(
- new KeyFrame(Duration.seconds(120),
- new KeyValue(timeBar.progressProperty(), 0)
- )
- );
- timeline.currentTimeProperty().addListener((observableValue, oldvalue, newvalue) ->{
- timeLabel.setText(fomartTime(new Duration(120000-newvalue.toMillis())));
- });
- timeline.setDelay(Duration.seconds(3));
- timeline.play();
- }
- private String fomartTime (Duration t){
- return String.format("0%d:%d:%d", (int)t.toMinutes(), (int)(t.toSeconds() % 60), (int)(t.toMillis() %100));
- }
- public void mute(ActionEvent mouseEvent) {
- if (player.getStatus() == MediaPlayer.Status.PLAYING){
- player.pause();
- muteBt.setText("Sound Off");
- }
- else {
- muteBt.setText("Sound On");
- player.play();
- }
- }
- @Override
- public void initialize(URL url, ResourceBundle resourceBundle) {
- loadRandomCard();
- countDown();
- }
- public void cardClick(MouseEvent mouseEvent) {
- if (mouseEvent.getClickCount() == 1 || mouseEvent.getClickCount() == 2) {
- if (++cardPicks == 2) {
- CardPane.setFlip(false);
- cardPicks = 0;
- } else {
- CardPane.setFlip(true);
- }
- }
- scoreDisplay.setText(String.valueOf(thisgame.getScore()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement