diff options
| author | loic <git-account@loicguegan.fr> | 2016-09-22 20:52:19 +0200 |
|---|---|---|
| committer | loic <git-account@loicguegan.fr> | 2016-09-22 20:52:19 +0200 |
| commit | 641043d526811d23693afafe300a4aa29827d60e (patch) | |
| tree | 5fd8cf6cc9c4ccc58aa2743dd22602199fecba89 | |
| parent | d794981f82a7de6f3f0841d3d1a2905daada60c6 (diff) | |
Add 2 and 4
| -rw-r--r-- | src/main/java/controller/MainWindowController.java | 75 |
1 files 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; i<board.length;i++) { for (int j = 0; j < board[i].length; j++) { - gc.setFill(Color.GRAY); + int value=board[i][j]; + switch (value){ + case -1: + gc.setFill(Color.rgb(202,192,180)); + break; + case 2: + gc.setFill(Color.rgb(236,226,217)); + break; + case 4: + gc.setFill(Color.rgb(237,222,199)); + break; + case 8: + gc.setFill(Color.rgb(241,175,115)); + break; + case 16: + gc.setFill(Color.rgb(242,151,94)); + break; + case 32: + gc.setFill(Color.rgb(242,151,94)); + break; + case 64: + gc.setFill(Color.rgb(244,123,96)); + break; + case 128: + gc.setFill(Color.rgb(233,206,115)); + break; + case 256: + gc.setFill(Color.rgb(233,206,115)); + break; + case 512: + gc.setFill(Color.rgb(237,197,84)); + break; + case 1024: + gc.setFill(Color.rgb(234,197,57)); + break; + case 2048: + gc.setFill(Color.rgb(233,193,43)); + break; + default: + gc.setFill(Color.BLACK); + break; + } + int x=this.boardPosition[0] + (j*this.squareSize); int y=this.boardPosition[1] + (i*this.squareSize); @@ -104,14 +148,31 @@ public class MainWindowController implements IObserver { } gc.fillRect(x,y, this.squareSize, this.squareSize); - gc.setFill(Color.BLACK); - int value=board[i][j]; - if(value<0){ - value=0; + if(value>2048) { + 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)); } } |
