Skip to content
Snippets Groups Projects
Select Git revision
  • b374828ea27215d62502f2fe7d134478987eba79
  • main default protected
2 results

Tile.java

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Tile.java 977 B
    package model;
    
    import javafx.scene.paint.Color;
    
    import java.util.Arrays;
    import java.util.HashMap;
    
    public class Tile {
      private static final int NUMBER_OF_SIDES = 4;
      private final Color colors[] = new Color[NUMBER_OF_SIDES];
    
      public Tile(Color[] colors) {
        if(colors.length != NUMBER_OF_SIDES)
          throw new IllegalArgumentException("A tile is defined by " + NUMBER_OF_SIDES
                                                + "and not" + colors.length + "sides.");
        for(int index = 0; index < NUMBER_OF_SIDES; index++)
          this.colors[index] = colors[index];
      }
    
      public Color getColor(CardinalDirection direction){
        return colors[direction.ordinal()];
      }
    
      @Override
      public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tile tile = (Tile) o;
        return Arrays.equals(colors, tile.colors);
      }
    
      @Override
      public int hashCode() {
        return Arrays.hashCode(colors);
      }
    }