Hi all,
I create small games in WinForms, Silverlight etc using C#. I have a question regarding the correct OO way of buiding the structure of classes.
This is a typical structure for me:
Soldier.cs
SoldierCollection.cs (an array of Soldiers plus methods that take care of manipulations of this array)
Board.cs (the GUI component, such as "Form1" in WinForms. Here I fill pictureboxes with data (ie Soldiers) from the SoldierCollection.
Rules.cs (Rules for checking for allowed movements etc)
What happens now is this:
1. First, Board.cs creates an instance of Soldiercollection.cs.
2. Next, it calls a method in this instance of SoldierCollection.cs, which in turn creates an array of Soldiers.
3. After this has been done, Board.cs gets graphically filled, using data from the instance of SoldierCollection.cs.
4. When a soldierpiece (say a picturebox) is dragged over the board using the mouse, another method in Soldiercollection.cs is called, which in turn calls the appropriate method(s) in Rules.cs. The result is then sent back to SoldierCollection, which decides what happens, and the result is returned to Board.cs, to update the playing field or perhaps showing a win.
The question is how all of these should connect to each other as OO-nicely as possible.
For example, both Rules.cs and SoldierCollection.cs will only appear once (as opposed to Soldier.cs, which may have dozens of instances). Therefore, I am tempted to set these to static. However, I have a feeling that this is looked down upon from an OO viewpoint.
So my specific question is: Is my design and process described above suitable or should it better be done in another way? And should I have the SoldierCollection or Rules classes static? What would be the pros and cons of using static classes here? (I also guess that if I want to track wins or keep playerturns, this must either be done in Board.cs or I would need yet another class, such as Game.cs. Perhaps I should start out with a Game.cs class that in turn connects to SOldierCollection etc and then flushes out the data to Board.cs for display?)
Thanks!
Petter