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 My question is, what square should be responsible for pieces on the board? On one hand, I can say that the On the other hand, I can have a and the form of the form after the board will be: How do you do it? And why? I can not get a clear winner in one of these approaches thanks 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? 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.
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. piece
boolean [,] IsPixelSet (int x, int y)
< / Pre>
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 ());}}}}
edit
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
Post a Comment