Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm new to creating games in C# and was hoping for some advice to help get me started. I am trying to create a board game using a person represented by a P, 5 rocks on different squares represented by R and home represented by H. The person walks around a 10x10 board based on keyboard actions, picking up the rocks as he reached the square they are on and placing the rocks home when he reaches the square home is on.

I have created the board using an array of Square [0,0] - [9,9] and am moving on to create the pieces. Is usual protocol to create a class for person, rock1, rock2, etc. with parameters such as rockscarried, powerleft, position, etc.? Also when displaying would the character displaying the object usually be in the class or separate? e.g. would class person have a char parameter with value 'P' or would 'P' be separate from the class?

Any advice is greatly appreciated.

Thanks very much,
Stephen.
Posted

1 solution

There's so many ways to do it!

If the state of the game can be completely represented by the board (as in Suduko) then I'd be inclined just to use a 2-dimensional array of chars.

By the sounds of it though, there is state (rocks carried etc.) so you might want to model it using distinct classes - 'Person', 'Rock', 'Home' all derived from a common base class which holds the x/y co-ord of where it is in the board. This is better abstraction for any game logic too and is typical of how tower defense games work (I know - I've written one).

In terms of 'rendering' returning a 'P' and 'R' or a 'H' again I'd make this an abstract method in the base class but doubtless someone will come along and bang on about 'single responsibility' and SOLID principles who will disagree. If this does happen I advise you to slap them.

Hope that helps..
 
Share this answer
 
Comments
Steve 2712 9-Jan-14 11:39am    
Thanks very much for the tips Rob. I've a good idea which way I'm going to go with it now. You've really helped me get some clear ideas.
Rob Philpott 9-Jan-14 12:32pm    
Good stuff, very welcome - good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900