c# - Which class has the responsibility of setting Piece's pixels on a Board(2d matrix)? The Piece or the Board? -


Then, I currently have the board class which is composed of the piece s Each piece is a color and a string that describes the type of piece. It also has 2D matrix which is set or closed on bits, which allows me to know which pixels paint with desired color or not.

My question is, what square should be responsible for pieces on the board? On one hand, I can say that the piece class should do this. But to do this, I have to pass the code as piece 's draw () as a reference to board and although it is not terrible I think it sounds awkward. It raises the problem that the piece board "know" the class.

On the other hand, I can have a piece

  boolean [,] IsPixelSet (int x, int y)  < / Pre> 

and the form of the form after the board will be:

  zero DrawPieceOnBoard () {For (int y = 0; y & lt; height; ++ y) {for (Int x = 0; x & lt; width; ++ x) {if (piece.ispxset (x, y) {board.DrawPixelAt (X, Y, piece.gatecar ());}}}}  

How do you do it? And why? I can not get a clear winner in one of these approaches

thanks

edit

I live in I'm not talking about pulling things up on the screen. What happens is that I'm implementing a Tetris game (currently, not a GUI) and I want to set a Square Pixel at different positions on the board at every moment. It falls on the ground as it falls on the ground.The original form of the board is only for each accelerator (x, y) oints. Suppose i now have a square Piece), should the piece know about the board and its draw () method can change the board, or should the board use the payment method of slice and do it yourself?

I would say that pulls the piece. For example, your function does not allow them to increase the pieces so they can get many colors.

The piece does not need to know all the boards, just some method (maybe part of an interface) draw (x, y, color) .


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -