The best way to display and program the playing field?

What would be the best way to display and program a simple game panel (like chess, checkers, etc.) in C #? In terms of control and the basic logic of the game.

The idea that came to my mind was to use the Picture Box (or a class inheriting from it) using the Board and Field classes.

  • Is this a worthy solution?
  • How to separate the graphics from the logic of the game using this solution (I believe that the Board and Field classes may not be enough)?
  • Is PictureBox efficient enough for this purpose?

At Google, for example, some of them led me to decisions with a button / tag for each playing field. But back to Board, Field and PictureBox.

Extensibility - the right design would make it easy to implement any other board game (or even a card game), like everything that goes with a board with variable fields in the end.

+6
c #
source share
5 answers

In an object-oriented approach, think about the objects involved in your game (for example, a board, parts) ... let each of them provide a drawing method that accepts a Graphics object and draws on it.

The drawing itself can be done on the PictureBox - this is an ideal control for this purpose, but it is not so important, because as soon as your drawing logic is in place, it will not depend on the type of control.

In general, do not use workarounds with various controls. This may be convenient for a conventional graphical interface. Not so much for games (or any graphics application).

+4
source share

In terms of data structure, take a look at the data structure of the board. http://en.wikipedia.org/wiki/Bitboard

+4
source share

If you want brilliant, you can try WPF, perf. Now it’s not so bad, and it’s very easy to get very customizable graphics, loading from external files, etc ....

In terms of generalizing the behavior, you probably want to separate the code for the scene graph (layout, drawing objects, and all the boring low-level materials), then place the layer for general interaction with the game console: select the source, then the destination for the moves, turns, etc. etc., then on top of your game logic.

I would most likely just run Tic-Tac-Toe, see if there is anywhere you need to break your layer separation, and fix it earlier before getting bogged down in the game logic.

+1
source share

If you feel very adventurous, you can try XNA;)

Yes, it is more complicated than other solutions, and may be redundant for a board game, but as soon as you get it, you can make some amazing games.

+1
source share

As a rule, first create logical constructions for the board, pieces, etc., then operations on them and only finally create a graphical interface more or less like an interface.

0
source share

All Articles