Add 2 and 4

This commit is contained in:
loic 2016-09-22 21:51:26 +02:00
parent 93953a52ce
commit cf931bc928

View file

@ -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<KeyEvent>() {
@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();