This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I'm programming a Risk-like strategy game (basically an emulation of the existing board game. i do it only for fun, no commercial interest behind it.)
A main feature of my implementation is that players can design their own maps. To achieve this the game reads in a local text file and creates the territories and continents on its own. So the players only have to supply the game with a correct text file.
Now a big issue that keeps bugging me for days already is the following: I don't know where it is best to put the method that creates the board. I have moved it around the project several times already and I always found something that I didn't like. In my latest implementation I moved it directly into the constructor of class Board. The constructor looks like this now: Board(File inputFile). But then I think it would be better if there was an external class like this: which has a method:
But with this implementation I think again that the board now relies on another class to be created which is not perfect either.
What the method basically does is the following: it reads in the minimum and maximum number of players allowed for the game, the name of the territories, their direct neighbors and their continent. I put the territories in a hashmap with their names as key. The min and max players are final variables that cannot be changed throughout the game. They are important to check whether the game is started with the right amount of players. So as you can see all these things are vital aspects of the board. Thats why I don't like the idea of setters because after reading the input file I dont want that information to be changed.
The reason why I dont want to put the method into class Board but only want to put it directly into its constructor is that there are various members i want to finalize. So I dont want to use setters for that. Thats why I also dont like GameHelper implementation. But with the implementation inside the constructor of class Board I am unhappy too because then the only way to create a board is by using an input file. Of course I could overload the constructor but then I basically provide additional functionality when in the end I will only use the implementation with the input file.
So I keep moving in circles and this takes up much time I could already spend on other stuff of the game.
I would appreciate your ideas on this. So far my classes are all relatively independent from each other and they all serve a single purpose. The only thing is with this method. Thanks!