Skip to content

Commit

Permalink
Add comments to step 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Mw3y committed Apr 8, 2024
1 parent 9c79e8a commit 50ad631
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
32 changes: 29 additions & 3 deletions src/ch/epfl/chacun/gui/ColorMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@
import ch.epfl.chacun.PlayerColor;
import javafx.scene.paint.Color;

/**
* Helper class to map player colors to JavaFX colors.
*
* @author Maxence Espagnet (sciper: 372808)
* @author Balthazar Baillat (sciper: 373420)
*/
public final class ColorMap {

private static final double OPACITY_FACTOR = .6;
/**
* The opacity factor to use for the stroke color.
*/
private static final double STROKE_OPACITY_FACTOR = .6;

// Non-instantiable
/**
* Non-instantiable class constructor
*/
private ColorMap() {
}

/**
* Returns the fill color for the given player color.
*
* @param playerColor the player color
* @return the fill color
*/
public static Color fillColor(PlayerColor playerColor) {
return switch (playerColor) {
case RED -> Color.RED;
Expand All @@ -21,9 +38,18 @@ public static Color fillColor(PlayerColor playerColor) {
};
}

/**
* Returns the stroke color for the given player color.
*
* @param playerColor the player color
* @return the stroke color
*/
public static Color strokeColor(PlayerColor playerColor) {
// For better contrast with light colors, use a darker stroke color
if (playerColor == PlayerColor.YELLOW || playerColor == PlayerColor.GREEN)
return fillColor(playerColor).deriveColor(0, 1, 1, OPACITY_FACTOR);
return fillColor(playerColor)
.deriveColor(0, 1, 1, STROKE_OPACITY_FACTOR);
// For dark colors, use a lighter stroke color
return Color.WHITE;
}

Expand Down
24 changes: 23 additions & 1 deletion src/ch/epfl/chacun/gui/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@
import javafx.scene.Node;
import javafx.scene.shape.SVGPath;

/**
* Helper class to create an icon for a player color and occupant kind.
*
* @author Maxence Espagnet (sciper: 372808)
* @author Balthazar Baillat (sciper: 373420)
*/
public final class Icon {

/**
* The pawn icon SVG path
*/
private final static String PAWN_SVG_PATH = "M -10 10 H -4 L 0 2 L 6 10 H 12 L 5 0 L 12 -2 L 12 -4 L 6 -6 L 6 -10 L 0 -10 L -2 -4 L -6 -2 L -8 -10 L -12 -10 L -8 6 Z";

/**
* The hut icon SVG path
*/
private final static String HUT_SVG_PATH = "M -8 10 H 8 V 2 H 12 L 0 -10 L -12 2 H -8 Z";

// Non-instantiable
/**
* Non-instantiable class constructor
*/
private Icon() {
}

/**
* Creates a new icon for the given player color and occupant kind.
*
* @param playerColor the player color
* @param occupantKind the occupant kind
* @return the icon node
*/
public static Node newFor(PlayerColor playerColor, Occupant.Kind occupantKind) {
SVGPath occupantIcon = new SVGPath();
occupantIcon.setFill(ColorMap.fillColor(playerColor));
Expand Down

0 comments on commit 50ad631

Please sign in to comment.