Skip to content
Snippets Groups Projects
Select Git revision
  • c94ace50622a58f4a086a7e7ff71d5626dbaef2f
  • main default protected
2 results

GameController.java

Blame
  • Forked from TRAVERS Corentin / flooding-template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GameController.java 4.72 KiB
    package controller;
    
    import javafx.animation.PauseTransition;
    import javafx.fxml.FXML;
    import javafx.scene.control.Label;
    import javafx.scene.paint.Color;
    import javafx.util.Duration;
    import model.*;
    import view.MatrixPane;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    public class GameController {
        public static final Color COLOR_ONE   = Color.RED;
        public static final Color COLOR_TWO   = Color.NAVAJOWHITE;
        public static final Color COLOR_THREE = Color.GRAY;
        public static final Color COLOR_FOUR  = Color.GREEN;
        private static final List<Color> availableColors = List.of(COLOR_ONE, COLOR_TWO, COLOR_THREE, COLOR_FOUR);
    
        public static final double PAUSE_MILLISECONDS = 400;
        private final PauseTransition pause = new PauseTransition(Duration.millis(PAUSE_MILLISECONDS));
    
    
    
        private final Random random = new Random();
    
        @FXML
        MatrixPane matrixPane;
    
        @FXML
        private Label scoreLabel;
    
        @FXML
        private Label tourLabel;
    
        private FloodGame game;
    
    
        public void initialize(){
            this.game = new FloodGame(matrixPane.getGrid().getNumberOfColumns()  * matrixPane.getGrid().getNumberOfRows());
            setPlayerHuman();
            matrixPane.setGameController(this);
            setScoreLabelTextProperty();
            setTourLabelTextProperty();
            addTurnListener();
            setPauseAnimation();
        }
    
    
    
        private void addTurnListener(){
            game.getTurnProperty().addListener((observable, oldValue, newValue) -> playComputerTurn());
        }
    
    
    
        private void colorGrid(ColorGenerator colorGenerator){
            // TODO
            matrixPane.getGrid().color(colorGenerator);
    
        }
    
    
        @FXML
        public void fillGridUniform() {
              colorGrid(new UniformColorGenerator(COLOR_ONE));
    
        }