/** * @file Common.java * * @author Christos Choutouridis AEM:8997 * @email cchoutou@ece.auth.gr */ package net.hoo2.auth.labyrinth; /** * Application wide object to hold settings like values for the session. */ class Defaults { static int boardSize = 15; /**@< Default board's size (if no one set it via command line) */ } /** * Helper C++-like enumerator class to hold direction */ class Direction { static final int UP =1; /**< North direction */ static final int RIGHT =3; /**< East direction */ static final int DOWN =5; /**< South direction */ static final int LEFT =7; /**< West direction */ } /** * @brief * An Application wide board position implementation holding just the coordinates * * Position is a helper class to enable us cope with the redundant position data (id and coordinates). * This class provide both static conversion functionalities between id and coordinates * and data representation in the coordinates system. */ class Position { /** * Basic constructor from coordinates * @param x The x coordinate * @param y The y coordinate */ protected Position(int x, int y) { this.x = x; this.y = y; } /** * Basic constructor from Id * @param tileId The id of tile */ protected Position(int tileId) { this.x = toX(tileId); this.y = toY(tileId); } /** @name non-static API */ /** @{ */ protected int getX() { return x; } /**< Read access to x coordinate */ protected int getY() { return y; } /**< Read access to y coordinate */ protected int getID(){ return toID(x, y); } /**< Virtual read access to id coordinate */ /** @} */ /** @name Static convention utilities */ /** @{ */ /** * Takes x and y coordinates and return the calculated Id coordinate * @param x The x coordinate * @param y The y coordinate * @return The converted value */ protected static int toID(int x, int y) { return y * Defaults.boardSize + x; } /** * Takes Id coordinate and return the corresponding x coordinate * @param id The id coordinate * @return The x coordinate */ protected static int toX(int id){ return id % Defaults.boardSize; } /** * Takes Id coordinate and return the corresponding y coordinate * @param id The id coordinate * @return The y coordinate */ protected static int toY(int id) { return id / Defaults.boardSize; } /** @} */ /** @name private data types */ /** @{ */ private int x; /**< The x coordinate of the constructed Position object */ private int y; /**< The y coordinate of the constructed Position object */ /** @} */ }