我的大脑不工作了,我试图抓住这个网格上的前三行。我正在制作一个简单的跳棋游戏,只是为了学习一些新东西。我的代码正在抓取前三列来初始化红色棋子的位置。我想要前三行。
这就是我的代码现在正在做的事情:
这是我的(简化的)代码。Square
是我的一类,它只保存一些小物品来跟踪碎片。
private Square[][] m_board = new Square[8][];
for (int i = 0; i < m_board.Length; i++)
m_board[i] = new Square[8];
//find which pieces should hold red pieces, the problem line
IEnumerable<Square> seqRedSquares =
m_board.Take(3).SelectMany(x => x).Where(x => x != null);
//second attempt with the same result
//IEnumerable<Square> seqRedSquares =
m_board[0].Union(m_board[1]).Union(m_board[2]).Where(x => x != null);
//display the pieces, all works fine
foreach (Square redSquare in seqRedSquares)
{
Piece piece = new Piece(redSquare.Location, Piece.Color.Red);
m_listPieces.Add(piece);
redSquare.Update(piece);
}