From: Erik V. <ev...@us...> - 2009-10-03 14:02:41
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13750/rails/game Modified Files: Game.java Round.java Portfolio.java Tile.java PublicCompany.java MapManager.java MapHex.java GameManagerI.java GameManager.java Log Message: Reduced dependence on static access to MapManager Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Portfolio.java 25 Sep 2009 19:13:01 -0000 1.36 --- Portfolio.java 3 Oct 2009 14:02:28 -0000 1.37 *************** *** 582,585 **** --- 582,586 ---- for (PrivateCompanyI priv : privateCompanies) { + sps = priv.getSpecialProperties(); if (sps == null) continue; Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** PublicCompany.java 25 Sep 2009 19:29:56 -0000 1.62 --- PublicCompany.java 3 Oct 2009 14:02:28 -0000 1.63 *************** *** 51,58 **** --- 51,60 ---- /** Home hex & city * */ + protected String homeHexName = null; protected MapHex homeHex = null; protected int homeCityNumber = 1; /** Destination hex * */ + protected String destinationHexName = null; protected MapHex destinationHex = null; protected BooleanState hasReachedDestination = null; *************** *** 244,247 **** --- 246,250 ---- protected Bank bank; protected StockMarketI stockMarket; + protected MapManager mapManager; /** *************** *** 287,314 **** Tag homeBaseTag = tag.getChild("Home"); if (homeBaseTag != null) { ! String homeHexName = homeBaseTag.getAttributeAsString("hex"); ! MapHex hex = MapManager.getInstance().getHex(homeHexName); ! if (hex != null) { ! homeHex = hex; ! homeCityNumber = homeBaseTag.getAttributeAsInteger("city", 1); ! } else { ! throw new ConfigurationException("Invalid home hex " ! + homeHexName ! + " for company " + name); ! } } Tag destinationTag = tag.getChild("Destination"); if (destinationTag != null) { ! String destHexName = destinationTag.getAttributeAsString("hex"); ! MapHex hex = MapManager.getInstance().getHex(destHexName); ! if (hex != null) { ! destinationHex = hex; ! hasReachedDestination = new BooleanState (name+"_reachedDestination", false); ! } else { ! throw new ConfigurationException("Invalid destination hex " ! + destHexName ! + " for company " + name); ! } } --- 290,300 ---- Tag homeBaseTag = tag.getChild("Home"); if (homeBaseTag != null) { ! homeHexName = homeBaseTag.getAttributeAsString("hex"); ! homeCityNumber = homeBaseTag.getAttributeAsInteger("city", 1); } Tag destinationTag = tag.getChild("Destination"); if (destinationTag != null) { ! destinationHexName = destinationTag.getAttributeAsString("hex"); } *************** *** 645,648 **** --- 631,635 ---- bank = gameManager.getBank(); stockMarket = gameManager.getStockMarket(); + mapManager = gameManager.getMapManager(); if (hasStockPrice && Util.hasValue(startSpace)) { *************** *** 677,680 **** --- 664,686 ---- } + if (homeHexName != null) { + homeHex = mapManager.getHex(homeHexName); + if (homeHex == null) { + throw new ConfigurationException("Invalid home hex " + + homeHexName + + " for company " + name); + } + } + + if (destinationHexName != null) { + destinationHex = mapManager.getHex(destinationHexName); + if (destinationHex != null) { + hasReachedDestination = new BooleanState (name+"_reachedDestination", false); + } else { + throw new ConfigurationException("Invalid destination hex " + + destinationHexName + + " for company " + name); + } + } } Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** GameManager.java 25 Sep 2009 19:13:01 -0000 1.54 --- GameManager.java 3 Oct 2009 14:02:28 -0000 1.55 *************** *** 47,50 **** --- 47,51 ---- protected TrainManagerI trainManager; protected StockMarketI stockMarket; + protected MapManager mapManager; protected Bank bank; *************** *** 331,334 **** --- 332,336 ---- TrainManagerI trainManager, StockMarketI stockMarket, + MapManager mapManager, Bank bank) { this.playerManager = playerManager; *************** *** 337,340 **** --- 339,343 ---- this.trainManager = trainManager; this.stockMarket = stockMarket; + this.mapManager = mapManager; this.bank = bank; *************** *** 958,961 **** --- 961,968 ---- return stockMarket; } + + public MapManager getMapManager() { + return mapManager; + } public Bank getBank () { Index: MapManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MapManager.java 4 Jun 2008 19:00:31 -0000 1.7 --- MapManager.java 3 Oct 2009 14:02:28 -0000 1.8 *************** *** 81,85 **** int maxY = 0; for (Tag hexTag : hexTags) { ! hex = new MapHex(); hex.configureFromXML(hexTag); mHexes.put(hex.getName(), hex); --- 81,85 ---- int maxY = 0; for (Tag hexTag : hexTags) { ! hex = new MapHex(this); hex.configureFromXML(hexTag); mHexes.put(hex.getName(), hex); Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Round.java 25 Sep 2009 19:29:56 -0000 1.24 --- Round.java 3 Oct 2009 14:02:28 -0000 1.25 *************** *** 35,39 **** protected Portfolio unavailable = null; protected Portfolio scrapHeap = null; ! protected StockMarketI stockMarket; protected Class<? extends RoundI> roundTypeForUI = null; --- 35,40 ---- protected Portfolio unavailable = null; protected Portfolio scrapHeap = null; ! protected StockMarketI stockMarket = null; ! protected MapManager mapManager = null; protected Class<? extends RoundI> roundTypeForUI = null; *************** *** 61,64 **** --- 62,66 ---- scrapHeap = bank.getScrapHeap(); stockMarket = aGameManager.getStockMarket(); + mapManager = aGameManager.getMapManager(); } *************** *** 184,188 **** cityNumber = 1; } ! hex = MapManager.getInstance().getHex(hexName); city = hex.getCity(cityNumber); --- 186,190 ---- cityNumber = 1; } ! hex = mapManager.getHex(hexName); city = hex.getCity(cityNumber); Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** Game.java 25 Sep 2009 19:13:01 -0000 1.28 --- Game.java 3 Oct 2009 14:02:28 -0000 1.29 *************** *** 27,30 **** --- 27,31 ---- protected TrainManagerI trainManager; protected StockMarketI stockMarket; + protected MapManager mapManager; protected Bank bank; // protected ArrayList companyList; *************** *** 146,149 **** --- 147,158 ---- } + mapManager = + (MapManager) componentManager.findComponent("Map"); + if (mapManager == null) { + throw new ConfigurationException( + "No Map XML element found in file " + + GAME_XML_FILE); + } + /* * Initialisations that involve relations between components can *************** *** 152,156 **** playerManager.setPlayers(players, bank); gameManager.init(playerManager, companyManager, ! phaseManager, trainManager, stockMarket, bank); companyManager.initCompanies(gameManager, playerManager.getPlayers()); --- 161,165 ---- playerManager.setPlayers(players, bank); gameManager.init(playerManager, companyManager, ! phaseManager, trainManager, stockMarket, mapManager, bank); companyManager.initCompanies(gameManager, playerManager.getPlayers()); Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** MapHex.java 8 Sep 2009 21:48:59 -0000 1.24 --- MapHex.java 3 Oct 2009 14:02:28 -0000 1.25 *************** *** 93,101 **** /** Tokens that are not bound to a Station (City), such as Bonus tokens */ protected List<TokenI> offStationTokens; protected static Logger log = Logger.getLogger(MapHex.class.getPackage().getName()); ! public MapHex() {} /** --- 93,105 ---- /** Tokens that are not bound to a Station (City), such as Bonus tokens */ protected List<TokenI> offStationTokens; + + protected MapManager mapManager = null; protected static Logger log = Logger.getLogger(MapHex.class.getPackage().getName()); ! public MapHex(MapManager mapManager) { ! this.mapManager = mapManager; ! } /** *************** *** 957,960 **** --- 961,968 ---- return false; } + + public MapManager getMapManager() { + return mapManager; + } @Override Index: Tile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Tile.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Tile.java 15 Jan 2009 20:53:28 -0000 1.27 --- Tile.java 3 Oct 2009 14:02:28 -0000 1.28 *************** *** 481,485 **** } ! if (hexes != null) convertHexString(); if (allowedHexes != null) { --- 481,485 ---- } ! if (hexes != null) convertHexString(hex.getMapManager()); if (allowedHexes != null) { *************** *** 505,509 **** ! private void convertHexString() { boolean allowed = !hexes.startsWith("-"); --- 505,509 ---- ! private void convertHexString(MapManager mapManager) { boolean allowed = !hexes.startsWith("-"); *************** *** 512,516 **** MapHex hex; for (int i = 0; i < hexArray.length; i++) { ! hex = MapManager.getInstance().getHex(hexArray[i]); if (hex != null) { if (allowed) { --- 512,516 ---- MapHex hex; for (int i = 0; i < hexArray.length; i++) { ! hex = mapManager.getHex(hexArray[i]); if (hex != null) { if (allowed) { Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GameManagerI.java 23 Sep 2009 21:38:57 -0000 1.11 --- GameManagerI.java 3 Oct 2009 14:02:28 -0000 1.12 *************** *** 21,25 **** CompanyManagerI companyManager, PhaseManager phaseManager, TrainManagerI trainManager, StockMarketI stockMarket, ! Bank bank); public abstract void startGame(); --- 21,25 ---- CompanyManagerI companyManager, PhaseManager phaseManager, TrainManagerI trainManager, StockMarketI stockMarket, ! MapManager mapManager, Bank bank); public abstract void startGame(); *************** *** 152,155 **** --- 152,156 ---- public PlayerManager getPlayerManager(); public StockMarketI getStockMarket(); + public MapManager getMapManager(); public Bank getBank (); |