From: Markus S. <mar...@we...> - 2003-07-28 08:52:18
|
> Yes, a HashMap would be better there. > I wouldn't change the variables from ints to Strings, though. Those > variables are used to identify images/sounds while at the same they > allow a compile-time check on image names. I wouldn't use something like > 'getImage("Free Colonist")' because a typo is easily made, if that's > what you meant. A HashMap for integers? I would switch to strings not only for images but also for types, states and directions. Yes, it is possible to make a typo, which is not recognisable at compile-time, but such bugs should be easy to detect and correct. On the other hand using constants and integers we are hard-coding all those things. I think it would be better to have a rules file, possibly an xml file, containing all the information about units, tiles and so forth. To add a new unit would be very easy, with no need to change the code and recompile. Looking up information is most easily done using a string instead of an integer. How it could look like: class Unit { private String type; private Rules rules; public Unit(String type, Rules rules) { this.type = type; this.rules = rules; } public int getInitialMoves() { return rules.getInitialRules(type); } public Image getImage() { return rules.getImage(type); } } Bye, Markus. ______________________________________________________________________________ ComputerBild 15-03 bestaetigt: Den besten Spam-Schutz gibt es bei WEB.DE FreeMail - Deutschlands beste E-Mail - http://s.web.de/?mc=021121 |