/// <summary> /// Assign a gnom view to the current instance. /// </summary> /// <param name="view"></param> public GnomController(IGnomTree view) { this.View = view; this.field = this.View[FieldId]; // TODO: extract in resource provider var text2 = new TextElement("Current moves: 0"); text2.Style.PaddingTop = 3; this.View[MessageBoxId].AddChild(text2); }
public static IPressable AddMatrixToGnom(INodeElement field, string[,] matrix) { var result = new TextElement[matrix.GetLength(0), matrix.GetLength(1)]; for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { result[i, j] = new TextElement(matrix[i, j]) { Style = new Style() { PaddingLeft = j * 2, PaddingTop = i * 2, Color = ConsoleColor.Green } }; if (i > 0) { result[i, j].LinkTo(ConsoleKey.UpArrow, result[i - 1, j]); } if (j > 0) { result[i, j].LinkTo(ConsoleKey.LeftArrow, result[i, j - 1]); } } } result[result.GetLength(0) - 1, 0].IsSelected = true; foreach (var node in result) { field.AddChild(node); } return result[result.GetLength(0) - 1, 0]; }
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]); } }
/// <summary> /// Prints the highscore in the rankings section of the view. /// </summary> /// <param name="table"></param> public void PrintHighscore(IHighscoreTable table) { this.View[ScoreBoxId].Style.Color = ConsoleColor.White; var rankings = table.Table; for (int i = 0; i < rankings.Count; i++) { // TODO: extract in resource provider var scoreToAdd = new TextElement(rankings[i].Stringify(i + 1)); scoreToAdd.Style.PaddingTop = (i * PlayerScoreMargin) + 1; this.View.AddChildToParent(this.View[ScoreBoxId], scoreToAdd); this.View[ScoreBoxId].Style.Height = table.Table.Count * HighscoreTableHeightIncrement; } }