views:

954

answers:

5

What would be the best way to display & program simple game board (say chess, checkers and such) in C#? In terms of controls and underlying game logic.

An idea that came to my mind was to use Picture Box (or class inheriting from it) with Board & Field classes.

  • Is that a decent solution after all?
  • How would I separate graphics from game logic using this solution (I believe Board & Field classes may not be enough)?
  • Is PictureBox efficient enough for such purpose?

Googling some also brought me to solutions using button/label for each game field. But back to Board, Field and PictureBox.

Extendability - designing it properly would easily allow to implement any other board game (or even card game) as it's all about board with modifiable fields after all.

+2  A: 

In an object-oriented approach, think about the objects involved in your game (e.g. the board, the pieces) … let them each provide a drawing method that takes a Graphics object and draws itself on it.

The drawing itself could be done on a PictureBox – this is the ideal control for such purpose – but this isn't really all that important because once your drawing logic is in place, it won't depend on the kind of control.

In general, don't use workarounds with different controls. These might be nice for a conventional GUI. Not so much for games (or any kind of graphics-heavy application).

Konrad Rudolph
+1  A: 

If you want the shiny, you could try WPF, the perf. is not too bad now, and it is very easy to get very customisable graphics, loading from external files, etc....

In terms of generalising the behaviour, you probably want to seperate scene graph code (layout, drawing objects, and all the boring low level stuff), then put a layer for general board game interaction: selecting source then destination for moves, turns, and the like, then layer your game logic on top of that.

I would probably just get Tic-Tac-Toe going first, see if there is anywhere you need to break your seperation of layers, and fix that early, before getting bogged down in the game logic.

Simon Buchan
+3  A: 

From data structure perspective take a look at the bitboard datastructure. http://en.wikipedia.org/wiki/Bitboard

Ankur Gupta
Good advice, but very low-level and ultimately irrelevant when thinking about the front-end aspect of the game.
Konrad Rudolph
+1  A: 

If you feel very adventurous you could try out XNA ;)

Yes, it's more complicated than the other solutions and might be overkill for a boardgame, but once you get a hang of it you are free to make some awesome games.

Nailer
A: 

Generally, first design the logical constructs for the board, pieces and such, then the operations on these, and only finally design a graphical interface, more or less as a frontend.

Svante