From: Brett <wak...@ea...> - 2005-04-18 03:39:59
|
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. 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... ---Brett. Bugs, pl. n.: Small living things that small living boys throw on small living girls. |
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. |
From: Brett <wak...@ea...> - 2005-04-18 23:11:09
|
On Mon, 2005-04-18 at 23:21 +0200, Erik Vos wrote: > Wouldn't a method have been simpler? > > boolean hasTokens() { > return (tokens.size() != 0); > } Hmmm... I think that may be. > 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.... > Hmmm... can you compare this with my swing version and see if I'm making the problem harder than it needs to be? ---Brett. ...this is an awesome sight. The entire rebel resistance buried under six million hardbound copies of "The Naked Lunch." - The Firesign Theater |
From: Erik V. <eri...@hc...> - 2005-04-19 19:52:37
|
Brett, > > 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.... > > > > Hmmm... can you compare this with my swing version and see if > I'm making > the problem harder than it needs to be? I think you are almost there. I have checked in: - a new version of test.StockTest that adds some markers to the stock chart by setting par prices, and - a new version of ui.StockChart with some (temporary) System.out prints to demonstrate that these markers are indeed picked up by your current code. All you need to do, it seems to me, is to let the markers display themselves on the right place (I can't help much with that at the moment....) BTW I have also added a few more missing I's to StockSpace and Company. And locally I have removed Little, Big and Simple Company, which I think are redundant now, but I keep these ones merged by CVS. Do you want to keep these? Erik. |
From: Brett <wak...@ea...> - 2005-04-20 05:47:36
|
On Tue, 2005-04-19 at 21:52 +0200, Erik Vos wrote: > Brett, > > Hmmm... can you compare this with my swing version and see if > > I'm making > > the problem harder than it needs to be? > > I think you are almost there. > > I have checked in: > - a new version of test.StockTest that adds some markers > to the stock chart by setting par prices, and > - a new version of ui.StockChart with some (temporary) System.out prints > to demonstrate that these markers are indeed picked up by your current code. > > > All you need to do, it seems to me, is to let the markers display themselves > on the right place (I can't help much with that at the moment....) > OK great. Calling a repaint is easy, if that's all needing to be done. > BTW I have also added a few more missing I's to StockSpace and Company. > Excellent. I had a suspicion I'd missed a few and hadn't had time to check. > And locally I have removed Little, Big and Simple Company, which I think > are redundant now, but I keep these ones merged by CVS. > Do you want to keep these? If they don't fit our needs, we don't need to keep them. CVS never truly deletes things, so if we need them later, we can retrieve them. ---Brett. Life's the same, except for the shoes. - The Cars |