From cf931bc928fed780add07252f96c6dbb91b604ff Mon Sep 17 00:00:00 2001 From: loic Date: Thu, 22 Sep 2016 21:51:26 +0200 Subject: [PATCH] Add 2 and 4 --- .../java/controller/MainWindowController.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/controller/MainWindowController.java b/src/main/java/controller/MainWindowController.java index 793276b..e92af36 100644 --- a/src/main/java/controller/MainWindowController.java +++ b/src/main/java/controller/MainWindowController.java @@ -9,6 +9,7 @@ import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; +import javafx.scene.control.Button; import javafx.scene.input.KeyEvent; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; @@ -16,6 +17,7 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import model.Board; import model.IModel; +import model.LineAlgorithm; import observer.IObserver; @@ -25,23 +27,23 @@ import observer.IObserver; public class MainWindowController implements IObserver { @FXML Canvas boardCanvas; - + @FXML Text score; + @FXML Button restartButton; private ModelAdapter adapter; private IModel model; private int squareSize=100; private int squarePadding=10; - private int[] boardPosition={0,0}; + private int[] boardPosition={40,0}; private int fontSize=60; - - public void loadComponent(ModelAdapter adapter, IModel model, Scene scene){ this.adapter=adapter; this.model=model; this.update(); + scene.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent event) { @@ -60,6 +62,7 @@ public class MainWindowController implements IObserver { } }); + } @FXML protected void goUp(ActionEvent event) { @@ -80,11 +83,32 @@ public class MainWindowController implements IObserver { this.draw(); } + @FXML private void restartGame(ActionEvent event){ + IModel model=new Board(4,4); + ModelAdapter adapter=new ModelAdapter((Board) model); + adapter.addObserver(this); + adapter.addRandomNumber(); + this.adapter=adapter; + this.model=model; + this.update(); + + } private void draw(){ + + + this.score.setFont(new Font(40)); + + if(this.adapter.isLoosed()){ + this.score.setText("Score : " + this.model.getScore() + " ----- YOU LOOSE !!"); + } + else{ + this.score.setText("Score : " + this.model.getScore()); + } + GraphicsContext gc = boardCanvas.getGraphicsContext2D(); gc.clearRect(0,0,500,500); int[][] board=this.model.getBoard();