Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to display & program game board?

Tags:

c#

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.

like image 828
user36890 Avatar asked Nov 28 '08 08:11

user36890


1 Answers

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).

like image 167
Konrad Rudolph Avatar answered Sep 18 '22 07:09

Konrad Rudolph