This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum TerrainType implements MovementEffects, ImageProviderFactory { | |
| OPEN(0), | |
| SAND(1), | |
| HILLS(2), | |
| MOUNTAINS(3), | |
| ALPINE(IMPASSABLE), | |
| MARSH(3), | |
| WATER(IMPASSABLE), | |
| CROPLANDS(1), | |
| URBAN(0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testEnumMap() throws Exception { | |
| System.out.println("\n*** Testing enum maps manipulation ***\n"); | |
| System.out.println("Creating enum maps..."); | |
| Map<TerrainType, String> enumMap = new EnumMap<TerrainType, String>(TerrainType.class); | |
| Set<TerrainType> woods = EnumSet.of(TerrainType.FOREST, TerrainType.LIGHT_WOODS); | |
| for (TerrainType terrainType : woods) { | |
| enumMap.put(terrainType, terrainType.name().toLowerCase() + ".png"); | |
| } | |
| System.out.println(enumMap); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testEnumSet() throws Exception { | |
| System.out.println("\n*** Testing enum sets manipulation ***\n"); | |
| System.out.println("Creating enum sets..."); | |
| Set<TerrainType> anyTerrain = EnumSet.allOf(TerrainType.class); | |
| Set<TerrainType> emptyTerrain = EnumSet.noneOf(TerrainType.class); | |
| Set<TerrainType> stream = EnumSet.of(TerrainType.RIVER, TerrainType.SUPER_RIVER); | |
| Set<TerrainType> woods = EnumSet.of(TerrainType.FOREST, TerrainType.LIGHT_WOODS); | |
| Set<TerrainType> water = EnumSet.of(TerrainType.WATER); | |
| Set<TerrainType> land = EnumSet.complementOf((EnumSet<TerrainType>) water); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testEnumManipulation() throws Exception { | |
| System.out.println("*** Testing enum manipulation ***\n"); | |
| System.out.println("Listing all enum values..."); | |
| TerrainType[] allTerrainTypes = TerrainType.values(); | |
| for (TerrainType tt : allTerrainTypes) { | |
| System.out.println(tt.ordinal() + ": " + tt.name()); | |
| } | |
| System.out.println("Basic usage of enums..."); | |
| TerrainType t1 = TerrainType.FOREST; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum TerrainType implements MovementEffects{ | |
| OPEN(0), | |
| SAND(1), | |
| HILLS(2), | |
| MOUNTAINS(3), | |
| ALPINE(IMPASSABLE), | |
| MARSH(3), | |
| WATER(IMPASSABLE), | |
| CROPLANDS(1), | |
| URBAN(0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum UnitType { | |
| LIGHT_INFANTRY(4, 6), | |
| INFANTRY(3, 6), | |
| LIGHT_CAVALRY(5, 10), | |
| HEAVY_CAVALRY(4, 8), | |
| ARTILLERY(2, 4), | |
| HORSE_ARTILLERY(2, 8); | |
| private final int line; | |
| private final int column; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Util { | |
| public static boolean isEven(int number) { | |
| return (number & 1) == 0; | |
| } | |
| public static boolean isOdd(int number) { | |
| return (number & 1) == 1; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum Direction { | |
| N(0, -1, -1), | |
| NE(1, 0, -1), | |
| SE(1, 1, 0), | |
| S(0, 1, 1), | |
| SW(-1, 1, 0), | |
| NW(-1, 0, -1), | |
| C(0, 0, 0); | |
| private final int incColumn; | |
| private final int incRowEven; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.swing.*; | |
| import java.awt.*; | |
| public class HexagonalMap extends JPanel { | |
| private int width; // Number of columns | |
| private int height; // Number of rows | |
| private int hexSide; // Side of the hexagon | |
| private int hexOffset; // Distance from left horizontal vertex to vertical axis | |
| private int hexApotheme; // Apotheme of the hexagon = radius of inscribed circumference | |
| private int hexRectWidth; // Width of the circumscribed rectangle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.swing.*; | |
| import java.awt.*; | |
| import java.awt.event.MouseEvent; | |
| import java.awt.event.MouseMotionAdapter; | |
| public class HexagonalMapGUI extends JFrame { | |
| static final int HEX_SIDE = 25; // side of hexagonal tile in pixels | |
| static final int MAP_WIDTH = 10; // number of columns | |
| static final int MAP_HEIGHT = 10; // number of rows | |
| private HexagonalMap map; |
NewerOlder