package view; import javafx.scene.control.Label; import javafx.scene.paint.Color; import javafx.scene.shape.Polygon; import model.Move; import model.Tile; /** * Class that makes the association between a tile from the model and its representation */ public class TileView { private Polygon fxTile; private Tile modelTile; private Label fishLabel; private boolean selected, highlighted; private Move highlightMove = null; // How do we get here from the selected tile (used when highlighting) public TileView(Polygon fxTile, Tile modelTile, Label fishLabel) { this.fxTile = fxTile; this.modelTile = modelTile; this.fishLabel = fishLabel; } /** * Tell the view to update according to the model */ public void update() { //TODO: Better tile representation Color fillColor = null; //FISH NUMBER if(modelTile.getNbFish() == 0) { fishLabel.setText(""); fillColor = Color.WHITE; } else { fishLabel.setText(Integer.toString(modelTile.getNbFish())); fillColor = Color.LIGHTBLUE; } //PENGUIN if (modelTile.getPenguinPresence().equals(Tile.PenguinPresence.RED_PENGUIN)) fillColor = Color.RED; else if (modelTile.getPenguinPresence().equals(Tile.PenguinPresence.BLUE_PENGUIN)) fillColor = Color.BLUE; //SELECTION/HIGHLIGHT if (selected) fillColor = fillColor.deriveColor(0, 0.5, 1, 1); if (highlighted) fillColor = fillColor.deriveColor(0, 1, 0.5, 1); fxTile.setFill(fillColor); } public Tile getModelTile() { return modelTile; } public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } public boolean isHighlighted() { return highlighted; } public void setHighlighted(boolean highlighted) { this.highlighted = highlighted; } public Move getHighlightMove() { return highlightMove; } public void setHighlightMove(Move highlightMove) { this.highlightMove = highlightMove; } }