private void InitializeField(IBalloon[,] matrix)
{
int rows = matrix.GetLength(0);
int columns = matrix.GetLength(1);
this.cachedField = new TextElement[rows, columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
// TODO: extract in resource provider
var childToAdd = new TextElement(WholeBalloonContent);
childToAdd.Style = new Style()
{
PaddingLeft = j * BalloonPaddingLeftMultiplier,
PaddingTop = i * BalloonPaddingTopMultiplier,
Color = Colors[matrix[i, j].IsPopped ? 0 : matrix[i, j].Number]
};
childToAdd.Id = i + " " + j;
// cache
this.cachedField[i, j] = childToAdd;
this.View.AddChildToParent(this.field, childToAdd);
// link to neighbors
if (i > 0)
{
childToAdd.LinkTo(ConsoleKey.UpArrow, this.cachedField[i - 1, j]);
}
if (j > 0)
{
childToAdd.LinkTo(ConsoleKey.LeftArrow, this.cachedField[i, j - 1]);
}
}
}
for (int i = columns - 1; i >= 0; i--)
{
this.cachedField[rows - 1, i].LinkTo(ConsoleKey.DownArrow, this.View[RestartButtonId]);
}
}