From: Erik V. <eri...@hc...> - 2005-04-18 21:22:00
|
> I've added the code to draw a token in ui/StockChit and the > logic to do > so in ui/StockChart. > > I added a boolean in game/StockSpace called hasTokens to make > it easy to > figure out if a particular stock space has any tokens on it. I added a > getter and setter for this new variable as well as inserted logic to > toggle the boolean in some of the other methods within the StockSpace > class. Wouldn't a method have been simpler? boolean hasTokens() { return (tokens.size() != 0); } > My current idea on how to put the tokens onto the Stock Market is to > insert them as part of drawing the whole chart. Unfortunately this is > making it rather difficult to test this because PublicCompany only > accepts a StockSpace for setCurrentPrice, so I'm hitting a chicken and > egg problem when it comes time to draw each StockSpace within the > StockChart. > > I suspect the solution is that this single method ought to be > broken up > into two separate methods that allow easy cross-indexing with the > information contained in a StockSpace: > > setCurrentPrice(int p) > setCurrentGridLocation(String coord) or setCurrentGridLocation(int x, > int y) > > Or perhaps I'm missing an easier solution entirely... Not sure what the problem is. If you are drawing a space you need the corresponding StockSpace object, if only to find the price, and then getTokens() will tell you what companies have a marker on that space. Maybe the confusion comes because I'm linking company and space objects as a whole, rather than having a separate int price attribute in a company object? In my stockmarket servlet the code is like for (row = 0; row < stockMarket.getNumberOfRows(); row++) { for (col = 0; col < stockMarket.getNumberOfColumns(); col++) { square = stockMarket.getStockSpace(row, col); if (square != null) { // draw square iterator = square.getTokens().iterator(); while (iterator.hasNext()) { company = (PublicCompany) iterator.next(); // draw company marker } } } } and I don't see why similar code would not work for you. I guess I'm missing a point somewhere.... Erik. |