From 641043d526811d23693afafe300a4aa29827d60e Mon Sep 17 00:00:00 2001 From: loic Date: Thu, 22 Sep 2016 20:52:19 +0200 Subject: [PATCH] Add 2 and 4 --- .../java/controller/MainWindowController.java | 75 +++++++++++++++++-- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/src/main/java/controller/MainWindowController.java b/src/main/java/controller/MainWindowController.java index 0d59029..793276b 100644 --- a/src/main/java/controller/MainWindowController.java +++ b/src/main/java/controller/MainWindowController.java @@ -12,6 +12,7 @@ import javafx.scene.canvas.GraphicsContext; import javafx.scene.input.KeyEvent; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; +import javafx.scene.text.Font; import javafx.scene.text.Text; import model.Board; import model.IModel; @@ -28,9 +29,10 @@ public class MainWindowController implements IObserver { private ModelAdapter adapter; private IModel model; - private int squareSize=50; + private int squareSize=100; private int squarePadding=10; private int[] boardPosition={0,0}; + private int fontSize=60; @@ -91,7 +93,49 @@ public class MainWindowController implements IObserver { for(int i=0; i2048) { + gc.setFill(Color.WHITE); + } + else{ + gc.setFill(Color.BLACK); + + } + + if(value>0){ + String strValue=""+value; + int localFontSize=fontSize; + if(strValue.length()==3){ + localFontSize=localFontSize/2; + }else if(strValue.length()==4){ + localFontSize=localFontSize/3; + } + else if(strValue.length()>4){ + localFontSize=localFontSize/4; + } + + gc.setFont(new Font(localFontSize)); + gc.fillText(strValue, x + (this.squareSize / 2) - ((localFontSize/3)+strValue.length()*localFontSize/5) , y + (this.squareSize / 2) + (localFontSize /3)); } - gc.fillText("" + value, x + (this.squareSize / 2), y + (this.squareSize / 2)); } }