Add 2 and 4

This commit is contained in:
loic 2016-09-22 20:52:19 +02:00
parent d794981f82
commit 641043d526

View file

@ -12,6 +12,7 @@ import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import model.Board; import model.Board;
import model.IModel; import model.IModel;
@ -28,9 +29,10 @@ public class MainWindowController implements IObserver {
private ModelAdapter adapter; private ModelAdapter adapter;
private IModel model; private IModel model;
private int squareSize=50; private int squareSize=100;
private int squarePadding=10; private int squarePadding=10;
private int[] boardPosition={0,0}; 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 i=0; i<board.length;i++) {
for (int j = 0; j < board[i].length; j++) { 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 x=this.boardPosition[0] + (j*this.squareSize);
int y=this.boardPosition[1] + (i*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.fillRect(x,y, this.squareSize, this.squareSize);
gc.setFill(Color.BLACK);
int value=board[i][j]; if(value>2048) {
if(value<0){ gc.setFill(Color.WHITE);
value=0; }
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));
} }
} }