From: Erik V. <ev...@us...> - 2009-11-02 23:31:00
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29771/rails/game Modified Files: MapHex.java MapManager.java PublicCompany.java Log Message: More rationalising of static method usage Index: MapManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapManager.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** MapManager.java 31 Oct 2009 17:08:27 -0000 1.11 --- MapManager.java 2 Nov 2009 23:30:36 -0000 1.12 *************** *** 12,24 **** private String mapUIClassName = null; - private static MapManager instance = null; // The next attributes are duplicates in MapHex. We'll see what we really // need. ! protected static int tileOrientation; ! protected static boolean lettersGoHorizontal; ! protected static boolean letterAHasEvenNumbers; ! protected static MapHex[][] hexes; protected Map<String, MapHex> mHexes = new HashMap<String, MapHex>(); protected int maxX, maxY; --- 12,23 ---- private String mapUIClassName = null; // The next attributes are duplicates in MapHex. We'll see what we really // need. ! protected int tileOrientation; ! protected boolean lettersGoHorizontal; ! protected boolean letterAHasEvenNumbers; ! protected MapHex[][] hexes; protected Map<String, MapHex> mHexes = new HashMap<String, MapHex>(); protected int maxX, maxY; *************** *** 36,40 **** public MapManager() { - instance = this; } --- 35,38 ---- *************** *** 53,60 **** if (attr.equals("EW")) { tileOrientation = MapHex.EW; - MapHex.setTileOrientation(MapHex.EW); } else if (attr.equals("NS")) { tileOrientation = MapHex.NS; - MapHex.setTileOrientation(MapHex.NS); } else { throw new ConfigurationException("Invalid tile orientation: " --- 51,56 ---- *************** *** 71,79 **** + attr); } - MapHex.setLettersGoHorizontal(lettersGoHorizontal); attr = tag.getAttributeAsString("even"); letterAHasEvenNumbers = ((attr.toUpperCase().charAt(0) - 'A')) % 2 == 0; - MapHex.setLetterAHasEvenNumbers(letterAHasEvenNumbers); List<Tag> hexTags = tag.getChildren("Hex"); --- 67,73 ---- *************** *** 116,120 **** for (j = 0; j <= maxY; j++) { if ((hex = hexes[i][j]) == null) continue; ! for (k = 0; k < 6; k++) { if (tileOrientation == MapHex.EW) { --- 110,114 ---- for (j = 0; j <= maxY; j++) { if ((hex = hexes[i][j]) == null) continue; ! for (k = 0; k < 6; k++) { if (tileOrientation == MapHex.EW) { *************** *** 150,163 **** /** - * @return an instance of the MapManager - */ - public static MapManager getInstance() { - return instance; - } - - /** * @return Returns the letterAHasEvenNumbers. */ ! public static boolean letterAHasEvenNumbers() { return letterAHasEvenNumbers; } --- 144,150 ---- /** * @return Returns the letterAHasEvenNumbers. */ ! public boolean letterAHasEvenNumbers() { return letterAHasEvenNumbers; } *************** *** 166,170 **** * @return Returns the lettersGoHorizontal. */ ! public static boolean lettersGoHorizontal() { return lettersGoHorizontal; } --- 153,157 ---- * @return Returns the lettersGoHorizontal. */ ! public boolean lettersGoHorizontal() { return lettersGoHorizontal; } *************** *** 173,177 **** * @return Returns the currentTileOrientation. */ ! public static int getTileOrientation() { return tileOrientation; } --- 160,164 ---- * @return Returns the currentTileOrientation. */ ! public int getTileOrientation() { return tileOrientation; } *************** *** 202,207 **** return stations; } ! ! public List<MapHex> parseLocations (String locationCodes) throws ConfigurationException { --- 189,194 ---- return stations; } ! ! public List<MapHex> parseLocations (String locationCodes) throws ConfigurationException { *************** *** 218,222 **** } } ! return locations; } --- 205,209 ---- } } ! return locations; } Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** MapHex.java 31 Oct 2009 17:08:26 -0000 1.28 --- MapHex.java 2 Nov 2009 23:30:36 -0000 1.29 *************** *** 42,48 **** public static final int EW = 0; public static final int NS = 1; - protected static int tileOrientation; - protected static boolean lettersGoHorizontal; - protected static boolean letterAHasEvenNumbers; private static final String[] ewOrNames = --- 42,45 ---- *************** *** 93,97 **** /** Tokens that are not bound to a Station (City), such as Bonus tokens */ protected List<TokenI> offStationTokens; ! protected MapManager mapManager = null; --- 90,94 ---- /** Tokens that are not bound to a Station (City), such as Bonus tokens */ protected List<TokenI> offStationTokens; ! protected MapManager mapManager = null; *************** *** 125,132 **** * drawing. */ ! if (lettersGoHorizontal) { row = number; column = letter - '@'; ! if (tileOrientation == MapHex.EW) { // Tiles with flat EW sides, letters go horizontally. // Example: 1841 (NOT TESTED, PROBABLY WRONG). --- 122,129 ---- * drawing. */ ! if (lettersGoHorizontal()) { row = number; column = letter - '@'; ! if (getTileOrientation() == MapHex.EW) { // Tiles with flat EW sides, letters go horizontally. // Example: 1841 (NOT TESTED, PROBABLY WRONG). *************** *** 144,152 **** row = letter - '@'; column = number; ! if (tileOrientation == MapHex.EW) { // Tiles with flat EW sides, letters go vertically. // Most common case. // Tested for 1830 and 1870. ! x = (column + (letterAHasEvenNumbers ? 1 : 0)) / 2; y = row; } else { --- 141,149 ---- row = letter - '@'; column = number; ! if (getTileOrientation() == MapHex.EW) { // Tiles with flat EW sides, letters go vertically. // Most common case. // Tested for 1830 and 1870. ! x = (column + (letterAHasEvenNumbers() ? 1 : 0)) / 2; y = row; } else { *************** *** 174,178 **** public void finishConfiguration (GameManagerI gameManager) { ! currentTile = gameManager.getTileManager().getTile(preprintedTileId); // We need completely new objects, not just references to the Tile's --- 171,175 ---- public void finishConfiguration (GameManagerI gameManager) { ! currentTile = gameManager.getTileManager().getTile(preprintedTileId); // We need completely new objects, not just references to the Tile's *************** *** 210,223 **** } ! public static void setTileOrientation(int orientation) { ! tileOrientation = orientation; ! } ! ! public static int getTileOrientation() { ! return tileOrientation; ! } ! ! public static void setLettersGoHorizontal(boolean b) { ! lettersGoHorizontal = b; } --- 207,212 ---- } ! public int getTileOrientation() { ! return mapManager.getTileOrientation(); } *************** *** 225,237 **** * @return Returns the letterAHasEvenNumbers. */ ! public static boolean hasLetterAEvenNumbers() { ! return letterAHasEvenNumbers; ! } ! ! /** ! * @param letterAHasEvenNumbers The letterAHasEvenNumbers to set. ! */ ! public static void setLetterAHasEvenNumbers(boolean letterAHasEvenNumbers) { ! MapHex.letterAHasEvenNumbers = letterAHasEvenNumbers; } --- 214,219 ---- * @return Returns the letterAHasEvenNumbers. */ ! public boolean letterAHasEvenNumbers() { ! return mapManager.letterAHasEvenNumbers(); } *************** *** 239,249 **** * @return Returns the lettersGoHorizontal. */ ! public static boolean isLettersGoHorizontal() { ! return lettersGoHorizontal; } ! public static String getOrientationName(int orientation) { ! if (tileOrientation == EW) { return ewOrNames[orientation % 6]; } else { --- 221,231 ---- * @return Returns the lettersGoHorizontal. */ ! public boolean lettersGoHorizontal() { ! return mapManager.lettersGoHorizontal(); } ! public String getOrientationName(int orientation) { ! if (getTileOrientation() == EW) { return ewOrNames[orientation % 6]; } else { *************** *** 322,352 **** } - /** Look for the Hex matching the Label in the terrain static map */ - /* EV: useful, but needs to be rewritten */ - public static MapHex getHexByLabel(String terrain, String label) { - /* - * int x = 0; int y = Integer.parseInt(new String(label.substring(1))); - * switch (label.charAt(0)) { case 'A': case 'a': x = 0; break; - * - * case 'B': case 'b': x = 1; break; - * - * case 'C': case 'c': x = 2; break; - * - * case 'D': case 'd': x = 3; break; - * - * case 'E': case 'e': x = 4; break; - * - * case 'F': case 'f': x = 5; break; - * - * case 'X': case 'x': // entrances GUIHex[] gameEntrances = (GUIHex[]) - * entranceHexes.get(terrain); return gameEntrances[y].getMapHexModel(); - * - * default: Log.error("Label " + label + " is invalid"); } y = 6 - y - - * (int) Math.abs(((x - 3) / 2)); GUIHex[][] correctHexes = (GUIHex[][]) - * terrainH.get(terrain); return correctHexes[x][y].getMapHexModel(); - */ - return null; - } - public int getTileCost() { if (currentTile.getId() == preprintedTileId) { --- 304,307 ---- *************** *** 963,967 **** return false; } ! public MapManager getMapManager() { return mapManager; --- 918,922 ---- return false; } ! public MapManager getMapManager() { return mapManager; *************** *** 1001,1005 **** int direction = rotation + endPoint; if (b.length() > 0) b.append(","); ! b.append(MapHex.getOrientationName(direction)); } } --- 956,960 ---- int direction = rotation + endPoint; if (b.length() > 0) b.append(","); ! b.append(getOrientationName(direction)); } } Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** PublicCompany.java 31 Oct 2009 17:08:26 -0000 1.70 --- PublicCompany.java 2 Nov 2009 23:30:36 -0000 1.71 *************** *** 1550,1554 **** String tileLaid = "#" + tile.getExternalId() + "/" + hex.getName() + "/" ! + MapHex.getOrientationName(orientation); tilesLaidThisTurn.appendWithDelimiter(tileLaid, ", "); --- 1550,1554 ---- String tileLaid = "#" + tile.getExternalId() + "/" + hex.getName() + "/" ! + hex.getOrientationName(orientation); tilesLaidThisTurn.appendWithDelimiter(tileLaid, ", "); |