From: Stefan F. <ste...@we...> - 2012-07-01 12:05:39
|
Martin: regardless if you want to display the number of free slots or only use it for internal book-keeping you need a state-type variable. Otherwise you will run into undo-problems. To have an updating display you need to create an observable model-type object which delivers that information to the display element after each update. So using an fixed-length array is not a solution. To solve the state issue I propose the following solutions: A) As the par prices of companies are already state-variables the number of free slots could be derived without adding another state variable. This is an easy solution if you only check the number of free slots at the time of choosing a new par price. B) Or you could use a HashMapState<Integer, Integer> variable which has the par prices as keys and the the number of available slots as values. A disadvantage of this approach is that you have to change every code location that assigns par prices, something that is not necessary for A. (Most likely there is only one, but better check). To solve the observable issue: A) If you want to make this observable you have to write your own subclass of ModelObject. Then you have to make this ModelObject dependent on the par price state variables of all companies in 1880 at initialization time. B) The HashMapState itself is a sub-class of ModelObject, thus it is a ModelObject already. In Rails2.0 the State/Model mechanisms will be easier to use and more powerful, however they are not 100% compatible, so it will need some manual changes anyway. Stefan On 06/30/2012 10:41 PM, Dr. Martin Brumm wrote: > Hi Erik, Brett, Stefan, > > i would like to display the parslots (in 1880 there are a number of > ParPrices each with an fixed amount of slots available) and their > current Status (occupied or not and if occupied by whom). > > At start those slots are unoccupied and get occupied upon Starting a > Major Corporation. The player is able to choose the ParPrice and the > “ParSlot” to determine the position of his company in the operational order. > > So from what I have seen this would require a new Model to be observed ? > Even though it’s an Array with a predetermined length. > > Is that the right way, or is there an easier way to handle that ? J > > Regrds, > > Martin > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > > > _______________________________________________ > Rails-devel mailing list > Rai...@li... > https://lists.sourceforge.net/lists/listinfo/rails-devel > |